mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 19:38:58 +00:00
Merge branch 'main' into ben/fix-node-napi-tests
This commit is contained in:
@@ -100,7 +100,7 @@ describe("Server", () => {
|
||||
});
|
||||
|
||||
test("should not allow Bun.serve with invalid tls option", () => {
|
||||
[1, "string", true, Symbol("symbol"), false].forEach(value => {
|
||||
[1, "string", true, Symbol("symbol")].forEach(value => {
|
||||
expect(() => {
|
||||
using server = Bun.serve({
|
||||
//@ts-ignore
|
||||
|
||||
@@ -96,6 +96,117 @@ it("writing to 1, 2 are possible", () => {
|
||||
expect(fs.writeSync(2, Buffer.from("\nhello-stderr-test\n"))).toBe(19);
|
||||
});
|
||||
|
||||
describe("test-fs-assert-encoding-error", () => {
|
||||
const testPath = join(tmpdirSync(), "assert-encoding-error");
|
||||
const options = "test";
|
||||
const expectedError = expect.objectContaining({
|
||||
code: "ERR_INVALID_ARG_VALUE",
|
||||
name: "TypeError",
|
||||
});
|
||||
|
||||
it("readFile throws on invalid encoding", () => {
|
||||
expect(() => {
|
||||
fs.readFile(testPath, options, () => {});
|
||||
}).toThrow(expectedError);
|
||||
});
|
||||
|
||||
it("readFileSync throws on invalid encoding", () => {
|
||||
expect(() => {
|
||||
fs.readFileSync(testPath, options);
|
||||
}).toThrow(expectedError);
|
||||
});
|
||||
|
||||
it("readdir throws on invalid encoding", () => {
|
||||
expect(() => {
|
||||
fs.readdir(testPath, options, () => {});
|
||||
}).toThrow(expectedError);
|
||||
});
|
||||
|
||||
it("readdirSync throws on invalid encoding", () => {
|
||||
expect(() => {
|
||||
fs.readdirSync(testPath, options);
|
||||
}).toThrow(expectedError);
|
||||
});
|
||||
|
||||
it("readlink throws on invalid encoding", () => {
|
||||
expect(() => {
|
||||
fs.readlink(testPath, options, () => {});
|
||||
}).toThrow(expectedError);
|
||||
});
|
||||
|
||||
it("readlinkSync throws on invalid encoding", () => {
|
||||
expect(() => {
|
||||
fs.readlinkSync(testPath, options);
|
||||
}).toThrow(expectedError);
|
||||
});
|
||||
|
||||
it("writeFile throws on invalid encoding", () => {
|
||||
expect(() => {
|
||||
fs.writeFile(testPath, "data", options, () => {});
|
||||
}).toThrow(expectedError);
|
||||
});
|
||||
|
||||
it("writeFileSync throws on invalid encoding", () => {
|
||||
expect(() => {
|
||||
fs.writeFileSync(testPath, "data", options);
|
||||
}).toThrow(expectedError);
|
||||
});
|
||||
|
||||
it("appendFile throws on invalid encoding", () => {
|
||||
expect(() => {
|
||||
fs.appendFile(testPath, "data", options, () => {});
|
||||
}).toThrow(expectedError);
|
||||
});
|
||||
|
||||
it("appendFileSync throws on invalid encoding", () => {
|
||||
expect(() => {
|
||||
fs.appendFileSync(testPath, "data", options);
|
||||
}).toThrow(expectedError);
|
||||
});
|
||||
|
||||
it("watch throws on invalid encoding", () => {
|
||||
expect(() => {
|
||||
fs.watch(testPath, options, () => {});
|
||||
}).toThrow(expectedError);
|
||||
});
|
||||
|
||||
it("realpath throws on invalid encoding", () => {
|
||||
expect(() => {
|
||||
fs.realpath(testPath, options, () => {});
|
||||
}).toThrow(expectedError);
|
||||
});
|
||||
|
||||
it("realpathSync throws on invalid encoding", () => {
|
||||
expect(() => {
|
||||
fs.realpathSync(testPath, options);
|
||||
}).toThrow(expectedError);
|
||||
});
|
||||
|
||||
it("mkdtemp throws on invalid encoding", () => {
|
||||
expect(() => {
|
||||
fs.mkdtemp(testPath, options, () => {});
|
||||
}).toThrow(expectedError);
|
||||
});
|
||||
|
||||
it("mkdtempSync throws on invalid encoding", () => {
|
||||
expect(() => {
|
||||
fs.mkdtempSync(testPath, options);
|
||||
}).toThrow(expectedError);
|
||||
});
|
||||
|
||||
it.todo("ReadStream throws on invalid encoding", () => {
|
||||
expect(() => {
|
||||
fs.ReadStream(testPath, options);
|
||||
}).toThrow(expectedError);
|
||||
});
|
||||
|
||||
it.todo("WriteStream throws on invalid encoding", () => {
|
||||
expect(() => {
|
||||
fs.WriteStream(testPath, options);
|
||||
}).toThrow(expectedError);
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: port node.js tests for these
|
||||
it("fs.readv returns object", async done => {
|
||||
const fd = await promisify(fs.open)(import.meta.path, "r");
|
||||
|
||||
6
test/js/third_party/prompts/prompts.test.ts
vendored
6
test/js/third_party/prompts/prompts.test.ts
vendored
@@ -9,7 +9,11 @@ test("works with prompts", async () => {
|
||||
stdin: "pipe",
|
||||
});
|
||||
|
||||
await Bun.sleep(100);
|
||||
const reader = child.stdout.getReader();
|
||||
|
||||
await reader.read();
|
||||
reader.releaseLock();
|
||||
|
||||
child.stdin.write("dylan\n");
|
||||
await Bun.sleep(100);
|
||||
child.stdin.write("999\n");
|
||||
|
||||
@@ -756,6 +756,55 @@ it("ReadableStream for empty file closes immediately", async () => {
|
||||
expect(chunks.length).toBe(0);
|
||||
});
|
||||
|
||||
it("ReadableStream errors the stream on pull rejection", async () => {
|
||||
let stream = new ReadableStream({
|
||||
pull(controller) {
|
||||
return Promise.reject("pull rejected");
|
||||
},
|
||||
});
|
||||
|
||||
let reader = stream.getReader();
|
||||
let closed = reader.closed.catch(err => `closed: ${err}`);
|
||||
let read = reader.read().catch(err => `read: ${err}`);
|
||||
expect(await Promise.race([closed, read])).toBe("closed: pull rejected");
|
||||
expect(await read).toBe("read: pull rejected");
|
||||
});
|
||||
|
||||
it("ReadableStream rejects pending reads when the lock is released", async () => {
|
||||
let { resolve, promise } = Promise.withResolvers();
|
||||
let stream = new ReadableStream({
|
||||
async pull(controller) {
|
||||
controller.enqueue("123");
|
||||
await promise;
|
||||
controller.enqueue("456");
|
||||
controller.close();
|
||||
},
|
||||
});
|
||||
|
||||
let reader = stream.getReader();
|
||||
expect((await reader.read()).value).toBe("123");
|
||||
|
||||
let read = reader.read();
|
||||
reader.releaseLock();
|
||||
expect(read).rejects.toThrow(
|
||||
expect.objectContaining({
|
||||
name: "AbortError",
|
||||
code: "ERR_STREAM_RELEASE_LOCK",
|
||||
}),
|
||||
);
|
||||
expect(reader.closed).rejects.toThrow(
|
||||
expect.objectContaining({
|
||||
name: "AbortError",
|
||||
code: "ERR_STREAM_RELEASE_LOCK",
|
||||
}),
|
||||
);
|
||||
|
||||
resolve();
|
||||
|
||||
reader = stream.getReader();
|
||||
expect((await reader.read()).value).toBe("456");
|
||||
});
|
||||
|
||||
it("new Response(stream).arrayBuffer() (bytes)", async () => {
|
||||
var queue = [Buffer.from("abdefgh")];
|
||||
var stream = new ReadableStream({
|
||||
@@ -1053,3 +1102,42 @@ it("fs.createReadStream(filename) should be able to break inside async loop", as
|
||||
expect(true).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("pipeTo doesn't cause unhandled rejections on readable errors", async () => {
|
||||
// https://github.com/WebKit/WebKit/blob/3a75b5d2de94aa396a99b454ac47f3be9e0dc726/LayoutTests/streams/pipeTo-unhandled-promise.html
|
||||
let unhandledRejectionCaught = false;
|
||||
|
||||
const catchUnhandledRejection = () => {
|
||||
unhandledRejectionCaught = true;
|
||||
};
|
||||
process.on("unhandledRejection", catchUnhandledRejection);
|
||||
|
||||
const writable = new WritableStream();
|
||||
const readable = new ReadableStream({ start: c => c.error("error") });
|
||||
readable.pipeTo(writable).catch(() => {});
|
||||
|
||||
await Bun.sleep(15);
|
||||
|
||||
process.off("unhandledRejection", catchUnhandledRejection);
|
||||
|
||||
expect(unhandledRejectionCaught).toBe(false);
|
||||
});
|
||||
|
||||
it("pipeThrough doesn't cause unhandled rejections on readable errors", async () => {
|
||||
let unhandledRejectionCaught = false;
|
||||
|
||||
const catchUnhandledRejection = () => {
|
||||
unhandledRejectionCaught = true;
|
||||
};
|
||||
process.on("unhandledRejection", catchUnhandledRejection);
|
||||
|
||||
const readable = new ReadableStream({ start: c => c.error("error") });
|
||||
const ts = new TransformStream();
|
||||
readable.pipeThrough(ts);
|
||||
|
||||
await Bun.sleep(15);
|
||||
|
||||
process.off("unhandledRejection", catchUnhandledRejection);
|
||||
|
||||
expect(unhandledRejectionCaught).toBe(false);
|
||||
});
|
||||
|
||||
8
test/regression/issue/014865.test.ts
Normal file
8
test/regression/issue/014865.test.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { test, expect } from "bun:test";
|
||||
import { Request } from "node-fetch";
|
||||
|
||||
test("node fetch Request URL field is set even with a valid URL", () => {
|
||||
expect(new Request("/").url).toBe("/");
|
||||
expect(new Request("https://bun.sh/").url).toBe("https://bun.sh/");
|
||||
expect(new Request(new URL("https://bun.sh/")).url).toBe("https://bun.sh/");
|
||||
});
|
||||
Reference in New Issue
Block a user