Skip to content

Commit baf1322

Browse files
committed
fix(test): parse the -- delimiter and pin the flag end to end
Two review findings. hasCliFlag/isFullSuiteRun read the whole argv, so `test -- --parallel=2` suppressed the default --parallel even though everything after -- is passed through, and a bare - was classified as an option so `test -` was treated as a full-suite run. The tests also asserted only resolveBunTestArgs output: reverting the spawn call to a hardcoded argv left every assertion green. A spawn test now runs the wrapper against a non-matching filter and asserts bun reports PARALLEL.
1 parent 4518004 commit baf1322

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

‎scripts/test.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,18 @@ export function createIsolatedTestEnvironment(
6060
}
6161

6262
function hasCliFlag(requested: string[], name: string): boolean {
63-
return requested.some(arg => arg === name || arg.startsWith(`${name}=`));
63+
const delimiterIndex = requested.indexOf("--");
64+
const wrapperArgs = delimiterIndex === -1 ? requested : requested.slice(0, delimiterIndex);
65+
return wrapperArgs.some(arg => arg === name || arg.startsWith(`${name}=`));
6466
}
6567

6668
/** True for a filter-less `bun run test`. `--timeout` / `--dots` / `--parallel=N` still count. */
6769
function isFullSuiteRun(requested: string[]): boolean {
68-
return !requested.some(arg => arg !== "-" && !arg.startsWith("-"));
70+
const delimiterIndex = requested.indexOf("--");
71+
const wrapperArgs = delimiterIndex === -1 ? requested : requested.slice(0, delimiterIndex);
72+
const passedThrough = delimiterIndex === -1 ? [] : requested.slice(delimiterIndex + 1);
73+
return passedThrough.length === 0
74+
&& !wrapperArgs.some(arg => arg === "-" || !arg.startsWith("-"));
6975
}
7076

7177
/**

‎tests/test-runner.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ describe("bun test argv", () => {
8383
test("a file filter keeps isolate and parallel but no suite path", () => {
8484
expect(resolveBunTestArgs(["tests/foo.test.ts"]))
8585
.toEqual(["--isolate", "--parallel", "tests/foo.test.ts"]);
86+
expect(resolveBunTestArgs(["-"]))
87+
.toEqual(["--isolate", "--parallel", "-"]);
8688
});
8789

8890
test("a caller-supplied concurrency is left alone", () => {
@@ -96,4 +98,27 @@ describe("bun test argv", () => {
9698
expect(resolveBunTestArgs(["--timeout=30000"]))
9799
.toEqual(["--isolate", "--parallel", "--timeout=30000", "./tests/"]);
98100
});
101+
102+
test("arguments after the delimiter are passed through instead of parsed as wrapper flags", () => {
103+
expect(resolveBunTestArgs(["--", "--parallel=2"]))
104+
.toEqual(["--isolate", "--parallel", "--", "--parallel=2"]);
105+
});
106+
107+
test("the wrapper passes parallel execution through to bun", () => {
108+
const result = Bun.spawnSync([
109+
process.execPath,
110+
join(import.meta.dir, "../scripts/test.ts"),
111+
"--pass-with-no-tests",
112+
join(import.meta.dir, "__no_matching_test_file__.test.ts"),
113+
], {
114+
cwd: join(import.meta.dir, ".."),
115+
env: { ...process.env, OCX_TEST_NO_QUEUE: "1" },
116+
stdout: "pipe",
117+
stderr: "pipe",
118+
});
119+
120+
const output = new TextDecoder().decode(result.stdout)
121+
+ new TextDecoder().decode(result.stderr);
122+
expect(output).toContain("PARALLEL");
123+
});
99124
});

0 commit comments

Comments
 (0)