Skip to content

Commit 03d5734

Browse files
committed
fix(tests): add filters to test command
1 parent 5d4830c commit 03d5734

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

scripts/test.ts

+24-15
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import { spawn } from "node:child_process";
22
import isMain from "is-main";
33

4-
async function runTests(
5-
nodeOptions: string[] = [],
4+
async function runTests({
5+
nodeOptions = [],
6+
filesFilter = "",
67
program = "node",
7-
programOptions: string[] = [],
8-
env: Record<string, string> = {},
9-
): Promise<void> {
8+
programOptions = [],
9+
env = {},
10+
}: {
11+
nodeOptions?: string[];
12+
filesFilter?: string;
13+
program?: string;
14+
programOptions?: string[];
15+
env?: Record<string, string>;
16+
}): Promise<void> {
1017
const time = Date.now();
1118

1219
return new Promise((resolve, reject) => {
@@ -18,7 +25,7 @@ async function runTests(
1825
"--experimental-strip-types",
1926
"--test",
2027
...nodeOptions,
21-
"src/**/*.test.ts",
28+
filesFilter !== "" ? filesFilter : "src/**/*.test.ts",
2229
],
2330
{ stdio: "inherit", env: { ...process.env, ...env } },
2431
);
@@ -38,27 +45,29 @@ async function runTests(
3845
}
3946

4047
if (isMain(import.meta)) {
48+
const filesFilter = process.argv.slice(3).join(" ").trim();
49+
4150
if (process.argv[2] === "test") {
42-
await runTests();
51+
await runTests({ filesFilter });
4352
}
4453

4554
if (process.argv[2] === "test:inspect") {
46-
await runTests(["--inspect"]);
55+
await runTests({ nodeOptions: ["--inspect"], filesFilter });
4756
}
4857

4958
if (process.argv[2] === "test:watch") {
50-
await runTests(["--watch"]);
59+
await runTests({ nodeOptions: ["--watch"], filesFilter });
5160
}
5261

5362
if (process.argv[2] === "test:coverage") {
54-
await runTests(
55-
["--experimental-test-coverage"],
56-
"c8",
57-
["-r", "html", "node"],
58-
{
63+
await runTests({
64+
nodeOptions: ["--experimental-test-coverage"],
65+
program: "c8",
66+
programOptions: ["-r", "html", "node"],
67+
env: {
5968
// biome-ignore lint/style/useNamingConvention: node options
6069
NODE_V8_COVERAGE: "./coverage",
6170
},
62-
);
71+
});
6372
}
6473
}

0 commit comments

Comments
 (0)