mocha 4.0.0 → 5.0.1
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 +1022 -971
- package/CHANGELOG.md.orig +1736 -0
- package/LICENSE +1 -1
- package/README.md +81 -85
- package/README.md.orig +132 -0
- package/bin/.eslintrc.yml +3 -0
- package/bin/_mocha +169 -153
- package/bin/mocha +12 -10
- package/bin/options.js +8 -6
- package/lib/browser/{.eslintrc.yaml → .eslintrc.yml} +0 -0
- package/lib/context.js +9 -15
- package/lib/interfaces/bdd.js +1 -1
- package/lib/mocha.js +23 -0
- package/lib/ms.js +4 -44
- package/lib/reporters/base.js +24 -40
- package/lib/reporters/base.js.orig +498 -0
- package/lib/reporters/progress.js +7 -5
- package/lib/runnable.js +14 -8
- package/lib/runner.js +4 -5
- package/lib/suite.js +5 -5
- package/lib/utils.js +1 -1
- package/mocha.js +7280 -7389
- package/package.json +16 -15
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,6 +179,7 @@ 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')
|
|
@@ -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('option: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('option: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('option:reporters', function () {
|
|
|
165
256
|
|
|
166
257
|
// --interfaces
|
|
167
258
|
|
|
168
|
-
program.on('option: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('option:interfaces', function () {
|
|
|
178
269
|
|
|
179
270
|
module.paths.push(cwd, join(cwd, 'node_modules'));
|
|
180
271
|
|
|
181
|
-
program.on('option: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) {
|
|
@@ -347,14 +444,14 @@ if (program.forbidPending) mocha.forbidPending();
|
|
|
347
444
|
// custom compiler support
|
|
348
445
|
|
|
349
446
|
if (program.compilers.length > 0) {
|
|
350
|
-
require('util').deprecate(
|
|
447
|
+
require('util').deprecate(() => {},
|
|
351
448
|
'"--compilers" will be removed in a future version of Mocha; see https://git.io/vdcSr for more info')();
|
|
352
449
|
}
|
|
353
|
-
|
|
354
|
-
program.compilers.forEach(
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
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);
|
|
358
455
|
|
|
359
456
|
if (mod[0] === '.') {
|
|
360
457
|
mod = join(process.cwd(), mod);
|
|
@@ -366,7 +463,7 @@ program.compilers.forEach(function (c) {
|
|
|
366
463
|
|
|
367
464
|
// requires
|
|
368
465
|
|
|
369
|
-
requires.forEach(
|
|
466
|
+
requires.forEach(mod => {
|
|
370
467
|
require(mod);
|
|
371
468
|
});
|
|
372
469
|
|
|
@@ -376,7 +473,7 @@ mocha.ui(program.ui);
|
|
|
376
473
|
|
|
377
474
|
// args
|
|
378
475
|
|
|
379
|
-
|
|
476
|
+
const args = program.args;
|
|
380
477
|
|
|
381
478
|
// default files to test/*.{js,coffee}
|
|
382
479
|
|
|
@@ -384,13 +481,13 @@ if (!args.length) {
|
|
|
384
481
|
args.push('test');
|
|
385
482
|
}
|
|
386
483
|
|
|
387
|
-
args.forEach(
|
|
388
|
-
|
|
484
|
+
args.forEach(arg => {
|
|
485
|
+
let newFiles;
|
|
389
486
|
try {
|
|
390
487
|
newFiles = utils.lookupFiles(arg, extensions, program.recursive);
|
|
391
488
|
} catch (err) {
|
|
392
489
|
if (err.message.indexOf('cannot resolve path') === 0) {
|
|
393
|
-
console.error(
|
|
490
|
+
console.error(`Warning: Could not find any test files matching pattern: ${arg}`);
|
|
394
491
|
return;
|
|
395
492
|
}
|
|
396
493
|
|
|
@@ -406,39 +503,40 @@ if (!files.length) {
|
|
|
406
503
|
}
|
|
407
504
|
|
|
408
505
|
// resolve
|
|
409
|
-
|
|
410
|
-
files = files.map(
|
|
411
|
-
return resolve(path);
|
|
412
|
-
});
|
|
506
|
+
let fileArgs = program.file.map(path => resolve(path));
|
|
507
|
+
files = files.map(path => resolve(path));
|
|
413
508
|
|
|
414
509
|
if (program.sort) {
|
|
415
510
|
files.sort();
|
|
416
511
|
}
|
|
417
512
|
|
|
513
|
+
// add files given through --file to be ran first
|
|
514
|
+
files = fileArgs.concat(files);
|
|
515
|
+
|
|
418
516
|
// --watch
|
|
419
517
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
518
|
+
let runner;
|
|
519
|
+
let loadAndRun;
|
|
520
|
+
let purge;
|
|
521
|
+
let rerun;
|
|
424
522
|
|
|
425
523
|
if (program.watch) {
|
|
426
524
|
console.log();
|
|
427
525
|
hideCursor();
|
|
428
|
-
process.on('SIGINT',
|
|
526
|
+
process.on('SIGINT', () => {
|
|
429
527
|
showCursor();
|
|
430
528
|
console.log('\n');
|
|
431
529
|
process.exit(130);
|
|
432
530
|
});
|
|
433
531
|
|
|
434
|
-
|
|
435
|
-
|
|
532
|
+
const watchFiles = utils.files(cwd, [ 'js' ].concat(program.watchExtensions));
|
|
533
|
+
let runAgain = false;
|
|
436
534
|
|
|
437
|
-
loadAndRun =
|
|
535
|
+
loadAndRun = () => {
|
|
438
536
|
try {
|
|
439
537
|
mocha.files = files;
|
|
440
538
|
runAgain = false;
|
|
441
|
-
runner = mocha.run(
|
|
539
|
+
runner = mocha.run(() => {
|
|
442
540
|
runner = null;
|
|
443
541
|
if (runAgain) {
|
|
444
542
|
rerun();
|
|
@@ -449,15 +547,15 @@ if (program.watch) {
|
|
|
449
547
|
}
|
|
450
548
|
};
|
|
451
549
|
|
|
452
|
-
purge =
|
|
453
|
-
watchFiles.forEach(
|
|
550
|
+
purge = () => {
|
|
551
|
+
watchFiles.forEach(file => {
|
|
454
552
|
delete require.cache[file];
|
|
455
553
|
});
|
|
456
554
|
};
|
|
457
555
|
|
|
458
556
|
loadAndRun();
|
|
459
557
|
|
|
460
|
-
rerun =
|
|
558
|
+
rerun = () => {
|
|
461
559
|
purge();
|
|
462
560
|
stop();
|
|
463
561
|
if (!program.grep) {
|
|
@@ -469,7 +567,7 @@ if (program.watch) {
|
|
|
469
567
|
loadAndRun();
|
|
470
568
|
};
|
|
471
569
|
|
|
472
|
-
utils.watch(watchFiles,
|
|
570
|
+
utils.watch(watchFiles, () => {
|
|
473
571
|
runAgain = true;
|
|
474
572
|
if (runner) {
|
|
475
573
|
runner.abort();
|
|
@@ -484,41 +582,7 @@ if (program.watch) {
|
|
|
484
582
|
runner = mocha.run(program.exit ? exit : exitLater);
|
|
485
583
|
}
|
|
486
584
|
|
|
487
|
-
|
|
488
|
-
process.on('exit', function () {
|
|
489
|
-
process.exit(Math.min(code, 255));
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
function exit (code) {
|
|
494
|
-
var clampedCode = Math.min(code, 255);
|
|
495
|
-
|
|
496
|
-
// Eagerly set the process's exit code in case stream.write doesn't
|
|
497
|
-
// execute its callback before the process terminates.
|
|
498
|
-
process.exitCode = clampedCode;
|
|
499
|
-
|
|
500
|
-
// flush output for Node.js Windows pipe bug
|
|
501
|
-
// https://github.com/joyent/node/issues/6247 is just one bug example
|
|
502
|
-
// https://github.com/visionmedia/mocha/issues/333 has a good discussion
|
|
503
|
-
function done () {
|
|
504
|
-
if (!(draining--)) {
|
|
505
|
-
process.exit(clampedCode);
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
var draining = 0;
|
|
510
|
-
var streams = [process.stdout, process.stderr];
|
|
511
|
-
|
|
512
|
-
streams.forEach(function (stream) {
|
|
513
|
-
// submit empty write request and wait for completion
|
|
514
|
-
draining += 1;
|
|
515
|
-
stream.write('', done);
|
|
516
|
-
});
|
|
517
|
-
|
|
518
|
-
done();
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
process.on('SIGINT', function () {
|
|
585
|
+
process.on('SIGINT', () => {
|
|
522
586
|
runner.abort();
|
|
523
587
|
|
|
524
588
|
// This is a hack:
|
|
@@ -526,51 +590,3 @@ process.on('SIGINT', function () {
|
|
|
526
590
|
// The amount of failures will be emitted as error code later
|
|
527
591
|
runner.failures = 130;
|
|
528
592
|
});
|
|
529
|
-
|
|
530
|
-
/**
|
|
531
|
-
* Parse list.
|
|
532
|
-
*/
|
|
533
|
-
|
|
534
|
-
function list (str) {
|
|
535
|
-
return str.split(/ *, */);
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
/**
|
|
539
|
-
* Hide the cursor.
|
|
540
|
-
*/
|
|
541
|
-
|
|
542
|
-
function hideCursor () {
|
|
543
|
-
process.stdout.write('\u001b[?25l');
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
/**
|
|
547
|
-
* Show the cursor.
|
|
548
|
-
*/
|
|
549
|
-
|
|
550
|
-
function showCursor () {
|
|
551
|
-
process.stdout.write('\u001b[?25h');
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
/**
|
|
555
|
-
* Stop play()ing.
|
|
556
|
-
*/
|
|
557
|
-
|
|
558
|
-
function stop () {
|
|
559
|
-
process.stdout.write('\u001b[2K');
|
|
560
|
-
clearInterval(play.timer);
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
/**
|
|
564
|
-
* Play the given array of strings.
|
|
565
|
-
*/
|
|
566
|
-
|
|
567
|
-
function play (arr, interval) {
|
|
568
|
-
var len = arr.length;
|
|
569
|
-
interval = interval || 100;
|
|
570
|
-
var i = 0;
|
|
571
|
-
|
|
572
|
-
play.timer = setInterval(function () {
|
|
573
|
-
var str = arr[i++ % len];
|
|
574
|
-
process.stdout.write('\u001b[0G' + str);
|
|
575
|
-
}, interval);
|
|
576
|
-
}
|
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)
|
|
File without changes
|
package/lib/context.js
CHANGED
|
@@ -29,7 +29,7 @@ Context.prototype.runnable = function (runnable) {
|
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
* Set test timeout `ms`.
|
|
32
|
+
* Set or get test timeout `ms`.
|
|
33
33
|
*
|
|
34
34
|
* @api private
|
|
35
35
|
* @param {number} ms
|
|
@@ -51,18 +51,24 @@ Context.prototype.timeout = function (ms) {
|
|
|
51
51
|
* @return {Context} self
|
|
52
52
|
*/
|
|
53
53
|
Context.prototype.enableTimeouts = function (enabled) {
|
|
54
|
+
if (!arguments.length) {
|
|
55
|
+
return this.runnable().enableTimeouts();
|
|
56
|
+
}
|
|
54
57
|
this.runnable().enableTimeouts(enabled);
|
|
55
58
|
return this;
|
|
56
59
|
};
|
|
57
60
|
|
|
58
61
|
/**
|
|
59
|
-
* Set test slowness threshold `ms`.
|
|
62
|
+
* Set or get test slowness threshold `ms`.
|
|
60
63
|
*
|
|
61
64
|
* @api private
|
|
62
65
|
* @param {number} ms
|
|
63
66
|
* @return {Context} self
|
|
64
67
|
*/
|
|
65
68
|
Context.prototype.slow = function (ms) {
|
|
69
|
+
if (!arguments.length) {
|
|
70
|
+
return this.runnable().slow();
|
|
71
|
+
}
|
|
66
72
|
this.runnable().slow(ms);
|
|
67
73
|
return this;
|
|
68
74
|
};
|
|
@@ -78,7 +84,7 @@ Context.prototype.skip = function () {
|
|
|
78
84
|
};
|
|
79
85
|
|
|
80
86
|
/**
|
|
81
|
-
*
|
|
87
|
+
* Set or get a number of allowed retries on failed tests
|
|
82
88
|
*
|
|
83
89
|
* @api private
|
|
84
90
|
* @param {number} n
|
|
@@ -91,15 +97,3 @@ Context.prototype.retries = function (n) {
|
|
|
91
97
|
this.runnable().retries(n);
|
|
92
98
|
return this;
|
|
93
99
|
};
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Inspect the context void of `._runnable`.
|
|
97
|
-
*
|
|
98
|
-
* @api private
|
|
99
|
-
* @return {string}
|
|
100
|
-
*/
|
|
101
|
-
Context.prototype.inspect = function () {
|
|
102
|
-
return JSON.stringify(this, function (key, val) {
|
|
103
|
-
return key === 'runnable' || key === 'test' ? undefined : val;
|
|
104
|
-
}, 2);
|
|
105
|
-
};
|