aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/bun.js')
-rw-r--r--test/bun.js/buffer.test.js82
-rw-r--r--test/bun.js/fetch.test.js44
-rw-r--r--test/bun.js/serve.test.ts1
-rw-r--r--test/bun.js/transpiler.test.js8
4 files changed, 89 insertions, 46 deletions
diff --git a/test/bun.js/buffer.test.js b/test/bun.js/buffer.test.js
index 47cdbe210..c3f422024 100644
--- a/test/bun.js/buffer.test.js
+++ b/test/bun.js/buffer.test.js
@@ -222,7 +222,7 @@ it("Buffer.copy", () => {
{
// Create two `Buffer` instances.
const buf1 = Buffer.allocUnsafe(26);
- const buf2 = Buffer.allocUnsafe(26).fill('!');
+ const buf2 = Buffer.allocUnsafe(26).fill("!");
for (let i = 0; i < 26; i++) {
// 97 is the decimal ASCII value for 'a'.
@@ -231,7 +231,7 @@ it("Buffer.copy", () => {
// Copy `buf1` bytes 16 through 19 into `buf2` starting at byte 8 of `buf2`.
buf1.copy(buf2, 8, 16, 20);
- expect(buf2.toString('ascii', 0, 25)).toBe('!!!!!!!!qrst!!!!!!!!!!!!!');
+ expect(buf2.toString("ascii", 0, 25)).toBe("!!!!!!!!qrst!!!!!!!!!!!!!");
}
{
@@ -243,7 +243,7 @@ it("Buffer.copy", () => {
}
buf.copy(buf, 0, 4, 10);
- expect(buf.toString()).toBe('efghijghijklmnopqrstuvwxyz');
+ expect(buf.toString()).toBe("efghijghijklmnopqrstuvwxyz");
}
});
@@ -427,33 +427,33 @@ it("write", () => {
});
it("includes", () => {
- const buf = Buffer.from('this is a buffer');
+ const buf = Buffer.from("this is a buffer");
- expect(buf.includes('this')).toBe(true);
- expect(buf.includes('is')).toBe(true);
- expect(buf.includes(Buffer.from('a buffer'))).toBe(true);
+ expect(buf.includes("this")).toBe(true);
+ expect(buf.includes("is")).toBe(true);
+ expect(buf.includes(Buffer.from("a buffer"))).toBe(true);
expect(buf.includes(97)).toBe(true);
- expect(buf.includes(Buffer.from('a buffer example'))).toBe(false);
- expect(buf.includes(Buffer.from('a buffer example').slice(0, 8))).toBe(true);
- expect(buf.includes('this', 4)).toBe(false);
+ expect(buf.includes(Buffer.from("a buffer example"))).toBe(false);
+ expect(buf.includes(Buffer.from("a buffer example").slice(0, 8))).toBe(true);
+ expect(buf.includes("this", 4)).toBe(false);
});
it("indexOf", () => {
- const buf = Buffer.from('this is a buffer');
+ const buf = Buffer.from("this is a buffer");
- expect(buf.indexOf('this')).toBe(0);
- expect(buf.indexOf('is')).toBe(2);
- expect(buf.indexOf(Buffer.from('a buffer'))).toBe(8);
+ expect(buf.indexOf("this")).toBe(0);
+ expect(buf.indexOf("is")).toBe(2);
+ expect(buf.indexOf(Buffer.from("a buffer"))).toBe(8);
expect(buf.indexOf(97)).toBe(8);
- expect(buf.indexOf(Buffer.from('a buffer example'))).toBe(-1);
- expect(buf.indexOf(Buffer.from('a buffer example').slice(0, 8))).toBe(8);
+ expect(buf.indexOf(Buffer.from("a buffer example"))).toBe(-1);
+ expect(buf.indexOf(Buffer.from("a buffer example").slice(0, 8))).toBe(8);
- const utf16Buffer = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'utf16le');
+ const utf16Buffer = Buffer.from("\u039a\u0391\u03a3\u03a3\u0395", "utf16le");
- expect(utf16Buffer.indexOf('\u03a3', 0, 'utf16le')).toBe(4);
- expect(utf16Buffer.indexOf('\u03a3', -4, 'utf16le')).toBe(6);
+ expect(utf16Buffer.indexOf("\u03a3", 0, "utf16le")).toBe(4);
+ expect(utf16Buffer.indexOf("\u03a3", -4, "utf16le")).toBe(6);
- const b = Buffer.from('abcdef');
+ const b = Buffer.from("abcdef");
// Passing a value that's a number, but not a valid byte.
// Prints: 2, equivalent to searching for 99 or 'c'.
@@ -462,31 +462,31 @@ it("indexOf", () => {
// Passing a byteOffset that coerces to NaN or 0.
// Prints: 1, searching the whole buffer.
- expect(b.indexOf('b', undefined)).toBe(1);
- expect(b.indexOf('b', {})).toBe(1);
- expect(b.indexOf('b', null)).toBe(1);
- expect(b.indexOf('b', [])).toBe(1);
+ expect(b.indexOf("b", undefined)).toBe(1);
+ expect(b.indexOf("b", {})).toBe(1);
+ expect(b.indexOf("b", null)).toBe(1);
+ expect(b.indexOf("b", [])).toBe(1);
});
it("lastIndexOf", () => {
- const buf = Buffer.from('this buffer is a buffer');
+ const buf = Buffer.from("this buffer is a buffer");
- expect(buf.lastIndexOf('this')).toBe(0);
- expect(buf.lastIndexOf('this', 0)).toBe(0);
- expect(buf.lastIndexOf('this', -1000)).toBe(-1);
- expect(buf.lastIndexOf('buffer')).toBe(17);
- expect(buf.lastIndexOf(Buffer.from('buffer'))).toBe(17);
+ expect(buf.lastIndexOf("this")).toBe(0);
+ expect(buf.lastIndexOf("this", 0)).toBe(0);
+ expect(buf.lastIndexOf("this", -1000)).toBe(-1);
+ expect(buf.lastIndexOf("buffer")).toBe(17);
+ expect(buf.lastIndexOf(Buffer.from("buffer"))).toBe(17);
expect(buf.lastIndexOf(97)).toBe(15);
- expect(buf.lastIndexOf(Buffer.from('yolo'))).toBe(-1);
- expect(buf.lastIndexOf('buffer', 5)).toBe(5);
- expect(buf.lastIndexOf('buffer', 4)).toBe(-1);
+ expect(buf.lastIndexOf(Buffer.from("yolo"))).toBe(-1);
+ expect(buf.lastIndexOf("buffer", 5)).toBe(5);
+ expect(buf.lastIndexOf("buffer", 4)).toBe(-1);
- const utf16Buffer = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'utf16le');
+ const utf16Buffer = Buffer.from("\u039a\u0391\u03a3\u03a3\u0395", "utf16le");
- expect(utf16Buffer.lastIndexOf('\u03a3', undefined, 'utf16le')).toBe(6);
- expect(utf16Buffer.lastIndexOf('\u03a3', -5, 'utf16le')).toBe(4);
+ expect(utf16Buffer.lastIndexOf("\u03a3", undefined, "utf16le")).toBe(6);
+ expect(utf16Buffer.lastIndexOf("\u03a3", -5, "utf16le")).toBe(4);
- const b = Buffer.from('abcdef');
+ const b = Buffer.from("abcdef");
// Passing a value that's a number, but not a valid byte.
// Prints: 2, equivalent to searching for 99 or 'c'.
@@ -495,11 +495,11 @@ it("lastIndexOf", () => {
// Passing a byteOffset that coerces to NaN or 0.
// Prints: 1, searching the whole buffer.
- expect(b.lastIndexOf('b', undefined)).toBe(1);
- expect(b.lastIndexOf('b', {})).toBe(1);
+ expect(b.lastIndexOf("b", undefined)).toBe(1);
+ expect(b.lastIndexOf("b", {})).toBe(1);
// Passing a byteOffset that coerces to 0.
// Prints: -1, equivalent to passing 0.
- expect(b.lastIndexOf('b', null)).toBe(-1);
- expect(b.lastIndexOf('b', [])).toBe(-1);
+ expect(b.lastIndexOf("b", null)).toBe(-1);
+ expect(b.lastIndexOf("b", [])).toBe(-1);
});
diff --git a/test/bun.js/fetch.test.js b/test/bun.js/fetch.test.js
index 9b6093afd..a4ab0bfa6 100644
--- a/test/bun.js/fetch.test.js
+++ b/test/bun.js/fetch.test.js
@@ -255,6 +255,50 @@ describe("Blob", () => {
}
});
+{
+ const sample = new TextEncoder().encode("Hello World!");
+ const typedArrays = [
+ Uint8Array,
+ Uint8ClampedArray,
+ Int8Array,
+ Uint16Array,
+ Int16Array,
+ Uint32Array,
+ Int32Array,
+ Float32Array,
+ Float64Array,
+ ];
+ const Constructors = [Blob, Response, Request];
+
+ for (let withGC of [false, true]) {
+ for (let TypedArray of typedArrays) {
+ for (let Constructor of Constructors) {
+ it(`${Constructor.name} arrayBuffer() with ${TypedArray.name}${
+ withGC ? " with gc" : ""
+ }`, async () => {
+ const data = new TypedArray(sample);
+ if (withGC) gc();
+ const input =
+ Constructor === Blob
+ ? [data]
+ : Constructor === Request
+ ? { body: data }
+ : data;
+ if (withGC) gc();
+ const blob = new Constructor(input);
+ if (withGC) gc();
+ const out = await blob.arrayBuffer();
+ if (withGC) gc();
+ expect(out instanceof ArrayBuffer).toBe(true);
+ if (withGC) gc();
+ expect(out.byteLength).toBe(data.byteLength);
+ if (withGC) gc();
+ });
+ }
+ }
+ }
+}
+
describe("Response", () => {
describe("Response.json", () => {
it("works", async () => {
diff --git a/test/bun.js/serve.test.ts b/test/bun.js/serve.test.ts
index 99b667a2d..ba505feba 100644
--- a/test/bun.js/serve.test.ts
+++ b/test/bun.js/serve.test.ts
@@ -158,7 +158,6 @@ describe("streaming", () => {
});
const response = await fetch(`http://localhost:${server.port}`);
- console.log("here");
expect(response.status).toBe(500);
} catch (e) {
if (!e || !(e instanceof TestPass)) {
diff --git a/test/bun.js/transpiler.test.js b/test/bun.js/transpiler.test.js
index 3bb458697..3d3bcc109 100644
--- a/test/bun.js/transpiler.test.js
+++ b/test/bun.js/transpiler.test.js
@@ -141,22 +141,22 @@ describe("Bun.Transpiler", () => {
x[x["y"] = 0] = "y";
})(x || (x = {}));
})(second = first.second || (first.second = {}));
-})(first || (first = {}))`
+})(first || (first = {}))`;
it("exported inner namespace", () => {
ts.expectPrinted_(input3, output3);
});
- const input4 = `export enum x { y }`
+ const input4 = `export enum x { y }`;
const output4 = `export var x;
(function(x) {
x[x["y"] = 0] = "y";
-})(x || (x = {}))`
+})(x || (x = {}))`;
it("exported enum", () => {
ts.expectPrinted_(input4, output4);
});
- })
+ });
describe("exports.replace", () => {
const transpiler = new Bun.Transpiler({