UNPKG

2.25 kBPlain TextView Raw
1#!/usr/bin/env node
2
3'use strict';
4
5/**
6 * This tiny wrapper file checks for known node flags and appends them
7 * when found, before invoking the "real" _mocha(1) executable.
8 */
9
10const spawn = require('child_process').spawn;
11const path = require('path');
12const getOptions = require('./options');
13const args = [path.join(__dirname, '_mocha')];
14
15// Load mocha.opts into process.argv
16// Must be loaded here to handle node-specific options
17getOptions();
18
19process.argv.slice(2).forEach(arg => {
20 const flag = arg.split('=')[0];
21
22 switch (flag) {
23 case '-d':
24 args.unshift('--debug');
25 args.push('--no-timeouts');
26 break;
27 case 'debug':
28 case '--debug':
29 case '--debug-brk':
30 case '--inspect':
31 case '--inspect-brk':
32 args.unshift(arg);
33 args.push('--no-timeouts');
34 break;
35 case '-gc':
36 case '--expose-gc':
37 args.unshift('--expose-gc');
38 break;
39 case '--gc-global':
40 case '--es_staging':
41 case '--no-deprecation':
42 case '--no-warnings':
43 case '--prof':
44 case '--log-timer-events':
45 case '--throw-deprecation':
46 case '--trace-deprecation':
47 case '--trace-warnings':
48 case '--use_strict':
49 case '--allow-natives-syntax':
50 case '--perf-basic-prof':
51 case '--napi-modules':
52 args.unshift(arg);
53 break;
54 default:
55 if (arg.indexOf('--harmony') === 0) {
56 args.unshift(arg);
57 } else if (arg.indexOf('--trace') === 0) {
58 args.unshift(arg);
59 } else if (arg.indexOf('--icu-data-dir') === 0) {
60 args.unshift(arg);
61 } else if (arg.indexOf('--max-old-space-size') === 0) {
62 args.unshift(arg);
63 } else if (arg.indexOf('--preserve-symlinks') === 0) {
64 args.unshift(arg);
65 } else {
66 args.push(arg);
67 }
68 break;
69 }
70});
71
72const proc = spawn(process.execPath, args, {
73 stdio: 'inherit'
74});
75proc.on('exit', (code, signal) => {
76 process.on('exit', () => {
77 if (signal) {
78 process.kill(process.pid, signal);
79 } else {
80 process.exit(code);
81 }
82 });
83});
84
85// terminate children.
86process.on('SIGINT', () => {
87 proc.kill('SIGINT'); // calls runner.abort()
88 proc.kill('SIGTERM'); // if that didn't work, we're probably in an infinite loop, so make it die.
89});