aboutsummaryrefslogtreecommitdiff
path: root/test/js
diff options
context:
space:
mode:
Diffstat (limited to 'test/js')
-rw-r--r--test/js/bun/resolve/import-meta.test.js8
-rw-r--r--test/js/bun/spawn/spawn-streaming-stdin.test.ts2
-rw-r--r--test/js/node/buffer.test.js26
-rw-r--r--test/js/node/fs/fs.test.ts10
-rw-r--r--test/js/node/stream/bufferlist.test.ts25
5 files changed, 35 insertions, 36 deletions
diff --git a/test/js/bun/resolve/import-meta.test.js b/test/js/bun/resolve/import-meta.test.js
index 492a19942..a940d0c87 100644
--- a/test/js/bun/resolve/import-meta.test.js
+++ b/test/js/bun/resolve/import-meta.test.js
@@ -8,10 +8,6 @@ import sync from "./require-json.json";
const { path, dir } = import.meta;
-it("primordials are not here!", () => {
- expect(globalThis[Symbol.for("Bun.lazy")]("primordials") === undefined).toBe(true);
-});
-
it("import.meta.main", () => {
const { exitCode } = spawnSync({
cmd: [bunExe(), "run", join(import.meta.dir, "./main-test-script.js")],
@@ -98,9 +94,7 @@ it("Module._cache", () => {
});
it("Module._resolveFilename()", () => {
- const expected = Bun.resolveSync(import.meta.path, "/");
- const result = Module._resolveFilename(import.meta.path, "/", true);
- expect(result).toBe(expected);
+ expect(Module._resolveFilename).toBeUndefined();
});
it("Module.createRequire(file://url).resolve(file://url)", () => {
diff --git a/test/js/bun/spawn/spawn-streaming-stdin.test.ts b/test/js/bun/spawn/spawn-streaming-stdin.test.ts
index 0c430b680..3226f03cc 100644
--- a/test/js/bun/spawn/spawn-streaming-stdin.test.ts
+++ b/test/js/bun/spawn/spawn-streaming-stdin.test.ts
@@ -62,4 +62,4 @@ test("spawn can write to stdin multiple chunks", async () => {
// assert we didn't leak any file descriptors
expect(newMaxFD).toBe(maxFD);
-}, 10_000);
+}, 20_000);
diff --git a/test/js/node/buffer.test.js b/test/js/node/buffer.test.js
index 4040f5ce2..7c3d16536 100644
--- a/test/js/node/buffer.test.js
+++ b/test/js/node/buffer.test.js
@@ -499,6 +499,23 @@ it("creating buffers larger than pool size", () => {
expect(sb).toBe(s);
});
+it("should use args correctly", () => {
+ const buf1 = Buffer.allocUnsafe(26);
+
+ for (let i = 0; i < 26; i++) {
+ // 97 is the decimal ASCII value for 'a'.
+ buf1[i] = i + 97;
+ }
+
+ expect(buf1.toString("utf8")).toBe("abcdefghijklmnopqrstuvwxyz");
+ expect(buf1.toString("utf8", 0, 5)).toBe("abcde");
+
+ const buf2 = Buffer.from("tést");
+ expect(buf2.toString("hex")).toBe("74c3a97374");
+ expect(buf2.toString("utf8", 0, 3)).toBe("té");
+ expect(buf2.toString(undefined, 0, 3)).toBe("té");
+});
+
it("hex toString()", () => {
const hexb = Buffer.allocUnsafe(256);
for (let i = 0; i < 256; i++) {
@@ -2403,15 +2420,6 @@ it("Buffer.toString(encoding, start, end)", () => {
expect(buf.toString("utf8", 100, 1)).toStrictEqual("");
});
-it("Buffer.toString(offset, length, encoding)", () => {
- const buf = Buffer.from("0123456789", "utf8");
-
- expect(buf.toString(3, 6, "utf8")).toStrictEqual("345678");
- expect(buf.toString(3, 100, "utf8")).toStrictEqual("3456789");
- expect(buf.toString(100, 200, "utf8")).toStrictEqual("");
- expect(buf.toString(100, 50, "utf8")).toStrictEqual("");
-});
-
it("Buffer.asciiSlice())", () => {
const buf = Buffer.from("0123456789", "ascii");
diff --git a/test/js/node/fs/fs.test.ts b/test/js/node/fs/fs.test.ts
index 2f898a2ea..0578e0fc7 100644
--- a/test/js/node/fs/fs.test.ts
+++ b/test/js/node/fs/fs.test.ts
@@ -2025,7 +2025,11 @@ it("BigIntStats", () => {
it("test syscall errno, issue#4198", () => {
const path = `${tmpdir()}/non-existent-${Date.now()}.txt`;
expect(() => openSync(path, "r")).toThrow("No such file or directory");
- expect(() => readSync(2147483640, Buffer.alloc(0))).toThrow("Bad file number");
+ if (process.platform == "darwin") {
+ expect(() => readSync(2147483640, Buffer.alloc(0))).toThrow("Bad file descriptor");
+ } else {
+ expect(() => readSync(2147483640, Buffer.alloc(0))).toThrow("Bad file number");
+ }
expect(() => readlinkSync(path)).toThrow("No such file or directory");
expect(() => realpathSync(path)).toThrow("No such file or directory");
expect(() => readFileSync(path)).toThrow("No such file or directory");
@@ -2034,10 +2038,10 @@ it("test syscall errno, issue#4198", () => {
expect(() => unlinkSync(path)).toThrow("No such file or directory");
expect(() => rmSync(path)).toThrow("No such file or directory");
expect(() => rmdirSync(path)).toThrow("No such file or directory");
- expect(() => closeSync(2147483640)).toThrow("Bad file number");
+ expect(() => closeSync(2147483640)).toThrow("Bad file descriptor");
mkdirSync(path);
expect(() => mkdirSync(path)).toThrow("File or folder exists");
- expect(() => unlinkSync(path)).toThrow("Is a directory");
+ expect(() => unlinkSync(path)).toThrow("Operation not permitted");
rmdirSync(path);
});
diff --git a/test/js/node/stream/bufferlist.test.ts b/test/js/node/stream/bufferlist.test.ts
index 8ab147d7e..b78911858 100644
--- a/test/js/node/stream/bufferlist.test.ts
+++ b/test/js/node/stream/bufferlist.test.ts
@@ -38,9 +38,7 @@ it("should fail on .concat() with invalid items", () => {
const list = new Readable().readableBuffer;
expect(list.length).toBe(0);
expect(list.push("foo")).toBeUndefined();
- expect(() => {
- list.concat(42);
- }).toThrow(TypeError);
+ list.concat(42);
});
it("should fail on .concat() buffer overflow", () => {
@@ -63,7 +61,7 @@ it("should work with .consume() on strings", () => {
// @ts-ignore
const list = new Readable().readableBuffer;
expect(list.length).toBe(0);
- expect(list.consume(42, true)).toBe("");
+ expect(() => list.consume()).toThrow();
expect(list.push("foo")).toBeUndefined();
expect(list.push("bar")).toBeUndefined();
expect(list.push("baz")).toBeUndefined();
@@ -82,7 +80,7 @@ it("should work with .consume() on buffers", () => {
// @ts-ignore
const list = new Readable().readableBuffer;
expect(list.length).toBe(0);
- expect(list.consume(42, false)).toEqual(new Uint8Array());
+ expect(() => list.consume()).toThrow();
expect(list.push(makeUint8Array("foo"))).toBeUndefined();
expect(list.push(makeUint8Array("bar"))).toBeUndefined();
expect(list.push(makeUint8Array("baz"))).toBeUndefined();
@@ -105,26 +103,21 @@ it("should fail on .consume() with invalid items", () => {
expect(list.length).toBe(0);
expect(list.push("foo")).toBeUndefined();
expect(list.length).toBe(1);
- expect(list.consume(0, false)).toEqual(new Uint8Array([]));
- expect(() => {
- list.consume(1, false);
- }).toThrow(TypeError);
- expect(list.consume(3, true)).toBe("foo");
+ expect(list.consume(0, false)).toEqual("");
+ expect(list.consume(1, false)).toEqual("f");
+ expect(list.consume(2, true)).toBe("oo");
expect(list.length).toBe(0);
expect(list.push(makeUint8Array("bar"))).toBeUndefined();
expect(list.length).toBe(1);
- expect(list.consume(0, true)).toEqual("");
- expect(() => {
- list.consume(1, true);
- }).toThrow(TypeError);
- expect(list.consume(3, false)).toEqual(new Uint8Array([98, 97, 114]));
+ expect(list.consume(0, true).byteLength).toEqual(0);
+ expect(list.consume(1, true)[0]).toEqual(98);
});
it("should work with .first()", () => {
// @ts-ignore
const list = new Readable().readableBuffer;
expect(list.length).toBe(0);
- expect(list.first()).toBeUndefined();
+ expect(() => list.first()).toThrow();
const item = {};
expect(list.push(item)).toBeUndefined();
expect(list.length).toBe(1);