aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/process-args.test.js
blob: 512b6b92cc78b25c7b6e3e8a7c7a4d1c78f8072a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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");
});