mocha 3.5.3 → 5.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 +1040 -959
- package/CHANGELOG.md.orig +1736 -0
- package/README.md +81 -85
- package/README.md.orig +132 -0
- package/bin/.eslintrc.yml +3 -0
- package/bin/_mocha +173 -153
- package/bin/mocha +12 -10
- package/bin/options.js +8 -6
- package/browser-entry.js +3 -3
- package/lib/browser/{.eslintrc.yaml → .eslintrc.yml} +0 -0
- package/lib/browser/growl.js +5 -0
- package/lib/context.js +10 -23
- package/lib/interfaces/bdd.js +1 -1
- package/lib/interfaces/common.js +0 -3
- package/lib/mocha.js +23 -1
- package/lib/ms.js +4 -44
- package/lib/reporters/base.js +41 -45
- package/lib/reporters/base.js.orig +498 -0
- package/lib/reporters/json-stream.js +0 -1
- package/lib/reporters/progress.js +7 -5
- package/lib/reporters/xunit.js +21 -6
- package/lib/runnable.js +17 -11
- package/lib/runner.js +42 -31
- package/lib/suite.js +25 -13
- package/lib/test.js +3 -5
- package/lib/utils.js +19 -198
- package/mocha.js +3268 -4599
- package/package.json +32 -34
- package/bower.json +0 -38
- package/lib/browser/debug.js +0 -7
- package/lib/browser/events.js +0 -195
- package/lib/to-iso-string/LICENSE +0 -19
- package/lib/to-iso-string/index.js +0 -37
package/bin/_mocha
CHANGED
|
@@ -7,52 +7,141 @@
|
|
|
7
7
|
* Module dependencies.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
const program = require('commander');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const resolve = path.resolve;
|
|
14
|
+
const exists = fs.existsSync;
|
|
15
|
+
const Mocha = require('../');
|
|
16
|
+
const utils = Mocha.utils;
|
|
17
|
+
const interfaceNames = Object.keys(Mocha.interfaces);
|
|
18
|
+
const join = path.join;
|
|
19
|
+
const cwd = process.cwd();
|
|
20
|
+
const getOptions = require('./options');
|
|
21
|
+
const mocha = new Mocha();
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Save timer references to avoid Sinon interfering (see GH-237).
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
const Date = global.Date;
|
|
28
|
+
const setTimeout = global.setTimeout;
|
|
29
|
+
const setInterval = global.setInterval;
|
|
30
|
+
const clearTimeout = global.clearTimeout;
|
|
31
|
+
const clearInterval = global.clearInterval;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Exits Mocha when tests + code under test has finished execution (default)
|
|
35
|
+
* @param {number} code - Exit code; typically # of failures
|
|
36
|
+
*/
|
|
37
|
+
const exitLater = code => {
|
|
38
|
+
process.on('exit', () => {
|
|
39
|
+
process.exit(Math.min(code, 255));
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Exits Mocha when Mocha itself has finished execution, regardless of
|
|
45
|
+
* what the tests or code under test is doing.
|
|
46
|
+
* @param {number} code - Exit code; typically # of failures
|
|
47
|
+
*/
|
|
48
|
+
const exit = code => {
|
|
49
|
+
const clampedCode = Math.min(code, 255);
|
|
50
|
+
let draining = 0;
|
|
51
|
+
|
|
52
|
+
// Eagerly set the process's exit code in case stream.write doesn't
|
|
53
|
+
// execute its callback before the process terminates.
|
|
54
|
+
process.exitCode = clampedCode;
|
|
55
|
+
|
|
56
|
+
// flush output for Node.js Windows pipe bug
|
|
57
|
+
// https://github.com/joyent/node/issues/6247 is just one bug example
|
|
58
|
+
// https://github.com/visionmedia/mocha/issues/333 has a good discussion
|
|
59
|
+
const done = () => {
|
|
60
|
+
if (!(draining--)) {
|
|
61
|
+
process.exit(clampedCode);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const streams = [process.stdout, process.stderr];
|
|
66
|
+
|
|
67
|
+
streams.forEach(stream => {
|
|
68
|
+
// submit empty write request and wait for completion
|
|
69
|
+
draining += 1;
|
|
70
|
+
stream.write('', done);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
done();
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Parse list.
|
|
78
|
+
*/
|
|
79
|
+
const list = str => str.split(/ *, */);
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Parse multiple flag.
|
|
83
|
+
*/
|
|
84
|
+
const collect = (val, memo) => memo.concat(val);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Hide the cursor.
|
|
88
|
+
*/
|
|
89
|
+
const hideCursor = () => {
|
|
90
|
+
process.stdout.write('\u001b[?25l');
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Show the cursor.
|
|
95
|
+
*/
|
|
96
|
+
const showCursor = () => {
|
|
97
|
+
process.stdout.write('\u001b[?25h');
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Stop play()ing.
|
|
102
|
+
*/
|
|
103
|
+
const stop = () => {
|
|
104
|
+
process.stdout.write('\u001b[2K');
|
|
105
|
+
clearInterval(play.timer);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Play the given array of strings.
|
|
110
|
+
*/
|
|
111
|
+
const play = (arr, interval) => {
|
|
112
|
+
const len = arr.length;
|
|
113
|
+
interval = interval || 100;
|
|
114
|
+
let i = 0;
|
|
115
|
+
|
|
116
|
+
play.timer = setInterval(() => {
|
|
117
|
+
const str = arr[i++ % len];
|
|
118
|
+
process.stdout.write(`\u001b[0G${str}`);
|
|
119
|
+
}, interval);
|
|
120
|
+
};
|
|
32
121
|
|
|
33
122
|
/**
|
|
34
123
|
* Files.
|
|
35
124
|
*/
|
|
36
125
|
|
|
37
|
-
|
|
126
|
+
let files = [];
|
|
38
127
|
|
|
39
128
|
/**
|
|
40
129
|
* Globals.
|
|
41
130
|
*/
|
|
42
131
|
|
|
43
|
-
|
|
132
|
+
let globals = [];
|
|
44
133
|
|
|
45
134
|
/**
|
|
46
135
|
* Requires.
|
|
47
136
|
*/
|
|
48
137
|
|
|
49
|
-
|
|
138
|
+
const requires = [];
|
|
50
139
|
|
|
51
140
|
/**
|
|
52
141
|
* Images.
|
|
53
142
|
*/
|
|
54
143
|
|
|
55
|
-
|
|
144
|
+
const images = {
|
|
56
145
|
fail: path.join(__dirname, '..', 'images', 'error.png'),
|
|
57
146
|
pass: path.join(__dirname, '..', 'images', 'ok.png')
|
|
58
147
|
};
|
|
@@ -78,7 +167,7 @@ program
|
|
|
78
167
|
.option('-r, --require <name>', 'require the given module')
|
|
79
168
|
.option('-s, --slow <ms>', '"slow" test threshold in milliseconds [75]')
|
|
80
169
|
.option('-t, --timeout <ms>', 'set test-case timeout in milliseconds [2000]')
|
|
81
|
-
.option('-u, --ui <name>',
|
|
170
|
+
.option('-u, --ui <name>', `specify user-interface (${interfaceNames.join('|')})`, 'bdd')
|
|
82
171
|
.option('-w, --watch', 'watch files for changes')
|
|
83
172
|
.option('--check-leaks', 'check for global variable leaks')
|
|
84
173
|
.option('--full-trace', 'display the full stack trace')
|
|
@@ -90,11 +179,12 @@ program
|
|
|
90
179
|
.option('--preserve-symlinks', 'Instructs the module loader to preserve symbolic links when resolving and caching modules')
|
|
91
180
|
.option('--icu-data-dir', 'include ICU data')
|
|
92
181
|
.option('--inline-diffs', 'display actual/expected differences inline within each string')
|
|
182
|
+
.option('--no-diff', 'do not show a diff on failure')
|
|
93
183
|
.option('--inspect', 'activate devtools in chrome')
|
|
94
184
|
.option('--inspect-brk', 'activate devtools in chrome and break on the first line')
|
|
95
185
|
.option('--interfaces', 'display available interfaces')
|
|
96
186
|
.option('--no-deprecation', 'silence deprecation warnings')
|
|
97
|
-
.option('--
|
|
187
|
+
.option('--exit', 'force shutdown of the event loop after test run: mocha will call process.exit')
|
|
98
188
|
.option('--no-timeouts', 'disables timeouts, given implicitly with --debug')
|
|
99
189
|
.option('--no-warnings', 'silence all node process warnings')
|
|
100
190
|
.option('--opts <path>', 'specify opts path', 'test/mocha.opts')
|
|
@@ -114,7 +204,8 @@ program
|
|
|
114
204
|
.option('--delay', 'wait for async suite definition')
|
|
115
205
|
.option('--allow-uncaught', 'enable uncaught errors to propagate')
|
|
116
206
|
.option('--forbid-only', 'causes test marked with only to fail the suite')
|
|
117
|
-
.option('--forbid-pending', 'causes pending tests and test marked with skip to fail the suite')
|
|
207
|
+
.option('--forbid-pending', 'causes pending tests and test marked with skip to fail the suite')
|
|
208
|
+
.option('--file <file>', 'include a file to be ran during the suite', collect, []);
|
|
118
209
|
|
|
119
210
|
program._name = 'mocha';
|
|
120
211
|
|
|
@@ -123,12 +214,12 @@ program._name = 'mocha';
|
|
|
123
214
|
program
|
|
124
215
|
.command('init <path>')
|
|
125
216
|
.description('initialize a client-side mocha setup at <path>')
|
|
126
|
-
.action(
|
|
127
|
-
|
|
217
|
+
.action(path => {
|
|
218
|
+
const mkdir = require('mkdirp');
|
|
128
219
|
mkdir.sync(path);
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
220
|
+
const css = fs.readFileSync(join(__dirname, '..', 'mocha.css'));
|
|
221
|
+
const js = fs.readFileSync(join(__dirname, '..', 'mocha.js'));
|
|
222
|
+
const tmpl = fs.readFileSync(join(__dirname, '..', 'lib/template.html'));
|
|
132
223
|
fs.writeFileSync(join(path, 'mocha.css'), css);
|
|
133
224
|
fs.writeFileSync(join(path, 'mocha.js'), js);
|
|
134
225
|
fs.writeFileSync(join(path, 'tests.js'), '');
|
|
@@ -138,13 +229,13 @@ program
|
|
|
138
229
|
|
|
139
230
|
// --globals
|
|
140
231
|
|
|
141
|
-
program.on('globals',
|
|
232
|
+
program.on('option:globals', val => {
|
|
142
233
|
globals = globals.concat(list(val));
|
|
143
234
|
});
|
|
144
235
|
|
|
145
236
|
// --reporters
|
|
146
237
|
|
|
147
|
-
program.on('reporters',
|
|
238
|
+
program.on('option:reporters', () => {
|
|
148
239
|
console.log();
|
|
149
240
|
console.log(' dot - dot matrix');
|
|
150
241
|
console.log(' doc - html documentation');
|
|
@@ -165,10 +256,10 @@ program.on('reporters', function () {
|
|
|
165
256
|
|
|
166
257
|
// --interfaces
|
|
167
258
|
|
|
168
|
-
program.on('interfaces',
|
|
259
|
+
program.on('option:interfaces', () => {
|
|
169
260
|
console.log('');
|
|
170
|
-
interfaceNames.forEach(
|
|
171
|
-
console.log(
|
|
261
|
+
interfaceNames.forEach(interfaceName => {
|
|
262
|
+
console.log(` ${interfaceName}`);
|
|
172
263
|
});
|
|
173
264
|
console.log('');
|
|
174
265
|
process.exit();
|
|
@@ -178,8 +269,8 @@ program.on('interfaces', function () {
|
|
|
178
269
|
|
|
179
270
|
module.paths.push(cwd, join(cwd, 'node_modules'));
|
|
180
271
|
|
|
181
|
-
program.on('require',
|
|
182
|
-
|
|
272
|
+
program.on('option:require', mod => {
|
|
273
|
+
const abs = exists(mod) || exists(`${mod}.js`);
|
|
183
274
|
if (abs) {
|
|
184
275
|
mod = resolve(mod);
|
|
185
276
|
}
|
|
@@ -201,12 +292,12 @@ Error.stackTraceLimit = Infinity; // TODO: config
|
|
|
201
292
|
|
|
202
293
|
// reporter options
|
|
203
294
|
|
|
204
|
-
|
|
295
|
+
const reporterOptions = {};
|
|
205
296
|
if (program.reporterOptions !== undefined) {
|
|
206
|
-
program.reporterOptions.split(',').forEach(
|
|
207
|
-
|
|
297
|
+
program.reporterOptions.split(',').forEach(opt => {
|
|
298
|
+
const L = opt.split('=');
|
|
208
299
|
if (L.length > 2 || L.length === 0) {
|
|
209
|
-
throw new Error(
|
|
300
|
+
throw new Error(`invalid reporter option '${opt}'`);
|
|
210
301
|
} else if (L.length === 2) {
|
|
211
302
|
reporterOptions[L[0]] = L[1];
|
|
212
303
|
} else {
|
|
@@ -221,14 +312,14 @@ mocha.reporter(program.reporter, reporterOptions);
|
|
|
221
312
|
|
|
222
313
|
// load reporter
|
|
223
314
|
|
|
224
|
-
|
|
315
|
+
let Reporter = null;
|
|
225
316
|
try {
|
|
226
|
-
Reporter = require(
|
|
317
|
+
Reporter = require(`../lib/reporters/${program.reporter}`);
|
|
227
318
|
} catch (err) {
|
|
228
319
|
try {
|
|
229
320
|
Reporter = require(program.reporter);
|
|
230
321
|
} catch (err2) {
|
|
231
|
-
throw new Error(
|
|
322
|
+
throw new Error(`reporter "${program.reporter}" does not exist`);
|
|
232
323
|
}
|
|
233
324
|
}
|
|
234
325
|
|
|
@@ -250,6 +341,12 @@ if (program.inlineDiffs) {
|
|
|
250
341
|
mocha.useInlineDiffs(true);
|
|
251
342
|
}
|
|
252
343
|
|
|
344
|
+
// --no-diff
|
|
345
|
+
|
|
346
|
+
if (process.argv.indexOf('--no-diff') !== -1) {
|
|
347
|
+
mocha.hideDiff(true);
|
|
348
|
+
}
|
|
349
|
+
|
|
253
350
|
// --slow <ms>
|
|
254
351
|
|
|
255
352
|
if (program.slow) {
|
|
@@ -346,11 +443,15 @@ if (program.forbidPending) mocha.forbidPending();
|
|
|
346
443
|
|
|
347
444
|
// custom compiler support
|
|
348
445
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
446
|
+
if (program.compilers.length > 0) {
|
|
447
|
+
require('util').deprecate(() => {},
|
|
448
|
+
'"--compilers" will be removed in a future version of Mocha; see https://git.io/vdcSr for more info')();
|
|
449
|
+
}
|
|
450
|
+
const extensions = ['js'];
|
|
451
|
+
program.compilers.forEach(c => {
|
|
452
|
+
const idx = c.indexOf(':');
|
|
453
|
+
const ext = c.slice(0, idx);
|
|
454
|
+
let mod = c.slice(idx + 1);
|
|
354
455
|
|
|
355
456
|
if (mod[0] === '.') {
|
|
356
457
|
mod = join(process.cwd(), mod);
|
|
@@ -362,7 +463,7 @@ program.compilers.forEach(function (c) {
|
|
|
362
463
|
|
|
363
464
|
// requires
|
|
364
465
|
|
|
365
|
-
requires.forEach(
|
|
466
|
+
requires.forEach(mod => {
|
|
366
467
|
require(mod);
|
|
367
468
|
});
|
|
368
469
|
|
|
@@ -372,7 +473,7 @@ mocha.ui(program.ui);
|
|
|
372
473
|
|
|
373
474
|
// args
|
|
374
475
|
|
|
375
|
-
|
|
476
|
+
const args = program.args;
|
|
376
477
|
|
|
377
478
|
// default files to test/*.{js,coffee}
|
|
378
479
|
|
|
@@ -380,13 +481,13 @@ if (!args.length) {
|
|
|
380
481
|
args.push('test');
|
|
381
482
|
}
|
|
382
483
|
|
|
383
|
-
args.forEach(
|
|
384
|
-
|
|
484
|
+
args.forEach(arg => {
|
|
485
|
+
let newFiles;
|
|
385
486
|
try {
|
|
386
487
|
newFiles = utils.lookupFiles(arg, extensions, program.recursive);
|
|
387
488
|
} catch (err) {
|
|
388
489
|
if (err.message.indexOf('cannot resolve path') === 0) {
|
|
389
|
-
console.error(
|
|
490
|
+
console.error(`Warning: Could not find any test files matching pattern: ${arg}`);
|
|
390
491
|
return;
|
|
391
492
|
}
|
|
392
493
|
|
|
@@ -402,39 +503,40 @@ if (!files.length) {
|
|
|
402
503
|
}
|
|
403
504
|
|
|
404
505
|
// resolve
|
|
405
|
-
|
|
406
|
-
files = files.map(
|
|
407
|
-
return resolve(path);
|
|
408
|
-
});
|
|
506
|
+
let fileArgs = program.file.map(path => resolve(path));
|
|
507
|
+
files = files.map(path => resolve(path));
|
|
409
508
|
|
|
410
509
|
if (program.sort) {
|
|
411
510
|
files.sort();
|
|
412
511
|
}
|
|
413
512
|
|
|
513
|
+
// add files given through --file to be ran first
|
|
514
|
+
files = fileArgs.concat(files);
|
|
515
|
+
|
|
414
516
|
// --watch
|
|
415
517
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
518
|
+
let runner;
|
|
519
|
+
let loadAndRun;
|
|
520
|
+
let purge;
|
|
521
|
+
let rerun;
|
|
420
522
|
|
|
421
523
|
if (program.watch) {
|
|
422
524
|
console.log();
|
|
423
525
|
hideCursor();
|
|
424
|
-
process.on('SIGINT',
|
|
526
|
+
process.on('SIGINT', () => {
|
|
425
527
|
showCursor();
|
|
426
528
|
console.log('\n');
|
|
427
529
|
process.exit(130);
|
|
428
530
|
});
|
|
429
531
|
|
|
430
|
-
|
|
431
|
-
|
|
532
|
+
const watchFiles = utils.files(cwd, [ 'js' ].concat(program.watchExtensions));
|
|
533
|
+
let runAgain = false;
|
|
432
534
|
|
|
433
|
-
loadAndRun =
|
|
535
|
+
loadAndRun = () => {
|
|
434
536
|
try {
|
|
435
537
|
mocha.files = files;
|
|
436
538
|
runAgain = false;
|
|
437
|
-
runner = mocha.run(
|
|
539
|
+
runner = mocha.run(() => {
|
|
438
540
|
runner = null;
|
|
439
541
|
if (runAgain) {
|
|
440
542
|
rerun();
|
|
@@ -445,15 +547,15 @@ if (program.watch) {
|
|
|
445
547
|
}
|
|
446
548
|
};
|
|
447
549
|
|
|
448
|
-
purge =
|
|
449
|
-
watchFiles.forEach(
|
|
550
|
+
purge = () => {
|
|
551
|
+
watchFiles.forEach(file => {
|
|
450
552
|
delete require.cache[file];
|
|
451
553
|
});
|
|
452
554
|
};
|
|
453
555
|
|
|
454
556
|
loadAndRun();
|
|
455
557
|
|
|
456
|
-
rerun =
|
|
558
|
+
rerun = () => {
|
|
457
559
|
purge();
|
|
458
560
|
stop();
|
|
459
561
|
if (!program.grep) {
|
|
@@ -465,7 +567,7 @@ if (program.watch) {
|
|
|
465
567
|
loadAndRun();
|
|
466
568
|
};
|
|
467
569
|
|
|
468
|
-
utils.watch(watchFiles,
|
|
570
|
+
utils.watch(watchFiles, () => {
|
|
469
571
|
runAgain = true;
|
|
470
572
|
if (runner) {
|
|
471
573
|
runner.abort();
|
|
@@ -480,41 +582,7 @@ if (program.watch) {
|
|
|
480
582
|
runner = mocha.run(program.exit ? exit : exitLater);
|
|
481
583
|
}
|
|
482
584
|
|
|
483
|
-
|
|
484
|
-
process.on('exit', function () {
|
|
485
|
-
process.exit(Math.min(code, 255));
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
function exit (code) {
|
|
490
|
-
var clampedCode = Math.min(code, 255);
|
|
491
|
-
|
|
492
|
-
// Eagerly set the process's exit code in case stream.write doesn't
|
|
493
|
-
// execute its callback before the process terminates.
|
|
494
|
-
process.exitCode = clampedCode;
|
|
495
|
-
|
|
496
|
-
// flush output for Node.js Windows pipe bug
|
|
497
|
-
// https://github.com/joyent/node/issues/6247 is just one bug example
|
|
498
|
-
// https://github.com/visionmedia/mocha/issues/333 has a good discussion
|
|
499
|
-
function done () {
|
|
500
|
-
if (!(draining--)) {
|
|
501
|
-
process.exit(clampedCode);
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
var draining = 0;
|
|
506
|
-
var streams = [process.stdout, process.stderr];
|
|
507
|
-
|
|
508
|
-
streams.forEach(function (stream) {
|
|
509
|
-
// submit empty write request and wait for completion
|
|
510
|
-
draining += 1;
|
|
511
|
-
stream.write('', done);
|
|
512
|
-
});
|
|
513
|
-
|
|
514
|
-
done();
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
process.on('SIGINT', function () {
|
|
585
|
+
process.on('SIGINT', () => {
|
|
518
586
|
runner.abort();
|
|
519
587
|
|
|
520
588
|
// This is a hack:
|
|
@@ -522,51 +590,3 @@ process.on('SIGINT', function () {
|
|
|
522
590
|
// The amount of failures will be emitted as error code later
|
|
523
591
|
runner.failures = 130;
|
|
524
592
|
});
|
|
525
|
-
|
|
526
|
-
/**
|
|
527
|
-
* Parse list.
|
|
528
|
-
*/
|
|
529
|
-
|
|
530
|
-
function list (str) {
|
|
531
|
-
return str.split(/ *, */);
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
/**
|
|
535
|
-
* Hide the cursor.
|
|
536
|
-
*/
|
|
537
|
-
|
|
538
|
-
function hideCursor () {
|
|
539
|
-
process.stdout.write('\u001b[?25l');
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
/**
|
|
543
|
-
* Show the cursor.
|
|
544
|
-
*/
|
|
545
|
-
|
|
546
|
-
function showCursor () {
|
|
547
|
-
process.stdout.write('\u001b[?25h');
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
/**
|
|
551
|
-
* Stop play()ing.
|
|
552
|
-
*/
|
|
553
|
-
|
|
554
|
-
function stop () {
|
|
555
|
-
process.stdout.write('\u001b[2K');
|
|
556
|
-
clearInterval(play.timer);
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
/**
|
|
560
|
-
* Play the given array of strings.
|
|
561
|
-
*/
|
|
562
|
-
|
|
563
|
-
function play (arr, interval) {
|
|
564
|
-
var len = arr.length;
|
|
565
|
-
interval = interval || 100;
|
|
566
|
-
var i = 0;
|
|
567
|
-
|
|
568
|
-
play.timer = setInterval(function () {
|
|
569
|
-
var str = arr[i++ % len];
|
|
570
|
-
process.stdout.write('\u001b[0G' + str);
|
|
571
|
-
}, interval);
|
|
572
|
-
}
|
package/bin/mocha
CHANGED
|
@@ -7,17 +7,17 @@
|
|
|
7
7
|
* when found, before invoking the "real" _mocha(1) executable.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const spawn = require('child_process').spawn;
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const getOptions = require('./options');
|
|
13
|
+
const args = [path.join(__dirname, '_mocha')];
|
|
14
14
|
|
|
15
15
|
// Load mocha.opts into process.argv
|
|
16
16
|
// Must be loaded here to handle node-specific options
|
|
17
17
|
getOptions();
|
|
18
18
|
|
|
19
|
-
process.argv.slice(2).forEach(
|
|
20
|
-
|
|
19
|
+
process.argv.slice(2).forEach(arg => {
|
|
20
|
+
const flag = arg.split('=')[0];
|
|
21
21
|
|
|
22
22
|
switch (flag) {
|
|
23
23
|
case '-d':
|
|
@@ -69,9 +69,11 @@ process.argv.slice(2).forEach(function (arg) {
|
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
const proc = spawn(process.execPath, args, {
|
|
73
|
+
stdio: 'inherit'
|
|
74
|
+
});
|
|
75
|
+
proc.on('exit', (code, signal) => {
|
|
76
|
+
process.on('exit', () => {
|
|
75
77
|
if (signal) {
|
|
76
78
|
process.kill(process.pid, signal);
|
|
77
79
|
} else {
|
|
@@ -81,7 +83,7 @@ proc.on('exit', function (code, signal) {
|
|
|
81
83
|
});
|
|
82
84
|
|
|
83
85
|
// terminate children.
|
|
84
|
-
process.on('SIGINT',
|
|
86
|
+
process.on('SIGINT', () => {
|
|
85
87
|
proc.kill('SIGINT'); // calls runner.abort()
|
|
86
88
|
proc.kill('SIGTERM'); // if that didn't work, we're probably in an infinite loop, so make it die.
|
|
87
89
|
});
|
package/bin/options.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Dependencies.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const fs = require('fs');
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Export `getOptions`.
|
|
@@ -17,18 +17,20 @@ module.exports = getOptions;
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
function getOptions () {
|
|
20
|
-
|
|
20
|
+
if (process.argv.length === 3 && (process.argv[2] === '-h' || process.argv[2] === '--help')) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const optsPath = process.argv.indexOf('--opts') === -1
|
|
21
25
|
? 'test/mocha.opts'
|
|
22
26
|
: process.argv[process.argv.indexOf('--opts') + 1];
|
|
23
27
|
|
|
24
28
|
try {
|
|
25
|
-
|
|
29
|
+
const opts = fs.readFileSync(optsPath, 'utf8')
|
|
26
30
|
.replace(/\\\s/g, '%20')
|
|
27
31
|
.split(/\s/)
|
|
28
32
|
.filter(Boolean)
|
|
29
|
-
.map(
|
|
30
|
-
return value.replace(/%20/g, ' ');
|
|
31
|
-
});
|
|
33
|
+
.map(value => value.replace(/%20/g, ' '));
|
|
32
34
|
|
|
33
35
|
process.argv = process.argv
|
|
34
36
|
.slice(0, 2)
|
package/browser-entry.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Shim process.stdout.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
process.stdout = require('browser-stdout')();
|
|
10
|
+
process.stdout = require('browser-stdout')({level: false});
|
|
11
11
|
|
|
12
12
|
var Mocha = require('./lib/mocha');
|
|
13
13
|
|
|
@@ -45,7 +45,7 @@ process.removeListener = function (e, fn) {
|
|
|
45
45
|
} else {
|
|
46
46
|
global.onerror = function () {};
|
|
47
47
|
}
|
|
48
|
-
var i =
|
|
48
|
+
var i = uncaughtExceptionHandlers.indexOf(fn);
|
|
49
49
|
if (i !== -1) {
|
|
50
50
|
uncaughtExceptionHandlers.splice(i, 1);
|
|
51
51
|
}
|
|
@@ -103,7 +103,7 @@ Mocha.Runner.immediately = function (callback) {
|
|
|
103
103
|
* only receive the 'message' attribute of the Error.
|
|
104
104
|
*/
|
|
105
105
|
mocha.throwError = function (err) {
|
|
106
|
-
|
|
106
|
+
uncaughtExceptionHandlers.forEach(function (fn) {
|
|
107
107
|
fn(err);
|
|
108
108
|
});
|
|
109
109
|
throw err;
|
|
File without changes
|