-
Notifications
You must be signed in to change notification settings - Fork 0
/
cover.js
65 lines (54 loc) · 1.46 KB
/
cover.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
#!/usr/bin/env node
/**
* This wrapper runs coverage analysis in valid environment.
* Usage:
* node node_modules/saby-units/cover[ --amd] path/to/your/test/runner.js
*/
const spawn = require('child_process').spawn;
const path = require('path');
const util = require('./lib/util');
const pathTo = util.pathTo;
const config = util.getConfig();
const inheritedArgs = process.argv.slice(2);
const args = [
path.join(pathTo('nyc'), 'bin', 'nyc')
];
const amdFlagAt = inheritedArgs.indexOf('--amd');
if (amdFlagAt === -1) {
//args.push('--require', 'babel-register', '--sourceMap', 'false', '--instrument', 'false');
} else {
inheritedArgs.splice(amdFlagAt, 1);
}
if (config.nyc) {
args.push(`-n=${config.nyc.include.join('|')}`);
args.push(`--report-dir=${config.nyc.reportDir}`);
args.push(`--reporter=${config.nyc.report}`);
args.push('--cache=false');
args.push(`--cwd=${config.nyc.cwd}`);
}
args.push(path.join(pathTo('mocha'), 'bin', 'mocha'));
args.push.apply(args, inheritedArgs);
const proc = spawn(
process.execPath,
args,
{stdio: 'inherit'}
);
proc.on('exit', (code, signal) => {
if (signal) {
process.kill(process.pid, signal);
} else {
process.exit(0);
}
});
process.on('exit', () => {
process.exitCode = 0;
});
// Terminate children on force exit
process.on('SIGINT', () => {
proc.kill('SIGINT');
proc.kill('SIGTERM');
});
process.on('SIGTERM', () => {
proc.kill('SIGINT');
proc.kill('SIGTERM');
});