diff options
-rw-r--r-- | src/bun.js/node/types.zig | 1 | ||||
-rw-r--r-- | src/cli/test_command.zig | 2 | ||||
-rw-r--r-- | test/bun.js/print-process-args.js | 4 | ||||
-rw-r--r-- | test/bun.js/process-args.test.js | 33 |
4 files changed, 39 insertions, 1 deletions
diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index 693e4e19e..5e54066b9 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -1841,6 +1841,7 @@ pub const Process = struct { vm.argv.len + 2, ) catch unreachable; var args_list = std.ArrayListUnmanaged(JSC.ZigString){ .items = args, .capacity = args.len }; + args_list.items.len = 0; // get the bun executable // without paying the cost of a syscall to resolve the full path diff --git a/src/cli/test_command.zig b/src/cli/test_command.zig index 77b2493d5..88942c012 100644 --- a/src/cli/test_command.zig +++ b/src/cli/test_command.zig @@ -327,7 +327,7 @@ pub const TestCommand = struct { js_ast.Expr.Data.Store.create(default_allocator); js_ast.Stmt.Data.Store.create(default_allocator); var vm = try JSC.VirtualMachine.init(ctx.allocator, ctx.args, null, ctx.log, env_loader); - vm.argv = ctx.positionals; + vm.argv = ctx.passthrough; try vm.bundler.configureDefines(); vm.bundler.options.rewrite_jest_for_tests = true; diff --git a/test/bun.js/print-process-args.js b/test/bun.js/print-process-args.js new file mode 100644 index 000000000..3d4540053 --- /dev/null +++ b/test/bun.js/print-process-args.js @@ -0,0 +1,4 @@ +var writer = Bun.stdout.writer() +writer.write(JSON.stringify(process.argv)); +await writer.flush(true); +process.exit(0);
\ No newline at end of file diff --git a/test/bun.js/process-args.test.js b/test/bun.js/process-args.test.js new file mode 100644 index 000000000..6bdfbf9e0 --- /dev/null +++ b/test/bun.js/process-args.test.js @@ -0,0 +1,33 @@ + +import { spawn } from "bun"; +import { test, expect } from "bun:test"; + +test("args exclude run", async () => { + const arg0 = process.argv[0]; + const arg1 = import.meta.dir + '/print-process-args.js'; + + const exe = process.versions.bun.includes("debug") ? "bun-debug" : "bun"; + + const { stdout: s1 } = spawn([exe, "print-process-args.js"], { cwd: import.meta.dir }); + const t1 = JSON.parse(await new Response(s1).text()); + expect(t1[0]).toBe(arg0); + expect(t1[1]).toBe(arg1); + + const { stdout: s2 } = spawn([exe, "print-process-args.js", "arg1"], { cwd: import.meta.dir }); + const t2 = JSON.parse(await new Response(s2).text()); + expect(t2[0]).toBe(arg0); + expect(t2[1]).toBe(arg1); + expect(t2[2]).toBe("arg1"); + + const { stdout: s3 } = spawn([exe, "run", "print-process-args.js"], { cwd: import.meta.dir }); + const t3 = JSON.parse(await new Response(s3).text()); + expect(t3[0]).toBe(arg0); + expect(t3[1]).toBe(arg1); + + const { stdout: s4 } = spawn([exe, "run", "print-process-args.js", "arg1", "arg2"], { cwd: import.meta.dir }); + const t4 = JSON.parse(await new Response(s4).text()); + expect(t4[0]).toBe(arg0); + expect(t4[1]).toBe(arg1); + expect(t4[2]).toBe("arg1"); + expect(t4[3]).toBe("arg2"); +});
\ No newline at end of file |