-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathtest.mjs
More file actions
59 lines (51 loc) · 1.31 KB
/
test.mjs
File metadata and controls
59 lines (51 loc) · 1.31 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
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
// Note: can be converted to ts file once node 20 support is dropped.
// Node 20 does not support --experimental-strip-types flag.
import {spawn} from 'node:child_process';
import path from 'node:path';
import process from 'node:process';
const args = process.argv.slice(2);
const userArgs = args.filter(arg => !arg.startsWith('-'));
const flags = args.filter(arg => arg.startsWith('-'));
const files = [];
if (userArgs.length > 0) {
for (const arg of userArgs) {
// Map .ts files to build/ .js files
let testPath = arg;
if (testPath.endsWith('.ts')) {
testPath = testPath.replace(/\.ts$/, '.js');
if (!testPath.startsWith('build/')) {
testPath = path.join('build', testPath);
}
}
files.push(testPath);
}
} else {
const isNode20 = process.version.startsWith('v20.');
if (isNode20) {
files.push('build/tests');
} else {
files.push('build/tests/**/*.test.js');
}
}
const nodeArgs = [
'--import',
'./build/tests/setup.js',
'--no-warnings=ExperimentalWarning',
'--test-reporter',
'spec',
'--test-force-exit',
'--test',
...flags,
...files,
];
const child = spawn('node', nodeArgs, {
stdio: 'inherit',
});
child.on('close', code => {
process.exit(code ?? 1);
});