-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest.js
More file actions
46 lines (38 loc) · 1.61 KB
/
test.js
File metadata and controls
46 lines (38 loc) · 1.61 KB
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
42
43
44
45
46
#!/usr/bin/env node
/**
* Test runner wrapper that configures Node.js for the TypeScript migration
* before spawning vitest. Adds --experimental-strip-types on Node >= 22.6
* so child processes can execute .ts files natively.
*/
import { spawnSync } from 'node:child_process';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { dirname, resolve } from 'node:path';
const __dirname = dirname(fileURLToPath(import.meta.url));
const hook = pathToFileURL(resolve(__dirname, 'ts-resolver-hook.js')).href;
const args = process.argv.slice(2);
const vitestBin = resolve(__dirname, '..', 'node_modules', 'vitest', 'vitest.mjs');
const [major, minor] = process.versions.node.split('.').map(Number);
const supportsStripTypes = major > 22 || (major === 22 && minor >= 6);
// Build NODE_OPTIONS: resolver hook + type stripping (Node >= 22.6)
const hookImport = `--import ${hook}`;
const existing = process.env.NODE_OPTIONS || '';
const parts = [
existing.includes(hookImport) ? null : hookImport,
supportsStripTypes && !existing.includes('--experimental-strip-types') && !existing.includes('--strip-types')
? (major >= 23 ? '--strip-types' : '--experimental-strip-types')
: null,
existing || null,
].filter(Boolean);
// Spawn vitest via node directly — avoids shell: true and works cross-platform
const result = spawnSync(process.execPath, [vitestBin, ...args], {
stdio: 'inherit',
env: {
...process.env,
NODE_OPTIONS: parts.join(' '),
},
});
if (result.error) {
process.stderr.write(`[test runner] Failed to spawn vitest: ${result.error.message}\n`);
process.exit(1);
}
process.exit(result.status ?? 1);