Skip to content

Commit cda73fe

Browse files
committed
fix: make npm test cross-platform
node --test <directory> walks the directory on Node 18 but tries to require it as a module on Node 22 (windows-latest ships 22.x), so CI was failing with MODULE_NOT_FOUND. Replace the directory argument with a small enumerator script that reads the compiled test dir and passes every *.test.js file explicitly to node --test — works on any node version on any OS.
1 parent 924970f commit cda73fe

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
@@ -16,7 +16,7 @@
1616
"start:agent": "node build/node/core/agent/src/server.js",
1717
"build:mac-app": "./scripts/build/rebuild-native-app.sh",
1818
"build:overlay": "./scripts/build/build-overlay.sh",
19-
"test": "npm run build && node --test build/node/core/agent/test"
19+
"test": "npm run build && node scripts/test/run-tests.mjs"
2020
},
2121
"devDependencies": {
2222
"@types/node": "^22.15.3",

scripts/test/run-tests.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env node
2+
import { readdirSync, existsSync } from "node:fs";
3+
import { join, posix } from "node:path";
4+
import { spawnSync } from "node:child_process";
5+
6+
const testDir = "build/node/core/agent/test";
7+
8+
if (!existsSync(testDir)) {
9+
console.error(`test directory not found: ${testDir} (did you run "npm run build"?)`);
10+
process.exit(1);
11+
}
12+
13+
const files = readdirSync(testDir, { recursive: true })
14+
.filter((entry) => typeof entry === "string" && entry.endsWith(".test.js"))
15+
.map((entry) => posix.join(testDir, entry.split(/[\\/]/).join("/")));
16+
17+
if (files.length === 0) {
18+
console.error(`no compiled test files under ${testDir}`);
19+
process.exit(1);
20+
}
21+
22+
const result = spawnSync(process.execPath, ["--test", ...files], {
23+
stdio: "inherit"
24+
});
25+
26+
process.exit(result.status ?? 1);

0 commit comments

Comments
 (0)