Skip to content

Commit 16e6810

Browse files
committed
fix: add cross-platform test runner for Node 20 compatibility
1 parent cf56131 commit 16e6810

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"format:check": "prettier --check 'src/**/*.{ts,tsx}'",
3333
"check": "npm run typecheck && npm run lint && npm run format:check",
3434
"build": "npm run check && npm run bundle && node -e \"require('fs').chmodSync('dist/cli.js', 0o755)\"",
35-
"test": "tsx --test \"src/tests/*.test.ts\"",
35+
"test": "node src/tests/run-tests.mjs",
3636
"test:single": "tsx --test",
3737
"prepack": "npm run build",
3838
"prepare": "husky"

src/tests/run-tests.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Cross-platform test runner: finds all *.test.ts files and runs them via tsx.
2+
// Needed because glob expansion in npm scripts behaves differently across
3+
// shells and Node versions (particularly Node 20 on Windows).
4+
/* eslint-disable */
5+
6+
import { spawnSync } from "child_process";
7+
import { readdirSync } from "fs";
8+
import { fileURLToPath } from "url";
9+
import { dirname, join } from "path";
10+
11+
const __dirname = dirname(fileURLToPath(import.meta.url));
12+
13+
const testFiles = readdirSync(__dirname)
14+
.filter((f) => f.endsWith(".test.ts"))
15+
.map((f) => join(__dirname, f))
16+
.sort();
17+
18+
// Resolve tsx from the project root
19+
const tsx = new URL("../../node_modules/.bin/tsx", import.meta.url).pathname;
20+
21+
const result = spawnSync(process.execPath, [tsx, "--test", ...testFiles], {
22+
stdio: "inherit",
23+
cwd: join(__dirname, "../.."),
24+
});
25+
26+
process.exit(result.status ?? 1);

0 commit comments

Comments
 (0)