mocha 3.5.2 → 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,137 @@
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
+
53
+ # 4.0.1 / 2017-10-05
54
+
55
+ ## :bug: Fixes
56
+
57
+ - [#3051]: Upgrade Growl to v1.10.3 to fix its [peer dep problems](https://github.com/tj/node-growl/pull/68) ([@dpogue])
58
+
59
+ [#3051]: https://github.com/mochajs/mocha/pull/3051
60
+ [@dpogue]: https://github.com/dpogue
61
+
62
+ # 4.0.0 / 2017-10-02
63
+
64
+ You might want to read this before filing a new bug! :stuck_out_tongue_closed_eyes:
65
+
66
+ ## :boom: Breaking Changes
67
+
68
+ For more info, please [read this article](https://boneskull.com/mocha-v4-nears-release/).
69
+
70
+ ### Compatibility
71
+
72
+ - [#3016]: Drop support for unmaintained versions of Node.js ([@boneskull]):
73
+ - 0.10.x
74
+ - 0.11.x
75
+ - 0.12.x
76
+ - iojs (any)
77
+ - 5.x.x
78
+ - [#2979]: Drop support for non-ES5-compliant browsers ([@boneskull]):
79
+ - IE7
80
+ - IE8
81
+ - PhantomJS 1.x
82
+ - [#2615]: Drop Bower support; old versions (3.x, etc.) will remain available ([@ScottFreeCode], [@boneskull])
83
+
84
+ ### Default Behavior
85
+
86
+ - [#2879]: By default, Mocha will no longer force the process to exit once all tests complete. This means any test code (or code under test) which would normally prevent `node` from exiting will do so when run in Mocha. Supply the `--exit` flag to revert to pre-v4.0.0 behavior ([@ScottFreeCode], [@boneskull])
87
+
88
+ ### Reporter Output
89
+
90
+ - [#2095]: Remove `stdout:` prefix from browser reporter logs ([@skeggse])
91
+ - [#2295]: Add separator in "unified diff" output ([@olsonpm])
92
+ - [#2686]: Print failure message when `--forbid-pending` or `--forbid-only` is specified ([@ScottFreeCode])
93
+ - [#2814]: Indent contexts for better readability when reporting failures ([@charlierudolph])
94
+
95
+ ## :-1: Deprecations
96
+
97
+ - [#2493]: The `--compilers` command-line option is now soft-deprecated and will emit a warning on `STDERR`. Read [this](https://github.com/mochajs/mocha/wiki/compilers-deprecation) for more info and workarounds ([@ScottFreeCode], [@boneskull])
98
+
99
+ ## :tada: Enhancements
100
+
101
+ - [#2628]: Allow override of default test suite name in XUnit reporter ([@ngeor])
102
+
103
+ ## :book: Documentation
104
+
105
+ - [#3020]: Link to CLA in `README.md` and `CONTRIBUTING.md` ([@skeggse])
106
+
107
+ ## :nut_and_bolt: Other
108
+
109
+ - [#2890]: Speed up build by (re-)consolidating SauceLabs tests ([@boneskull])
110
+
111
+ [#3016]: https://github.com/mochajs/mocha/issues/3016
112
+ [#2979]: https://github.com/mochajs/mocha/issues/2979
113
+ [#2615]: https://github.com/mochajs/mocha/issues/2615
114
+ [#2879]: https://github.com/mochajs/mocha/issues/2879
115
+ [#2095]: https://github.com/mochajs/mocha/issues/2095
116
+ [#2295]: https://github.com/mochajs/mocha/issues/2295
117
+ [#2686]: https://github.com/mochajs/mocha/issues/2686
118
+ [#2814]: https://github.com/mochajs/mocha/pull/2814
119
+ [#2493]: https://github.com/mochajs/mocha/issues/2493
120
+ [#2628]: https://github.com/mochajs/mocha/issues/2628
121
+ [#3020]: https://github.com/mochajs/mocha/pull/3020
122
+ [#2890]: https://github.com/mochajs/mocha/issues/2890
123
+ [@skeggse]: https://github.com/skeggse
124
+ [@olsonpm]: https://github.com/olsonpm
125
+ [@ngeor]: https://github.com/ngeor
126
+
127
+ # 3.5.3 / 2017-09-11
128
+
129
+ ## :bug: Fixes
130
+
131
+ - [#3003]: Fix invalid entities in xUnit reporter first appearing in v3.5.1 ([@jkrems])
132
+
133
+ [#3003]: https://github.com/mochajs/mocha/pull/3003
134
+
1
135
  # 3.5.2 / 2017-09-10
2
136
 
3
137
  ## :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.
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,11 +174,12 @@ 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')
96
181
  .option('--no-deprecation', 'silence deprecation warnings')
97
- .option('--no-exit', 'require a clean shutdown of the event loop: mocha will not call process.exit')
182
+ .option('--exit', 'force shutdown of the event loop after test run: mocha will call process.exit')
98
183
  .option('--no-timeouts', 'disables timeouts, given implicitly with --debug')
99
184
  .option('--no-warnings', 'silence all node process warnings')
100
185
  .option('--opts <path>', 'specify opts path', 'test/mocha.opts')
@@ -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('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('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('reporters', function () {
165
250
 
166
251
  // --interfaces
167
252
 
168
- program.on('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('interfaces', function () {
178
263
 
179
264
  module.paths.push(cwd, join(cwd, 'node_modules'));
180
265
 
181
- program.on('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) {
@@ -346,11 +437,15 @@ if (program.forbidPending) mocha.forbidPending();
346
437
 
347
438
  // custom compiler support
348
439
 
349
- var extensions = ['js'];
350
- program.compilers.forEach(function (c) {
351
- var idx = c.indexOf(':');
352
- var ext = c.slice(0, idx);
353
- var mod = c.slice(idx + 1);
440
+ if (program.compilers.length > 0) {
441
+ require('util').deprecate(() => {},
442
+ '"--compilers" will be removed in a future version of Mocha; see https://git.io/vdcSr for more info')();
443
+ }
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);
354
449
 
355
450
  if (mod[0] === '.') {
356
451
  mod = join(process.cwd(), mod);
@@ -362,7 +457,7 @@ program.compilers.forEach(function (c) {
362
457
 
363
458
  // requires
364
459
 
365
- requires.forEach(function (mod) {
460
+ requires.forEach(mod => {
366
461
  require(mod);
367
462
  });
368
463
 
@@ -372,7 +467,7 @@ mocha.ui(program.ui);
372
467
 
373
468
  // args
374
469
 
375
- var args = program.args;
470
+ const args = program.args;
376
471
 
377
472
  // default files to test/*.{js,coffee}
378
473
 
@@ -380,13 +475,13 @@ if (!args.length) {
380
475
  args.push('test');
381
476
  }
382
477
 
383
- args.forEach(function (arg) {
384
- var newFiles;
478
+ args.forEach(arg => {
479
+ let newFiles;
385
480
  try {
386
481
  newFiles = utils.lookupFiles(arg, extensions, program.recursive);
387
482
  } catch (err) {
388
483
  if (err.message.indexOf('cannot resolve path') === 0) {
389
- 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}`);
390
485
  return;
391
486
  }
392
487
 
@@ -403,9 +498,7 @@ if (!files.length) {
403
498
 
404
499
  // resolve
405
500
 
406
- files = files.map(function (path) {
407
- return resolve(path);
408
- });
501
+ files = files.map(path => resolve(path));
409
502
 
410
503
  if (program.sort) {
411
504
  files.sort();
@@ -413,28 +506,28 @@ if (program.sort) {
413
506
 
414
507
  // --watch
415
508
 
416
- var runner;
417
- var loadAndRun;
418
- var purge;
419
- var rerun;
509
+ let runner;
510
+ let loadAndRun;
511
+ let purge;
512
+ let rerun;
420
513
 
421
514
  if (program.watch) {
422
515
  console.log();
423
516
  hideCursor();
424
- process.on('SIGINT', function () {
517
+ process.on('SIGINT', () => {
425
518
  showCursor();
426
519
  console.log('\n');
427
520
  process.exit(130);
428
521
  });
429
522
 
430
- var watchFiles = utils.files(cwd, [ 'js' ].concat(program.watchExtensions));
431
- var runAgain = false;
523
+ const watchFiles = utils.files(cwd, [ 'js' ].concat(program.watchExtensions));
524
+ let runAgain = false;
432
525
 
433
- loadAndRun = function loadAndRun () {
526
+ loadAndRun = () => {
434
527
  try {
435
528
  mocha.files = files;
436
529
  runAgain = false;
437
- runner = mocha.run(function () {
530
+ runner = mocha.run(() => {
438
531
  runner = null;
439
532
  if (runAgain) {
440
533
  rerun();
@@ -445,15 +538,15 @@ if (program.watch) {
445
538
  }
446
539
  };
447
540
 
448
- purge = function purge () {
449
- watchFiles.forEach(function (file) {
541
+ purge = () => {
542
+ watchFiles.forEach(file => {
450
543
  delete require.cache[file];
451
544
  });
452
545
  };
453
546
 
454
547
  loadAndRun();
455
548
 
456
- rerun = function rerun () {
549
+ rerun = () => {
457
550
  purge();
458
551
  stop();
459
552
  if (!program.grep) {
@@ -465,7 +558,7 @@ if (program.watch) {
465
558
  loadAndRun();
466
559
  };
467
560
 
468
- utils.watch(watchFiles, function () {
561
+ utils.watch(watchFiles, () => {
469
562
  runAgain = true;
470
563
  if (runner) {
471
564
  runner.abort();
@@ -480,41 +573,7 @@ if (program.watch) {
480
573
  runner = mocha.run(program.exit ? exit : exitLater);
481
574
  }
482
575
 
483
- function exitLater (code) {
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 () {
576
+ process.on('SIGINT', () => {
518
577
  runner.abort();
519
578
 
520
579
  // This is a hack:
@@ -522,51 +581,3 @@ process.on('SIGINT', function () {
522
581
  // The amount of failures will be emitted as error code later
523
582
  runner.failures = 130;
524
583
  });
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
- }