mocha 4.0.1 → 4.1.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 CHANGED
@@ -1,3 +1,55 @@
1
+ # 4.1.0 / 2017-12-28
2
+
3
+ This is mainly a "housekeeping" release.
4
+
5
+ Welcome [@Bamieh] and [@xxczaki] to the team!
6
+
7
+ ## :bug:: Fixes
8
+
9
+ - [#2661]: `progress` reporter now accepts reporter options ([@canoztokmak])
10
+ - [#3142]: `xit` in `bdd` interface now properly returns its `Test` object ([@Bamieh])
11
+ - [#3075]: Diffs now computed eagerly to avoid misinformation when reported ([@abrady0])
12
+ - [#2745]: `--help` will now help you even if you have a `mocha.opts` ([@Zarel])
13
+
14
+ ## :tada: Enhancements
15
+
16
+ - [#2514]: The `--no-diff` flag will completely disable diff output ([@CapacitorSet])
17
+ - [#3058]: All "setters" in Mocha's API are now also "getters" if called without arguments ([@makepanic])
18
+
19
+ ## :book: Documentation
20
+
21
+ - [#3170]: Optimization and site speed improvements ([@Munter])
22
+ - [#2987]: Moved the old [site repo](https://github.com/mochajs/mochajs.github.io) into the main repo under `docs/` ([@boneskull])
23
+ - [#2896]: Add [maintainer guide](https://github.com/mochajs/mocha/blob/master/MAINTAINERS.md) ([@boneskull])
24
+ - Various fixes and updates ([@xxczaki], [@maty21], [@leedm777])
25
+
26
+ ## :nut_and_bolt: Other
27
+
28
+ - Test improvements and fixes ([@eugenet8k], [@ngeor], [@38elements], [@Gerhut], [@ScottFreeCode], [@boneskull])
29
+ - Refactoring and cruft excision ([@38elements], [@Bamieh], [@finnigantime], [@boneskull])
30
+
31
+ [#2661]: https://github.com/mochajs/mocha/issues/2661
32
+ [#3142]: https://github.com/mochajs/mocha/issues/3142
33
+ [#3075]: https://github.com/mochajs/mocha/pull/3075
34
+ [#2745]: https://github.com/mochajs/mocha/issues/2745
35
+ [#2514]: https://github.com/mochajs/mocha/issues/2514
36
+ [#3058]: https://github.com/mochajs/mocha/issues/3058
37
+ [#3170]: https://github.com/mochajs/mocha/pull/3170
38
+ [#2987]: https://github.com/mochajs/mocha/issues/2987
39
+ [#2896]: https://github.com/mochajs/mocha/issues/2896
40
+ [@canoztokmak]: https://github.com/canoztokmak
41
+ [@Bamieh]: https://github.com/Bamieh
42
+ [@abrady0]: https://github.com/abrady0
43
+ [@Zarel]: https://github.com/Zarel
44
+ [@CapacitorSet]: https://github.com/CapacitorSet
45
+ [@xxczaki]: https://github.com/xxczaki
46
+ [@maty21]: https://github.com/maty21
47
+ [@leedm777]: https://github.com/leedm777
48
+ [@eugenet8k]: https://github.com/eugenet8k
49
+ [@38elements]: https://github.com/38elements
50
+ [@Gerhut]: https://github.com/Gerhut
51
+ [@finnigantime]: https://github.com/finnigantime
52
+
1
53
  # 4.0.1 / 2017-10-05
2
54
 
3
55
  ## :bug: Fixes
package/README.md CHANGED
@@ -9,23 +9,23 @@
9
9
  *Thank you* :kissing_heart: to all of you interested in helping. These are Mocha's immediate needs:
10
10
 
11
11
  1. Increase test coverage on Node.js and browser
12
- - Increase integration coverage for all reporters
13
- - `html` reporter must be tested in browser
14
- - ~~Basic console reporters (*not* `nyan`, `landing`, etc.) must be tested in **both** browser and Node.js contexts; PhantomJS can consume all console reporters~~
15
- - ~~Filesystem-based reporters must be tested in Node.js context~~
16
- - **UPDATE - May 24 2017**: Thanks to [community contributions](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#mag-coverage), the coverage on most reporters has increased dramatically! The `html` reporter is still in [dire need of coverage](https://coveralls.io/builds/11674428/source?filename=lib%2Freporters%2Fhtml.js).
17
- - Increase coverage against all interfaces (`exports` in particular). Ideally this becomes a "matrix" where we repeat sets of integration tests across all interfaces.
18
- - Refactor non-Node.js-specific tests to allow them to run in a browser context. Node.js-specific tests include those which *require* the CLI or filesystem. Most everything else is fair game.
12
+ - Increase integration coverage for all reporters
13
+ - `html` reporter must be tested in browser
14
+ - ~~Basic console reporters (*not* `nyan`, `landing`, etc.) must be tested in **both** browser and Node.js contexts; PhantomJS can consume all console reporters~~
15
+ - ~~Filesystem-based reporters must be tested in Node.js context~~
16
+ - **UPDATE - May 24 2017**: Thanks to [community contributions](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#mag-coverage), the coverage on most reporters has increased dramatically! The `html` reporter is still in [dire need of coverage](https://coveralls.io/builds/11674428/source?filename=lib%2Freporters%2Fhtml.js).
17
+ - Increase coverage against all interfaces (`exports` in particular). Ideally this becomes a "matrix" where we repeat sets of integration tests across all interfaces.
18
+ - Refactor non-Node.js-specific tests to allow them to run in a browser context. Node.js-specific tests include those which *require* the CLI or filesystem. Most everything else is fair game.
19
19
  2. Review current open pull requests
20
- - We need individuals familiar with Mocha's codebase. Got questions? Ask them in [our chat room](https://gitter.im/mochajs/mocha).
21
- - Pull requests **must** have supporting tests. The only exceptions are pure cosmetic or non-functional changes.
22
- - Pull request contributors must sign [the CLA](https://cla.js.foundation/mochajs/mocha).
20
+ - We need individuals familiar with Mocha's codebase. Got questions? Ask them in [our chat room](https://gitter.im/mochajs/mocha).
21
+ - Pull requests **must** have supporting tests. The only exceptions are pure cosmetic or non-functional changes.
22
+ - Pull request contributors must sign [the CLA](https://cla.js.foundation/mochajs/mocha).
23
23
  3. Close old, inactive issues and pull requests
24
- - ~~A bot should do this. We need a bot. Got a bot?~~ We now use GitHub's own [probot-stale](https://www.npmjs.com/package/probot-stale).
24
+ - ~~A bot should do this. We need a bot. Got a bot?~~ We now use GitHub's own [probot-stale](https://www.npmjs.com/package/probot-stale).
25
25
  4. Triage issues
26
- - If we run into "critical" bugs, they need fixing.
27
- - "Critical" means Mocha is broken w/o workarounds for a *large percentage* of users
28
- - Otherwise: respond to issues, close new dupe issues, confirm bugs, ask for more info, etc.
26
+ - If we run into "critical" bugs, they need fixing.
27
+ - "Critical" means Mocha is broken w/o workarounds for a *large percentage* of users
28
+ - Otherwise: respond to issues, close new dupe issues, confirm bugs, ask for more info, etc.
29
29
 
30
30
  Once we gain ground on the above items, we can work together formalize our contribution guidelines and governance. For further info & ideas, please see our [projects](https://github.com/mochajs/mocha/projects/).
31
31
 
@@ -0,0 +1,3 @@
1
+ env:
2
+ es6: true
3
+ browser: false
package/bin/_mocha CHANGED
@@ -7,52 +7,136 @@
7
7
  * Module dependencies.
8
8
  */
9
9
 
10
- var program = require('commander');
11
- var path = require('path');
12
- var fs = require('fs');
13
- var resolve = path.resolve;
14
- var exists = fs.existsSync || path.existsSync;
15
- var Mocha = require('../');
16
- var utils = Mocha.utils;
17
- var interfaceNames = Object.keys(Mocha.interfaces);
18
- var join = path.join;
19
- var cwd = process.cwd();
20
- var getOptions = require('./options');
21
- var mocha = new Mocha();
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
- var Date = global.Date;
28
- var setTimeout = global.setTimeout;
29
- var setInterval = global.setInterval;
30
- var clearTimeout = global.clearTimeout;
31
- var clearInterval = global.clearInterval;
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
+ * Hide the cursor.
83
+ */
84
+ const hideCursor = () => {
85
+ process.stdout.write('\u001b[?25l');
86
+ };
87
+
88
+ /**
89
+ * Show the cursor.
90
+ */
91
+ const showCursor = () => {
92
+ process.stdout.write('\u001b[?25h');
93
+ };
94
+
95
+ /**
96
+ * Stop play()ing.
97
+ */
98
+ const stop = () => {
99
+ process.stdout.write('\u001b[2K');
100
+ clearInterval(play.timer);
101
+ };
102
+
103
+ /**
104
+ * Play the given array of strings.
105
+ */
106
+ const play = (arr, interval) => {
107
+ const len = arr.length;
108
+ interval = interval || 100;
109
+ let i = 0;
110
+
111
+ play.timer = setInterval(() => {
112
+ const str = arr[i++ % len];
113
+ process.stdout.write(`\u001b[0G${str}`);
114
+ }, interval);
115
+ };
32
116
 
33
117
  /**
34
118
  * Files.
35
119
  */
36
120
 
37
- var files = [];
121
+ let files = [];
38
122
 
39
123
  /**
40
124
  * Globals.
41
125
  */
42
126
 
43
- var globals = [];
127
+ let globals = [];
44
128
 
45
129
  /**
46
130
  * Requires.
47
131
  */
48
132
 
49
- var requires = [];
133
+ const requires = [];
50
134
 
51
135
  /**
52
136
  * Images.
53
137
  */
54
138
 
55
- var images = {
139
+ const images = {
56
140
  fail: path.join(__dirname, '..', 'images', 'error.png'),
57
141
  pass: path.join(__dirname, '..', 'images', 'ok.png')
58
142
  };
@@ -78,7 +162,7 @@ program
78
162
  .option('-r, --require <name>', 'require the given module')
79
163
  .option('-s, --slow <ms>', '"slow" test threshold in milliseconds [75]')
80
164
  .option('-t, --timeout <ms>', 'set test-case timeout in milliseconds [2000]')
81
- .option('-u, --ui <name>', 'specify user-interface (' + interfaceNames.join('|') + ')', 'bdd')
165
+ .option('-u, --ui <name>', `specify user-interface (${interfaceNames.join('|')})`, 'bdd')
82
166
  .option('-w, --watch', 'watch files for changes')
83
167
  .option('--check-leaks', 'check for global variable leaks')
84
168
  .option('--full-trace', 'display the full stack trace')
@@ -90,6 +174,7 @@ program
90
174
  .option('--preserve-symlinks', 'Instructs the module loader to preserve symbolic links when resolving and caching modules')
91
175
  .option('--icu-data-dir', 'include ICU data')
92
176
  .option('--inline-diffs', 'display actual/expected differences inline within each string')
177
+ .option('--no-diff', 'do not show a diff on failure')
93
178
  .option('--inspect', 'activate devtools in chrome')
94
179
  .option('--inspect-brk', 'activate devtools in chrome and break on the first line')
95
180
  .option('--interfaces', 'display available interfaces')
@@ -123,12 +208,12 @@ program._name = 'mocha';
123
208
  program
124
209
  .command('init <path>')
125
210
  .description('initialize a client-side mocha setup at <path>')
126
- .action(function (path) {
127
- var mkdir = require('mkdirp');
211
+ .action(path => {
212
+ const mkdir = require('mkdirp');
128
213
  mkdir.sync(path);
129
- var css = fs.readFileSync(join(__dirname, '..', 'mocha.css'));
130
- var js = fs.readFileSync(join(__dirname, '..', 'mocha.js'));
131
- var tmpl = fs.readFileSync(join(__dirname, '..', 'lib/template.html'));
214
+ const css = fs.readFileSync(join(__dirname, '..', 'mocha.css'));
215
+ const js = fs.readFileSync(join(__dirname, '..', 'mocha.js'));
216
+ const tmpl = fs.readFileSync(join(__dirname, '..', 'lib/template.html'));
132
217
  fs.writeFileSync(join(path, 'mocha.css'), css);
133
218
  fs.writeFileSync(join(path, 'mocha.js'), js);
134
219
  fs.writeFileSync(join(path, 'tests.js'), '');
@@ -138,13 +223,13 @@ program
138
223
 
139
224
  // --globals
140
225
 
141
- program.on('option:globals', function (val) {
226
+ program.on('option:globals', val => {
142
227
  globals = globals.concat(list(val));
143
228
  });
144
229
 
145
230
  // --reporters
146
231
 
147
- program.on('option:reporters', function () {
232
+ program.on('option:reporters', () => {
148
233
  console.log();
149
234
  console.log(' dot - dot matrix');
150
235
  console.log(' doc - html documentation');
@@ -165,10 +250,10 @@ program.on('option:reporters', function () {
165
250
 
166
251
  // --interfaces
167
252
 
168
- program.on('option:interfaces', function () {
253
+ program.on('option:interfaces', () => {
169
254
  console.log('');
170
- interfaceNames.forEach(function (interfaceName) {
171
- console.log(' ' + interfaceName);
255
+ interfaceNames.forEach(interfaceName => {
256
+ console.log(` ${interfaceName}`);
172
257
  });
173
258
  console.log('');
174
259
  process.exit();
@@ -178,8 +263,8 @@ program.on('option:interfaces', function () {
178
263
 
179
264
  module.paths.push(cwd, join(cwd, 'node_modules'));
180
265
 
181
- program.on('option:require', function (mod) {
182
- var abs = exists(mod) || exists(mod + '.js');
266
+ program.on('option:require', mod => {
267
+ const abs = exists(mod) || exists(`${mod}.js`);
183
268
  if (abs) {
184
269
  mod = resolve(mod);
185
270
  }
@@ -201,12 +286,12 @@ Error.stackTraceLimit = Infinity; // TODO: config
201
286
 
202
287
  // reporter options
203
288
 
204
- var reporterOptions = {};
289
+ const reporterOptions = {};
205
290
  if (program.reporterOptions !== undefined) {
206
- program.reporterOptions.split(',').forEach(function (opt) {
207
- var L = opt.split('=');
291
+ program.reporterOptions.split(',').forEach(opt => {
292
+ const L = opt.split('=');
208
293
  if (L.length > 2 || L.length === 0) {
209
- throw new Error("invalid reporter option '" + opt + "'");
294
+ throw new Error(`invalid reporter option '${opt}'`);
210
295
  } else if (L.length === 2) {
211
296
  reporterOptions[L[0]] = L[1];
212
297
  } else {
@@ -221,14 +306,14 @@ mocha.reporter(program.reporter, reporterOptions);
221
306
 
222
307
  // load reporter
223
308
 
224
- var Reporter = null;
309
+ let Reporter = null;
225
310
  try {
226
- Reporter = require('../lib/reporters/' + program.reporter);
311
+ Reporter = require(`../lib/reporters/${program.reporter}`);
227
312
  } catch (err) {
228
313
  try {
229
314
  Reporter = require(program.reporter);
230
315
  } catch (err2) {
231
- throw new Error('reporter "' + program.reporter + '" does not exist');
316
+ throw new Error(`reporter "${program.reporter}" does not exist`);
232
317
  }
233
318
  }
234
319
 
@@ -250,6 +335,12 @@ if (program.inlineDiffs) {
250
335
  mocha.useInlineDiffs(true);
251
336
  }
252
337
 
338
+ // --no-diff
339
+
340
+ if (process.argv.indexOf('--no-diff') !== -1) {
341
+ mocha.hideDiff(true);
342
+ }
343
+
253
344
  // --slow <ms>
254
345
 
255
346
  if (program.slow) {
@@ -347,14 +438,14 @@ if (program.forbidPending) mocha.forbidPending();
347
438
  // custom compiler support
348
439
 
349
440
  if (program.compilers.length > 0) {
350
- require('util').deprecate(function () {},
441
+ require('util').deprecate(() => {},
351
442
  '"--compilers" will be removed in a future version of Mocha; see https://git.io/vdcSr for more info')();
352
443
  }
353
- var extensions = ['js'];
354
- program.compilers.forEach(function (c) {
355
- var idx = c.indexOf(':');
356
- var ext = c.slice(0, idx);
357
- var mod = c.slice(idx + 1);
444
+ const extensions = ['js'];
445
+ program.compilers.forEach(c => {
446
+ const idx = c.indexOf(':');
447
+ const ext = c.slice(0, idx);
448
+ let mod = c.slice(idx + 1);
358
449
 
359
450
  if (mod[0] === '.') {
360
451
  mod = join(process.cwd(), mod);
@@ -366,7 +457,7 @@ program.compilers.forEach(function (c) {
366
457
 
367
458
  // requires
368
459
 
369
- requires.forEach(function (mod) {
460
+ requires.forEach(mod => {
370
461
  require(mod);
371
462
  });
372
463
 
@@ -376,7 +467,7 @@ mocha.ui(program.ui);
376
467
 
377
468
  // args
378
469
 
379
- var args = program.args;
470
+ const args = program.args;
380
471
 
381
472
  // default files to test/*.{js,coffee}
382
473
 
@@ -384,13 +475,13 @@ if (!args.length) {
384
475
  args.push('test');
385
476
  }
386
477
 
387
- args.forEach(function (arg) {
388
- var newFiles;
478
+ args.forEach(arg => {
479
+ let newFiles;
389
480
  try {
390
481
  newFiles = utils.lookupFiles(arg, extensions, program.recursive);
391
482
  } catch (err) {
392
483
  if (err.message.indexOf('cannot resolve path') === 0) {
393
- console.error('Warning: Could not find any test files matching pattern: ' + arg);
484
+ console.error(`Warning: Could not find any test files matching pattern: ${arg}`);
394
485
  return;
395
486
  }
396
487
 
@@ -407,9 +498,7 @@ if (!files.length) {
407
498
 
408
499
  // resolve
409
500
 
410
- files = files.map(function (path) {
411
- return resolve(path);
412
- });
501
+ files = files.map(path => resolve(path));
413
502
 
414
503
  if (program.sort) {
415
504
  files.sort();
@@ -417,28 +506,28 @@ if (program.sort) {
417
506
 
418
507
  // --watch
419
508
 
420
- var runner;
421
- var loadAndRun;
422
- var purge;
423
- var rerun;
509
+ let runner;
510
+ let loadAndRun;
511
+ let purge;
512
+ let rerun;
424
513
 
425
514
  if (program.watch) {
426
515
  console.log();
427
516
  hideCursor();
428
- process.on('SIGINT', function () {
517
+ process.on('SIGINT', () => {
429
518
  showCursor();
430
519
  console.log('\n');
431
520
  process.exit(130);
432
521
  });
433
522
 
434
- var watchFiles = utils.files(cwd, [ 'js' ].concat(program.watchExtensions));
435
- var runAgain = false;
523
+ const watchFiles = utils.files(cwd, [ 'js' ].concat(program.watchExtensions));
524
+ let runAgain = false;
436
525
 
437
- loadAndRun = function loadAndRun () {
526
+ loadAndRun = () => {
438
527
  try {
439
528
  mocha.files = files;
440
529
  runAgain = false;
441
- runner = mocha.run(function () {
530
+ runner = mocha.run(() => {
442
531
  runner = null;
443
532
  if (runAgain) {
444
533
  rerun();
@@ -449,15 +538,15 @@ if (program.watch) {
449
538
  }
450
539
  };
451
540
 
452
- purge = function purge () {
453
- watchFiles.forEach(function (file) {
541
+ purge = () => {
542
+ watchFiles.forEach(file => {
454
543
  delete require.cache[file];
455
544
  });
456
545
  };
457
546
 
458
547
  loadAndRun();
459
548
 
460
- rerun = function rerun () {
549
+ rerun = () => {
461
550
  purge();
462
551
  stop();
463
552
  if (!program.grep) {
@@ -469,7 +558,7 @@ if (program.watch) {
469
558
  loadAndRun();
470
559
  };
471
560
 
472
- utils.watch(watchFiles, function () {
561
+ utils.watch(watchFiles, () => {
473
562
  runAgain = true;
474
563
  if (runner) {
475
564
  runner.abort();
@@ -484,41 +573,7 @@ if (program.watch) {
484
573
  runner = mocha.run(program.exit ? exit : exitLater);
485
574
  }
486
575
 
487
- function exitLater (code) {
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 () {
576
+ process.on('SIGINT', () => {
522
577
  runner.abort();
523
578
 
524
579
  // This is a hack:
@@ -526,51 +581,3 @@ process.on('SIGINT', function () {
526
581
  // The amount of failures will be emitted as error code later
527
582
  runner.failures = 130;
528
583
  });
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
- var spawn = require('child_process').spawn;
11
- var path = require('path');
12
- var getOptions = require('./options');
13
- var args = [path.join(__dirname, '_mocha')];
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(function (arg) {
20
- var flag = arg.split('=')[0];
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
- var proc = spawn(process.execPath, args, { stdio: 'inherit' });
73
- proc.on('exit', function (code, signal) {
74
- process.on('exit', function () {
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', function () {
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
- var fs = require('fs');
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
- var optsPath = process.argv.indexOf('--opts') === -1
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
- var opts = fs.readFileSync(optsPath, 'utf8')
29
+ const opts = fs.readFileSync(optsPath, 'utf8')
26
30
  .replace(/\\\s/g, '%20')
27
31
  .split(/\s/)
28
32
  .filter(Boolean)
29
- .map(function (value) {
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)