-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathtest_unit.js
75 lines (65 loc) · 1.74 KB
/
test_unit.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
* @license MIT
*/
const cp = require('child_process');
const path = require('path');
const COVERAGE_LINES_THRESHOLD = 40;
// Add `out` to the NODE_PATH so absolute paths can be resolved.
const env = { ...process.env };
env.NODE_PATH = path.resolve(__dirname, '../out-esbuild');
let testFiles = ['**/out-esbuild/**/*.test.js'];
let flagArgs = [];
if (process.argv.length > 2) {
const args = process.argv.slice(2);
flagArgs = args.filter(e => e.startsWith('--'));
// ability to inject particular test files via
// yarn test [testFileA testFileB ...]
files = args.filter(e => !e.startsWith('--'));
if (files.length) {
testFiles = files;
}
}
const checkCoverage = flagArgs.indexOf('--coverage') >= 0;
if (checkCoverage) {
flagArgs.splice(flagArgs.indexOf('--coverage'), 1);
const executable = npmBinScript('nyc');
const args = [
'--check-coverage',
`--lines=${COVERAGE_LINES_THRESHOLD}`,
'--exclude=out-esbuild/vs/**',
npmBinScript('mocha'),
...testFiles,
...flagArgs
];
console.info('executable', executable);
console.info('args', args);
const run = cp.spawnSync(
executable,
args,
{
cwd: path.resolve(__dirname, '..'),
env,
shell: true,
stdio: 'inherit'
}
);
process.exit(run.status);
}
const run = cp.spawnSync(
npmBinScript('mocha'),
[...testFiles, ...flagArgs],
{
cwd: path.resolve(__dirname, '..'),
env,
shell: true,
stdio: 'inherit'
}
);
function npmBinScript(script) {
return path.resolve(__dirname, `../node_modules/.bin/` + (process.platform === 'win32' ? `${script}.cmd` : script));
}
if (run.error) {
console.error(run.error);
}
process.exit(run.status ?? -1);