-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (43 loc) · 1.28 KB
/
index.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
exports.command = 'test';
exports.description = 'run unit tests with mochapack';
exports.builder = {};
exports.handler = argv => {
const execa = require('execa');
const bin = require.resolve('mochapack/bin/mochapack');
let rawArgv = [];
Object.keys(argv).forEach(row => {
const filter = [];
if (!filter.includes(row)) {
rawArgv.push(`--${row}`);
rawArgv.push(argv[row]);
}
});
let nodeArgs = [];
// const inspectPos = rawArgv.findIndex(arg => arg.startsWith('--inspect-brk'));
// if (inspectPos !== -1) {
// nodeArgs = rawArgv.splice(inspectPos, 1);
// }
const argvParams = [
...nodeArgs,
bin,
'--recursive',
'--require',
require.resolve('./setup.js'),
'--webpack-config',
require.resolve('./webpack.config.js'),
...rawArgv,
...['tests/**/*.spec.js']
];
return new Promise((resolve, reject) => {
const child = execa('node', argvParams, {stdio: 'inherit'});
child.on('error', reject);
child.on('exit', code => {
if (code !== 0) {
reject(`mochapack exited with code ${code}.`);
}
else {
resolve();
}
});
});
};