mocha 5.1.1 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +686 -984
- package/README.md +2 -1
- package/{images → assets/growl}/error.png +0 -0
- package/{images → assets/growl}/ok.png +0 -0
- package/bin/_mocha +4 -595
- package/bin/mocha +121 -61
- package/bin/options.js +6 -39
- package/browser-entry.js +21 -17
- package/lib/browser/growl.js +165 -2
- package/lib/browser/progress.js +11 -11
- package/lib/{template.html → browser/template.html} +0 -0
- package/lib/browser/tty.js +2 -2
- package/lib/cli/cli.js +68 -0
- package/lib/cli/commands.js +13 -0
- package/lib/cli/config.js +79 -0
- package/lib/cli/index.js +9 -0
- package/lib/cli/init.js +37 -0
- package/lib/cli/node-flags.js +69 -0
- package/lib/cli/one-and-dones.js +70 -0
- package/lib/cli/options.js +330 -0
- package/lib/cli/run-helpers.js +337 -0
- package/lib/cli/run-option-metadata.js +76 -0
- package/lib/cli/run.js +297 -0
- package/lib/context.js +14 -14
- package/lib/errors.js +141 -0
- package/lib/growl.js +136 -0
- package/lib/hook.js +5 -16
- package/lib/interfaces/bdd.js +16 -13
- package/lib/interfaces/common.js +62 -18
- package/lib/interfaces/exports.js +5 -8
- package/lib/interfaces/qunit.js +10 -10
- package/lib/interfaces/tdd.js +12 -11
- package/lib/mocha.js +477 -256
- package/lib/mocharc.json +10 -0
- package/lib/pending.js +1 -5
- package/lib/reporters/base.js +95 -117
- package/lib/reporters/doc.js +23 -9
- package/lib/reporters/dot.js +19 -13
- package/lib/reporters/html.js +82 -47
- package/lib/reporters/json-stream.js +43 -23
- package/lib/reporters/json.js +32 -23
- package/lib/reporters/landing.js +16 -9
- package/lib/reporters/list.js +19 -11
- package/lib/reporters/markdown.js +18 -12
- package/lib/reporters/min.js +8 -4
- package/lib/reporters/nyan.js +42 -35
- package/lib/reporters/progress.js +12 -7
- package/lib/reporters/spec.js +23 -12
- package/lib/reporters/tap.js +250 -32
- package/lib/reporters/xunit.js +61 -35
- package/lib/runnable.js +152 -95
- package/lib/runner.js +296 -248
- package/lib/stats-collector.js +83 -0
- package/lib/suite.js +294 -75
- package/lib/test.js +16 -15
- package/lib/utils.js +419 -146
- package/mocha.js +4589 -2228
- package/package.json +137 -38
- package/lib/ms.js +0 -94
- package/lib/reporters/base.js.orig +0 -498
- package/lib/reporters/json.js.orig +0 -128
package/README.md
CHANGED
|
@@ -11,9 +11,10 @@
|
|
|
11
11
|
|
|
12
12
|
## Links
|
|
13
13
|
|
|
14
|
-
- **[Documentation](https://mochajs.org)**
|
|
14
|
+
- **[Documentation](https://mochajs.org/)**
|
|
15
15
|
- **[Release Notes / History / Changes](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)**
|
|
16
16
|
- [Code of Conduct](https://github.com/mochajs/mocha/blob/master/.github/CODE_OF_CONDUCT.md)
|
|
17
|
+
- [Contributing](https://github.com/mochajs/mocha/blob/master/.github/CONTRIBUTING.md)
|
|
17
18
|
- [Gitter Chatroom](https://gitter.im/mochajs/mocha) (ask questions here!)
|
|
18
19
|
- [Google Group](https://groups.google.com/group/mochajs)
|
|
19
20
|
- [Issue Tracker](https://github.com/mochajs/mocha/issues)
|
|
File without changes
|
|
File without changes
|
package/bin/_mocha
CHANGED
|
@@ -1,601 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
/* eslint no-unused-vars: off */
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Module dependencies.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const program = require('commander');
|
|
11
|
-
const path = require('path');
|
|
12
|
-
const fs = require('fs');
|
|
13
|
-
const minimatch = require('minimatch');
|
|
14
|
-
const resolve = path.resolve;
|
|
15
|
-
const exists = fs.existsSync;
|
|
16
|
-
const Mocha = require('../');
|
|
17
|
-
const utils = Mocha.utils;
|
|
18
|
-
const interfaceNames = Object.keys(Mocha.interfaces);
|
|
19
|
-
const join = path.join;
|
|
20
|
-
const cwd = process.cwd();
|
|
21
|
-
const getOptions = require('./options');
|
|
22
|
-
const mocha = new Mocha();
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Save timer references to avoid Sinon interfering (see GH-237).
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
const Date = global.Date;
|
|
29
|
-
const setTimeout = global.setTimeout;
|
|
30
|
-
const setInterval = global.setInterval;
|
|
31
|
-
const clearTimeout = global.clearTimeout;
|
|
32
|
-
const clearInterval = global.clearInterval;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Exits Mocha when tests + code under test has finished execution (default)
|
|
36
|
-
* @param {number} code - Exit code; typically # of failures
|
|
37
|
-
*/
|
|
38
|
-
const exitLater = code => {
|
|
39
|
-
process.on('exit', () => {
|
|
40
|
-
process.exit(Math.min(code, 255));
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Exits Mocha when Mocha itself has finished execution, regardless of
|
|
46
|
-
* what the tests or code under test is doing.
|
|
47
|
-
* @param {number} code - Exit code; typically # of failures
|
|
48
|
-
*/
|
|
49
|
-
const exit = code => {
|
|
50
|
-
const clampedCode = Math.min(code, 255);
|
|
51
|
-
let draining = 0;
|
|
52
|
-
|
|
53
|
-
// Eagerly set the process's exit code in case stream.write doesn't
|
|
54
|
-
// execute its callback before the process terminates.
|
|
55
|
-
process.exitCode = clampedCode;
|
|
56
|
-
|
|
57
|
-
// flush output for Node.js Windows pipe bug
|
|
58
|
-
// https://github.com/joyent/node/issues/6247 is just one bug example
|
|
59
|
-
// https://github.com/visionmedia/mocha/issues/333 has a good discussion
|
|
60
|
-
const done = () => {
|
|
61
|
-
if (!(draining--)) {
|
|
62
|
-
process.exit(clampedCode);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const streams = [process.stdout, process.stderr];
|
|
67
|
-
|
|
68
|
-
streams.forEach(stream => {
|
|
69
|
-
// submit empty write request and wait for completion
|
|
70
|
-
draining += 1;
|
|
71
|
-
stream.write('', done);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
done();
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Parse list.
|
|
79
|
-
*/
|
|
80
|
-
const list = str => str.split(/ *, */);
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Parse multiple flag.
|
|
84
|
-
*/
|
|
85
|
-
const collect = (val, memo) => memo.concat(val);
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Hide the cursor.
|
|
89
|
-
*/
|
|
90
|
-
const hideCursor = () => {
|
|
91
|
-
process.stdout.write('\u001b[?25l');
|
|
92
|
-
};
|
|
93
|
-
|
|
94
4
|
/**
|
|
95
|
-
*
|
|
5
|
+
* This file remains for backwards compatibility only.
|
|
6
|
+
* Don't put stuff in this file.
|
|
7
|
+
* @see module:lib/cli
|
|
96
8
|
*/
|
|
97
|
-
const showCursor = () => {
|
|
98
|
-
process.stdout.write('\u001b[?25h');
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Stop play()ing.
|
|
103
|
-
*/
|
|
104
|
-
const stop = () => {
|
|
105
|
-
process.stdout.write('\u001b[2K');
|
|
106
|
-
clearInterval(play.timer);
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Play the given array of strings.
|
|
111
|
-
*/
|
|
112
|
-
const play = (arr, interval) => {
|
|
113
|
-
const len = arr.length;
|
|
114
|
-
interval = interval || 100;
|
|
115
|
-
let i = 0;
|
|
116
|
-
|
|
117
|
-
play.timer = setInterval(() => {
|
|
118
|
-
const str = arr[i++ % len];
|
|
119
|
-
process.stdout.write(`\u001b[0G${str}`);
|
|
120
|
-
}, interval);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Files.
|
|
125
|
-
*/
|
|
126
|
-
|
|
127
|
-
let files = [];
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Globals.
|
|
131
|
-
*/
|
|
132
|
-
|
|
133
|
-
let globals = [];
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Requires.
|
|
137
|
-
*/
|
|
138
|
-
|
|
139
|
-
const requires = [];
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Images.
|
|
143
|
-
*/
|
|
144
|
-
|
|
145
|
-
const images = {
|
|
146
|
-
fail: path.join(__dirname, '..', 'images', 'error.png'),
|
|
147
|
-
pass: path.join(__dirname, '..', 'images', 'ok.png')
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
// options
|
|
151
|
-
|
|
152
|
-
program
|
|
153
|
-
.version(JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8')).version)
|
|
154
|
-
.usage('[debug] [options] [files]')
|
|
155
|
-
.option('-A, --async-only', 'force all tests to take a callback (async) or return a promise')
|
|
156
|
-
.option('-c, --colors', 'force enabling of colors')
|
|
157
|
-
.option('-C, --no-colors', 'force disabling of colors')
|
|
158
|
-
.option('-G, --growl', 'enable growl notification support')
|
|
159
|
-
.option('-O, --reporter-options <k=v,k2=v2,...>', 'reporter-specific options')
|
|
160
|
-
.option('-R, --reporter <name>', 'specify the reporter to use', 'spec')
|
|
161
|
-
.option('-S, --sort', 'sort test files')
|
|
162
|
-
.option('-b, --bail', 'bail after first test failure')
|
|
163
|
-
.option('-d, --debug', "enable node's debugger, synonym for node --debug")
|
|
164
|
-
.option('-g, --grep <pattern>', 'only run tests matching <pattern>')
|
|
165
|
-
.option('-f, --fgrep <string>', 'only run tests containing <string>')
|
|
166
|
-
.option('-gc, --expose-gc', 'expose gc extension')
|
|
167
|
-
.option('-i, --invert', 'inverts --grep and --fgrep matches')
|
|
168
|
-
.option('-r, --require <name>', 'require the given module')
|
|
169
|
-
.option('-s, --slow <ms>', '"slow" test threshold in milliseconds [75]')
|
|
170
|
-
.option('-t, --timeout <ms>', 'set test-case timeout in milliseconds [2000]')
|
|
171
|
-
.option('-u, --ui <name>', `specify user-interface (${interfaceNames.join('|')})`, 'bdd')
|
|
172
|
-
.option('-w, --watch', 'watch files for changes')
|
|
173
|
-
.option('--check-leaks', 'check for global variable leaks')
|
|
174
|
-
.option('--full-trace', 'display the full stack trace')
|
|
175
|
-
.option('--compilers <ext>:<module>,...', 'use the given module(s) to compile files', list, [])
|
|
176
|
-
.option('--debug-brk', "enable node's debugger breaking on the first line")
|
|
177
|
-
.option('--globals <names>', 'allow the given comma-delimited global [names]', list, [])
|
|
178
|
-
.option('--es_staging', 'enable all staged features')
|
|
179
|
-
.option('--harmony<_classes,_generators,...>', 'all node --harmony* flags are available')
|
|
180
|
-
.option('--preserve-symlinks', 'Instructs the module loader to preserve symbolic links when resolving and caching modules')
|
|
181
|
-
.option('--icu-data-dir', 'include ICU data')
|
|
182
|
-
.option('--inline-diffs', 'display actual/expected differences inline within each string')
|
|
183
|
-
.option('--no-diff', 'do not show a diff on failure')
|
|
184
|
-
.option('--inspect', 'activate devtools in chrome')
|
|
185
|
-
.option('--inspect-brk', 'activate devtools in chrome and break on the first line')
|
|
186
|
-
.option('--interfaces', 'display available interfaces')
|
|
187
|
-
.option('--no-deprecation', 'silence deprecation warnings')
|
|
188
|
-
.option('--exit', 'force shutdown of the event loop after test run: mocha will call process.exit')
|
|
189
|
-
.option('--no-timeouts', 'disables timeouts, given implicitly with --debug')
|
|
190
|
-
.option('--no-warnings', 'silence all node process warnings')
|
|
191
|
-
.option('--opts <path>', 'specify opts path', 'test/mocha.opts')
|
|
192
|
-
.option('--perf-basic-prof', 'enable perf linux profiler (basic support)')
|
|
193
|
-
.option('--napi-modules', 'enable experimental NAPI modules')
|
|
194
|
-
.option('--prof', 'log statistical profiling information')
|
|
195
|
-
.option('--log-timer-events', 'Time events including external callbacks')
|
|
196
|
-
.option('--recursive', 'include sub directories')
|
|
197
|
-
.option('--reporters', 'display available reporters')
|
|
198
|
-
.option('--retries <times>', 'set numbers of time to retry a failed test case')
|
|
199
|
-
.option('--throw-deprecation', 'throw an exception anytime a deprecated function is used')
|
|
200
|
-
.option('--trace', 'trace function calls')
|
|
201
|
-
.option('--trace-deprecation', 'show stack traces on deprecations')
|
|
202
|
-
.option('--trace-warnings', 'show stack traces on node process warnings')
|
|
203
|
-
.option('--use_strict', 'enforce strict mode')
|
|
204
|
-
.option('--watch-extensions <ext>,...', 'additional extensions to monitor with --watch', list, [])
|
|
205
|
-
.option('--delay', 'wait for async suite definition')
|
|
206
|
-
.option('--allow-uncaught', 'enable uncaught errors to propagate')
|
|
207
|
-
.option('--forbid-only', 'causes test marked with only to fail the suite')
|
|
208
|
-
.option('--forbid-pending', 'causes pending tests and test marked with skip to fail the suite')
|
|
209
|
-
.option('--file <file>', 'include a file to be ran during the suite', collect, [])
|
|
210
|
-
.option('--exclude <file>', 'a file or glob pattern to ignore', collect, []);
|
|
211
|
-
|
|
212
|
-
program._name = 'mocha';
|
|
213
|
-
|
|
214
|
-
// init command
|
|
215
|
-
|
|
216
|
-
program
|
|
217
|
-
.command('init <path>')
|
|
218
|
-
.description('initialize a client-side mocha setup at <path>')
|
|
219
|
-
.action(path => {
|
|
220
|
-
const mkdir = require('mkdirp');
|
|
221
|
-
mkdir.sync(path);
|
|
222
|
-
const css = fs.readFileSync(join(__dirname, '..', 'mocha.css'));
|
|
223
|
-
const js = fs.readFileSync(join(__dirname, '..', 'mocha.js'));
|
|
224
|
-
const tmpl = fs.readFileSync(join(__dirname, '..', 'lib/template.html'));
|
|
225
|
-
fs.writeFileSync(join(path, 'mocha.css'), css);
|
|
226
|
-
fs.writeFileSync(join(path, 'mocha.js'), js);
|
|
227
|
-
fs.writeFileSync(join(path, 'tests.js'), '');
|
|
228
|
-
fs.writeFileSync(join(path, 'index.html'), tmpl);
|
|
229
|
-
process.exit(0);
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
// --globals
|
|
233
|
-
|
|
234
|
-
program.on('option:globals', val => {
|
|
235
|
-
globals = globals.concat(list(val));
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
// --reporters
|
|
239
|
-
|
|
240
|
-
program.on('option:reporters', () => {
|
|
241
|
-
console.log();
|
|
242
|
-
console.log(' dot - dot matrix');
|
|
243
|
-
console.log(' doc - html documentation');
|
|
244
|
-
console.log(' spec - hierarchical spec list');
|
|
245
|
-
console.log(' json - single json object');
|
|
246
|
-
console.log(' progress - progress bar');
|
|
247
|
-
console.log(' list - spec-style listing');
|
|
248
|
-
console.log(' tap - test-anything-protocol');
|
|
249
|
-
console.log(' landing - unicode landing strip');
|
|
250
|
-
console.log(' xunit - xunit reporter');
|
|
251
|
-
console.log(' min - minimal reporter (great with --watch)');
|
|
252
|
-
console.log(' json-stream - newline delimited json events');
|
|
253
|
-
console.log(' markdown - markdown documentation (github flavour)');
|
|
254
|
-
console.log(' nyan - nyan cat!');
|
|
255
|
-
console.log();
|
|
256
|
-
process.exit();
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
// --interfaces
|
|
260
|
-
|
|
261
|
-
program.on('option:interfaces', () => {
|
|
262
|
-
console.log('');
|
|
263
|
-
interfaceNames.forEach(interfaceName => {
|
|
264
|
-
console.log(` ${interfaceName}`);
|
|
265
|
-
});
|
|
266
|
-
console.log('');
|
|
267
|
-
process.exit();
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
// -r, --require
|
|
271
|
-
|
|
272
|
-
module.paths.push(cwd, join(cwd, 'node_modules'));
|
|
273
|
-
|
|
274
|
-
program.on('option:require', mod => {
|
|
275
|
-
const abs = exists(mod) || exists(`${mod}.js`);
|
|
276
|
-
if (abs) {
|
|
277
|
-
mod = resolve(mod);
|
|
278
|
-
}
|
|
279
|
-
requires.push(mod);
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
// If not already done, load mocha.opts
|
|
283
|
-
if (!process.env.LOADED_MOCHA_OPTS) {
|
|
284
|
-
getOptions();
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
// parse args
|
|
288
|
-
|
|
289
|
-
program.parse(process.argv);
|
|
290
|
-
|
|
291
|
-
// infinite stack traces
|
|
292
|
-
|
|
293
|
-
Error.stackTraceLimit = Infinity; // TODO: config
|
|
294
|
-
|
|
295
|
-
// reporter options
|
|
296
|
-
|
|
297
|
-
const reporterOptions = {};
|
|
298
|
-
if (program.reporterOptions !== undefined) {
|
|
299
|
-
program.reporterOptions.split(',').forEach(opt => {
|
|
300
|
-
const L = opt.split('=');
|
|
301
|
-
if (L.length > 2 || L.length === 0) {
|
|
302
|
-
throw new Error(`invalid reporter option '${opt}'`);
|
|
303
|
-
} else if (L.length === 2) {
|
|
304
|
-
reporterOptions[L[0]] = L[1];
|
|
305
|
-
} else {
|
|
306
|
-
reporterOptions[L[0]] = true;
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// reporter
|
|
312
|
-
|
|
313
|
-
mocha.reporter(program.reporter, reporterOptions);
|
|
314
|
-
|
|
315
|
-
// load reporter
|
|
316
|
-
|
|
317
|
-
let Reporter = null;
|
|
318
|
-
try {
|
|
319
|
-
Reporter = require(`../lib/reporters/${program.reporter}`);
|
|
320
|
-
} catch (err) {
|
|
321
|
-
try {
|
|
322
|
-
Reporter = require(program.reporter);
|
|
323
|
-
} catch (err2) {
|
|
324
|
-
throw new Error(`reporter "${program.reporter}" does not exist`);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
// --no-colors
|
|
329
|
-
|
|
330
|
-
if (!program.colors) {
|
|
331
|
-
mocha.useColors(false);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
// --colors
|
|
335
|
-
|
|
336
|
-
if (~process.argv.indexOf('--colors') || ~process.argv.indexOf('-c')) {
|
|
337
|
-
mocha.useColors(true);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
// --inline-diffs
|
|
341
|
-
|
|
342
|
-
if (program.inlineDiffs) {
|
|
343
|
-
mocha.useInlineDiffs(true);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
// --no-diff
|
|
347
|
-
|
|
348
|
-
if (process.argv.indexOf('--no-diff') !== -1) {
|
|
349
|
-
mocha.hideDiff(true);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// --slow <ms>
|
|
353
|
-
|
|
354
|
-
if (program.slow) {
|
|
355
|
-
mocha.suite.slow(program.slow);
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
// --no-timeouts
|
|
359
|
-
|
|
360
|
-
if (!program.timeouts) {
|
|
361
|
-
mocha.enableTimeouts(false);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
// --timeout
|
|
365
|
-
|
|
366
|
-
if (program.timeout) {
|
|
367
|
-
mocha.suite.timeout(program.timeout);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// --bail
|
|
371
|
-
|
|
372
|
-
mocha.suite.bail(program.bail);
|
|
373
|
-
|
|
374
|
-
// --grep
|
|
375
|
-
|
|
376
|
-
if (program.grep) {
|
|
377
|
-
mocha.grep(program.grep);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// --fgrep
|
|
381
|
-
|
|
382
|
-
if (program.fgrep) {
|
|
383
|
-
mocha.fgrep(program.fgrep);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
// --invert
|
|
387
|
-
|
|
388
|
-
if (program.invert) {
|
|
389
|
-
mocha.invert();
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// --check-leaks
|
|
393
|
-
|
|
394
|
-
if (program.checkLeaks) {
|
|
395
|
-
mocha.checkLeaks();
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
// --stack-trace
|
|
399
|
-
|
|
400
|
-
if (program.fullTrace) {
|
|
401
|
-
mocha.fullTrace();
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
// --growl
|
|
405
|
-
|
|
406
|
-
if (program.growl) {
|
|
407
|
-
mocha.growl();
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
// --async-only
|
|
411
|
-
|
|
412
|
-
if (program.asyncOnly) {
|
|
413
|
-
mocha.asyncOnly();
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
// --delay
|
|
417
|
-
|
|
418
|
-
if (program.delay) {
|
|
419
|
-
mocha.delay();
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
// --allow-uncaught
|
|
423
|
-
|
|
424
|
-
if (program.allowUncaught) {
|
|
425
|
-
mocha.allowUncaught();
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
// --globals
|
|
429
|
-
|
|
430
|
-
mocha.globals(globals);
|
|
431
|
-
|
|
432
|
-
// --retries
|
|
433
|
-
|
|
434
|
-
if (program.retries) {
|
|
435
|
-
mocha.suite.retries(program.retries);
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
// --forbid-only
|
|
439
|
-
|
|
440
|
-
if (program.forbidOnly) mocha.forbidOnly();
|
|
441
|
-
|
|
442
|
-
// --forbid-pending
|
|
443
|
-
|
|
444
|
-
if (program.forbidPending) mocha.forbidPending();
|
|
445
|
-
|
|
446
|
-
// custom compiler support
|
|
447
|
-
|
|
448
|
-
if (program.compilers.length > 0) {
|
|
449
|
-
require('util').deprecate(() => {},
|
|
450
|
-
'"--compilers" will be removed in a future version of Mocha; see https://git.io/vdcSr for more info')();
|
|
451
|
-
}
|
|
452
|
-
const extensions = ['js'];
|
|
453
|
-
program.compilers.forEach(c => {
|
|
454
|
-
const idx = c.indexOf(':');
|
|
455
|
-
const ext = c.slice(0, idx);
|
|
456
|
-
let mod = c.slice(idx + 1);
|
|
457
|
-
|
|
458
|
-
if (mod[0] === '.') {
|
|
459
|
-
mod = join(process.cwd(), mod);
|
|
460
|
-
}
|
|
461
|
-
require(mod);
|
|
462
|
-
extensions.push(ext);
|
|
463
|
-
program.watchExtensions.push(ext);
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
// requires
|
|
467
|
-
|
|
468
|
-
requires.forEach(mod => {
|
|
469
|
-
require(mod);
|
|
470
|
-
});
|
|
471
|
-
|
|
472
|
-
// interface
|
|
473
|
-
|
|
474
|
-
mocha.ui(program.ui);
|
|
475
|
-
|
|
476
|
-
// args
|
|
477
|
-
|
|
478
|
-
const args = program.args;
|
|
479
|
-
|
|
480
|
-
// default files to test/*.{js,coffee}
|
|
481
|
-
|
|
482
|
-
if (!args.length) {
|
|
483
|
-
args.push('test');
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
args.forEach(arg => {
|
|
487
|
-
let newFiles;
|
|
488
|
-
try {
|
|
489
|
-
newFiles = utils.lookupFiles(arg, extensions, program.recursive);
|
|
490
|
-
} catch (err) {
|
|
491
|
-
if (err.message.indexOf('cannot resolve path') === 0) {
|
|
492
|
-
console.error(`Warning: Could not find any test files matching pattern: ${arg}`);
|
|
493
|
-
return;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
throw err;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
if (typeof newFiles !== 'undefined') {
|
|
500
|
-
if (typeof newFiles === 'string') {
|
|
501
|
-
newFiles = [newFiles];
|
|
502
|
-
}
|
|
503
|
-
newFiles = newFiles.filter(fileName => program.exclude.every(pattern => !minimatch(fileName, pattern)));
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
files = files.concat(newFiles);
|
|
507
|
-
});
|
|
508
|
-
|
|
509
|
-
if (!files.length) {
|
|
510
|
-
console.error('No test files found');
|
|
511
|
-
process.exit(1);
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
// resolve
|
|
515
|
-
let fileArgs = program.file.map(path => resolve(path));
|
|
516
|
-
files = files.map(path => resolve(path));
|
|
517
|
-
|
|
518
|
-
if (program.sort) {
|
|
519
|
-
files.sort();
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
// add files given through --file to be ran first
|
|
523
|
-
files = fileArgs.concat(files);
|
|
524
|
-
|
|
525
|
-
// --watch
|
|
526
|
-
|
|
527
|
-
let runner;
|
|
528
|
-
let loadAndRun;
|
|
529
|
-
let purge;
|
|
530
|
-
let rerun;
|
|
531
|
-
|
|
532
|
-
if (program.watch) {
|
|
533
|
-
console.log();
|
|
534
|
-
hideCursor();
|
|
535
|
-
process.on('SIGINT', () => {
|
|
536
|
-
showCursor();
|
|
537
|
-
console.log('\n');
|
|
538
|
-
process.exit(130);
|
|
539
|
-
});
|
|
540
|
-
|
|
541
|
-
const watchFiles = utils.files(cwd, [ 'js' ].concat(program.watchExtensions));
|
|
542
|
-
let runAgain = false;
|
|
543
|
-
|
|
544
|
-
loadAndRun = () => {
|
|
545
|
-
try {
|
|
546
|
-
mocha.files = files;
|
|
547
|
-
runAgain = false;
|
|
548
|
-
runner = mocha.run(() => {
|
|
549
|
-
runner = null;
|
|
550
|
-
if (runAgain) {
|
|
551
|
-
rerun();
|
|
552
|
-
}
|
|
553
|
-
});
|
|
554
|
-
} catch (e) {
|
|
555
|
-
console.log(e.stack);
|
|
556
|
-
}
|
|
557
|
-
};
|
|
558
|
-
|
|
559
|
-
purge = () => {
|
|
560
|
-
watchFiles.forEach(file => {
|
|
561
|
-
delete require.cache[file];
|
|
562
|
-
});
|
|
563
|
-
};
|
|
564
|
-
|
|
565
|
-
loadAndRun();
|
|
566
|
-
|
|
567
|
-
rerun = () => {
|
|
568
|
-
purge();
|
|
569
|
-
stop();
|
|
570
|
-
if (!program.grep) {
|
|
571
|
-
mocha.grep(null);
|
|
572
|
-
}
|
|
573
|
-
mocha.suite = mocha.suite.clone();
|
|
574
|
-
mocha.suite.ctx = new Mocha.Context();
|
|
575
|
-
mocha.ui(program.ui);
|
|
576
|
-
loadAndRun();
|
|
577
|
-
};
|
|
578
|
-
|
|
579
|
-
utils.watch(watchFiles, () => {
|
|
580
|
-
runAgain = true;
|
|
581
|
-
if (runner) {
|
|
582
|
-
runner.abort();
|
|
583
|
-
} else {
|
|
584
|
-
rerun();
|
|
585
|
-
}
|
|
586
|
-
});
|
|
587
|
-
} else {
|
|
588
|
-
// load
|
|
589
|
-
|
|
590
|
-
mocha.files = files;
|
|
591
|
-
runner = mocha.run(program.exit ? exit : exitLater);
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
process.on('SIGINT', () => {
|
|
595
|
-
runner.abort();
|
|
596
9
|
|
|
597
|
-
|
|
598
|
-
// Instead of `process.exit(130)`, set runner.failures to 130 (exit code for SIGINT)
|
|
599
|
-
// The amount of failures will be emitted as error code later
|
|
600
|
-
runner.failures = 130;
|
|
601
|
-
});
|
|
10
|
+
require('../lib/cli').main();
|