diff --git a/.vscode/launch.json b/.vscode/launch.json index 1940f06653..d443761407 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -430,9 +430,13 @@ "name": "BUN_DEBUG_QUIET_LOGS", "value": "1" }, + { + "name": "BUN_DEBUG_jest", + "value": "1" + }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", - "value": "2" + "value": "1" } ] }, @@ -452,6 +456,18 @@ "name": "BUN_DEBUG_QUIET_LOGS", "value": "1" }, + { + "name": "BUN_DEBUG_EventLoop", + "value": "1" + }, + { + "name": "BUN_DEBUG_SYS", + "value": "1" + }, + { + "name": "BUN_DEBUG_PipeWriter", + "value": "1" + }, { "name": "BUN_GARBAGE_COLLECTOR_LEVEL", "value": "2" diff --git a/packages/bun-inspector-frontend/bun.lockb b/packages/bun-inspector-frontend/bun.lockb index 9133cce88c..053ac06792 100755 Binary files a/packages/bun-inspector-frontend/bun.lockb and b/packages/bun-inspector-frontend/bun.lockb differ diff --git a/packages/bun-internal-test/bun.lockb b/packages/bun-internal-test/bun.lockb index cef9d5e7e6..78a096d6a2 100755 Binary files a/packages/bun-internal-test/bun.lockb and b/packages/bun-internal-test/bun.lockb differ diff --git a/packages/bun-usockets/src/eventing/libuv.c b/packages/bun-usockets/src/eventing/libuv.c index e57f0164d3..b5c3d8c8d2 100644 --- a/packages/bun-usockets/src/eventing/libuv.c +++ b/packages/bun-usockets/src/eventing/libuv.c @@ -197,6 +197,7 @@ void us_loop_free(struct us_loop_t *loop) { void us_loop_run(struct us_loop_t *loop) { us_loop_integrate(loop); + uv_update_time(loop->uv_loop); uv_run(loop->uv_loop, UV_RUN_ONCE); } diff --git a/src/bun.js/webcore/blob/ReadFile.zig b/src/bun.js/webcore/blob/ReadFile.zig index 6febb718cd..5e045134d3 100644 --- a/src/bun.js/webcore/blob/ReadFile.zig +++ b/src/bun.js/webcore/blob/ReadFile.zig @@ -564,7 +564,7 @@ pub const ReadFileUV = struct { on_complete_fn: ReadFile.OnReadFileCallback, is_regular_file: bool = false, - req: libuv.fs_t = libuv.fs_t.uninitialized, + req: libuv.fs_t = std.mem.zeroes(libuv.fs_t), pub fn start(loop: *libuv.Loop, store: *Store, off: SizeType, max_len: SizeType, comptime Handler: type, handler: *anyopaque) void { log("ReadFileUV.start", .{}); @@ -630,7 +630,8 @@ pub const ReadFileUV = struct { return; } - this.req.assertCleanedUp(); + this.req.deinit(); + this.req.data = this; if (libuv.uv_fs_fstat(this.loop, &this.req, bun.uvfdcast(opened_fd), &onFileInitialStat).errEnum()) |errno| { this.errno = bun.errnoToZigErr(errno); diff --git a/src/io/PipeWriter.zig b/src/io/PipeWriter.zig index 053e8de714..3d53546e00 100644 --- a/src/io/PipeWriter.zig +++ b/src/io/PipeWriter.zig @@ -1092,6 +1092,7 @@ pub fn WindowsStreamingWriter( this.closeWithoutReporting(); return; } + // success means that we send all the data inside current_payload const written = this.current_payload.size(); this.current_payload.reset(); diff --git a/src/js/builtins/ProcessObjectInternals.ts b/src/js/builtins/ProcessObjectInternals.ts index 38c68893c2..5425ac5026 100644 --- a/src/js/builtins/ProcessObjectInternals.ts +++ b/src/js/builtins/ProcessObjectInternals.ts @@ -364,6 +364,10 @@ export function windowsEnv(internalEnv: InternalEnvMap, envMapList: Array { + return { ...internalEnv }; + }; + return new Proxy(internalEnv, { get(_, p) { return typeof p === "string" ? internalEnv[p.toUpperCase()] : undefined; diff --git a/src/js/node/child_process.js b/src/js/node/child_process.js index cf88291026..f97ca55839 100644 --- a/src/js/node/child_process.js +++ b/src/js/node/child_process.js @@ -1217,7 +1217,6 @@ class ChildProcess extends EventEmitter { // TODO: better ipc support const ipc = $isArray(stdio) && stdio[3] === "ipc"; - var env = options.envPairs || undefined; const detachedOption = options.detached; this.#encoding = options.encoding || undefined; @@ -1595,7 +1594,7 @@ const validateObject = (value, name, options = null) => { const nullable = options?.nullable ?? false; if ( (!nullable && value === null) || - (!allowArray && ArrayIsArray.$call(value)) || + (!allowArray && $isJSArray(value)) || (typeof value !== "object" && (!allowFunction || typeof value !== "function")) ) { throw new ERR_INVALID_ARG_TYPE(name, "object", value); diff --git a/test/bundler/__snapshots__/bun-build-api.test.ts.snap b/test/bundler/__snapshots__/bun-build-api.test.ts.snap index 08a1b40f3d..30746b67d6 100644 --- a/test/bundler/__snapshots__/bun-build-api.test.ts.snap +++ b/test/bundler/__snapshots__/bun-build-api.test.ts.snap @@ -1,117 +1,117 @@ -// Bun Snapshot v1, https://goo.gl/fbAQLP - -exports[`Bun.build BuildArtifact properties: hash 1`] = `"e4885a8bc2de343a"`; - -exports[`Bun.build BuildArtifact properties + entry.naming: hash 1`] = `"cb8abf3391c2971f"`; - -exports[`Bun.build BuildArtifact properties sourcemap: hash index.js 1`] = `"e4885a8bc2de343a"`; - -exports[`Bun.build BuildArtifact properties sourcemap: hash index.js.map 1`] = `"0000000000000000"`; - -exports[`Bun.build Bun.write(BuildArtifact) 1`] = ` -"var __defProp = Object.defineProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { - get: all[name], - enumerable: true, - configurable: true, - set: (newValue) => all[name] = () => newValue - }); -}; -var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res); - -// test/bundler/fixtures/trivial/fn.js -var exports_fn = {}; -__export(exports_fn, { - fn: () => { - { - return fn; - } - } -}); -function fn(a) { - return a + 42; -} -var init_fn = __esm(() => { -}); - -// test/bundler/fixtures/trivial/index.js -var NS = Promise.resolve().then(() => (init_fn(), exports_fn)); -NS.then(({ fn: fn2 }) => { - console.log(fn2(42)); -}); -" -`; - -exports[`Bun.build outdir + reading out blobs works 1`] = ` -"var __defProp = Object.defineProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { - get: all[name], - enumerable: true, - configurable: true, - set: (newValue) => all[name] = () => newValue - }); -}; -var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res); - -// test/bundler/fixtures/trivial/fn.js -var exports_fn = {}; -__export(exports_fn, { - fn: () => { - { - return fn; - } - } -}); -function fn(a) { - return a + 42; -} -var init_fn = __esm(() => { -}); - -// test/bundler/fixtures/trivial/index.js -var NS = Promise.resolve().then(() => (init_fn(), exports_fn)); -NS.then(({ fn: fn2 }) => { - console.log(fn2(42)); -}); -" -`; - -exports[`Bun.build new Response(BuildArtifact) sets content type: response text 1`] = ` -"var __defProp = Object.defineProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { - get: all[name], - enumerable: true, - configurable: true, - set: (newValue) => all[name] = () => newValue - }); -}; -var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res); - -// test/bundler/fixtures/trivial/fn.js -var exports_fn = {}; -__export(exports_fn, { - fn: () => { - { - return fn; - } - } -}); -function fn(a) { - return a + 42; -} -var init_fn = __esm(() => { -}); - -// test/bundler/fixtures/trivial/index.js -var NS = Promise.resolve().then(() => (init_fn(), exports_fn)); -NS.then(({ fn: fn2 }) => { - console.log(fn2(42)); -}); -" -`; +// Bun Snapshot v1, https://goo.gl/fbAQLP + +exports[`Bun.build BuildArtifact properties: hash 1`] = `"e4885a8bc2de343a"`; + +exports[`Bun.build BuildArtifact properties + entry.naming: hash 1`] = `"cb8abf3391c2971f"`; + +exports[`Bun.build BuildArtifact properties sourcemap: hash index.js 1`] = `"e4885a8bc2de343a"`; + +exports[`Bun.build BuildArtifact properties sourcemap: hash index.js.map 1`] = `"0000000000000000"`; + +exports[`Bun.build Bun.write(BuildArtifact) 1`] = ` +"var __defProp = Object.defineProperty; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { + get: all[name], + enumerable: true, + configurable: true, + set: (newValue) => all[name] = () => newValue + }); +}; +var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res); + +// test/bundler/fixtures/trivial/fn.js +var exports_fn = {}; +__export(exports_fn, { + fn: () => { + { + return fn; + } + } +}); +function fn(a) { + return a + 42; +} +var init_fn = __esm(() => { +}); + +// test/bundler/fixtures/trivial/index.js +var NS = Promise.resolve().then(() => (init_fn(), exports_fn)); +NS.then(({ fn: fn2 }) => { + console.log(fn2(42)); +}); +" +`; + +exports[`Bun.build outdir + reading out blobs works 1`] = ` +"var __defProp = Object.defineProperty; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { + get: all[name], + enumerable: true, + configurable: true, + set: (newValue) => all[name] = () => newValue + }); +}; +var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res); + +// test/bundler/fixtures/trivial/fn.js +var exports_fn = {}; +__export(exports_fn, { + fn: () => { + { + return fn; + } + } +}); +function fn(a) { + return a + 42; +} +var init_fn = __esm(() => { +}); + +// test/bundler/fixtures/trivial/index.js +var NS = Promise.resolve().then(() => (init_fn(), exports_fn)); +NS.then(({ fn: fn2 }) => { + console.log(fn2(42)); +}); +" +`; + +exports[`Bun.build new Response(BuildArtifact) sets content type: response text 1`] = ` +"var __defProp = Object.defineProperty; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { + get: all[name], + enumerable: true, + configurable: true, + set: (newValue) => all[name] = () => newValue + }); +}; +var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res); + +// test/bundler/fixtures/trivial/fn.js +var exports_fn = {}; +__export(exports_fn, { + fn: () => { + { + return fn; + } + } +}); +function fn(a) { + return a + 42; +} +var init_fn = __esm(() => { +}); + +// test/bundler/fixtures/trivial/index.js +var NS = Promise.resolve().then(() => (init_fn(), exports_fn)); +NS.then(({ fn: fn2 }) => { + console.log(fn2(42)); +}); +" +`; diff --git a/test/js/node/child_process/child-process-stdio.test.js b/test/js/node/child_process/child-process-stdio.test.js index 40a9fa0efc..424fddb815 100644 --- a/test/js/node/child_process/child-process-stdio.test.js +++ b/test/js/node/child_process/child-process-stdio.test.js @@ -78,14 +78,14 @@ describe("process.stdin", () => { child.stdin.end(input); }); - it("should allow us to read > 65kb from stdin", done => { + it.only("should allow us to read > 65kb from stdin", done => { const numReps = Math.ceil((1024 * 1024) / 5); const input = Buffer.alloc("hello".length * numReps) .fill("hello") .toString(); // Child should read from stdin and write it back const child = spawn(bunExe(), [CHILD_PROCESS_FILE, "STDIN", "FLOWING"], { - env: { ...bunEnv, BUN_DEBUG_QUIET_LOGS: "0", BUN_DEBUG: "/tmp/out.log" }, + env: { ...bunEnv, BUN_DEBUG_QUIET_LOGS: "1" }, stdio: ["pipe", "pipe", "inherit"], }); let data = ""; diff --git a/test/js/node/child_process/fixtures/child-process-echo-options.js b/test/js/node/child_process/fixtures/child-process-echo-options.js index 7d6298bd02..0f5be894af 100644 --- a/test/js/node/child_process/fixtures/child-process-echo-options.js +++ b/test/js/node/child_process/fixtures/child-process-echo-options.js @@ -1,2 +1,3 @@ // TODO - bun has no `send` method in the process -process?.send({ env: process.env }); +const out = { env: { ...process.env } }; +process?.send(out); diff --git a/test/js/node/fs/fs.test.ts b/test/js/node/fs/fs.test.ts index 428ef3cf8d..7553485223 100644 --- a/test/js/node/fs/fs.test.ts +++ b/test/js/node/fs/fs.test.ts @@ -1481,7 +1481,7 @@ describe("rmdirSync", () => { }); }); -describe.skipIf(isWindows)("createReadStream", () => { +describe("createReadStream", () => { it("works (1 chunk)", async () => { return await new Promise((resolve, reject) => { var stream = createReadStream(import.meta.dir + "/readFileSync.txt", {}); diff --git a/test/js/node/process/process-stdin-echo.js b/test/js/node/process/process-stdin-echo.js index 0475586258..77dabcb545 100644 --- a/test/js/node/process/process-stdin-echo.js +++ b/test/js/node/process/process-stdin-echo.js @@ -2,10 +2,10 @@ process.stdin.setEncoding("utf8"); process.stdin.on("data", data => { process.stdout.write(data); }); -process.stdin.once(process.argv[2] == "close-event" ? "close" : "end", () => { - process.stdout.write(process.argv[2] == "close-event" ? "ENDED-CLOSE" : "ENDED"); +process.stdin.once(process.argv[2] === "close-event" ? "close" : "end", () => { + process.stdout.write(process.argv[2] === "close-event" ? "ENDED-CLOSE" : "ENDED"); }); -if (process.argv[2] == "resume") { +if (process.argv[2] === "resume") { process.stdout.write("RESUMED"); process.stdin.resume(); } diff --git a/test/js/third_party/es-module-lexer/es-module-lexer.test.ts b/test/js/third_party/es-module-lexer/es-module-lexer.test.ts index 2202a61a67..e9f7ebbbd6 100644 --- a/test/js/third_party/es-module-lexer/es-module-lexer.test.ts +++ b/test/js/third_party/es-module-lexer/es-module-lexer.test.ts @@ -1,5 +1,5 @@ import { test, expect } from "bun:test"; -import { spawnSync } from "bun"; +import { spawn } from "bun"; import { bunEnv, bunExe } from "../../../harness"; import { join } from "path"; @@ -11,13 +11,13 @@ import { join } from "path"; // // At the time of writing, this includes WebAssembly compilation and Atomics // It excludes FinalizationRegistry since that doesn't need to keep the process alive. -test("es-module-lexer consistently loads", () => { +test("es-module-lexer consistently loads", async () => { for (let i = 0; i < 10; i++) { - const { stdout, exitCode } = spawnSync({ + const { stdout, exited } = spawn({ cmd: [bunExe(), join(import.meta.dir, "index.ts")], env: bunEnv, }); - expect(JSON.parse(stdout?.toString())).toEqual({ + expect(await new Response(stdout).json()).toEqual({ imports: [ { n: "b", @@ -40,6 +40,6 @@ test("es-module-lexer consistently loads", () => { }, ], }); - expect(exitCode).toBe(42); + expect(await exited).toBe(42); } });