mocha 8.3.2 → 9.0.2

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,70 @@
1
+ # 9.0.2 / 2021-07-03
2
+
3
+ ## :bug: Fixes
4
+
5
+ - [#4668](https://github.com/mochajs/mocha/issues/4668): ESM: make `--require <dir>` work with new `import`-first loading ([**@giltayar**](https://github.com/giltayar))
6
+
7
+ ## :nut_and_bolt: Other
8
+
9
+ - [#4674](https://github.com/mochajs/mocha/issues/4674): Update production dependencies ([**@juergba**](https://github.com/juergba))
10
+
11
+ # 9.0.1 / 2021-06-18
12
+
13
+ ## :nut_and_bolt: Other
14
+
15
+ - [#4657](https://github.com/mochajs/mocha/issues/4657): Browser: add separate bundle for modern browsers ([**@juergba**](https://github.com/juergba))
16
+
17
+ We added a separate browser bundle `mocha-es2018.js` in javascript ES2018, as we skipped the transpilation down to ES5. This is an **experimental step towards freezing Mocha's support of IE11**.
18
+
19
+ - [#4653](https://github.com/mochajs/mocha/issues/4653): ESM: proper version check in `hasStableEsmImplementation` ([**@alexander-fenster**](https://github.com/alexander-fenster))
20
+
21
+ # 9.0.0 / 2021-06-07
22
+
23
+ ## :boom: Breaking Changes
24
+
25
+ - [#4633](https://github.com/mochajs/mocha/issues/4633): **Drop Node.js v10.x support** ([**@juergba**](https://github.com/juergba))
26
+
27
+ - [#4635](https://github.com/mochajs/mocha/issues/4635): `import`-first loading of test files ([**@giltayar**](https://github.com/giltayar))
28
+
29
+ **Mocha is going ESM-first!** This means that it will now use ESM `import(test_file)` to load the test files, instead of the CommonJS `require(test_file)`. This is not a problem, as `import` can also load most files that `require` does. In the rare cases where this fails, it will fallback to `require(...)`. This ESM-first approach is the next step in Mocha's ESM migration, and allows ESM loaders to load and transform the test file.
30
+
31
+ - [#4636](https://github.com/mochajs/mocha/issues/4636): Remove deprecated `utils.lookupFiles()` ([**@juergba**](https://github.com/juergba))
32
+
33
+ - [#4638](https://github.com/mochajs/mocha/issues/4638): Limit the size of `actual`/`expected` for `diff` generation ([**@juergba**](https://github.com/juergba))
34
+
35
+ - [#4389](https://github.com/mochajs/mocha/issues/4389): Refactoring: Consuming log-symbols alternate to code for win32 in reporters/base ([**@MoonSupport**](https://github.com/MoonSupport))
36
+
37
+ ## :tada: Enhancements
38
+
39
+ - [#4640](https://github.com/mochajs/mocha/issues/4640): Add new option `--dry-run` ([**@juergba**](https://github.com/juergba))
40
+
41
+ ## :bug: Fixes
42
+
43
+ - [#4128](https://github.com/mochajs/mocha/issues/4128): Fix: control stringification of error message ([**@syeutyu**](https://github.com/syeutyu))
44
+
45
+ ## :nut_and_bolt: Other
46
+
47
+ - [#4646](https://github.com/mochajs/mocha/issues/4646): Deprecate `Runner(suite: Suite, delay: boolean)` signature ([**@juergba**](https://github.com/juergba))
48
+ - [#4643](https://github.com/mochajs/mocha/issues/4643): Update production dependencies ([**@juergba**](https://github.com/juergba))
49
+
50
+ # 8.4.0 / 2021-05-07
51
+
52
+ ## :tada: Enhancements
53
+
54
+ - [#4502](https://github.com/mochajs/mocha/issues/4502): CLI file parsing errors now have error codes ([**@evaline-ju**](https://github.com/evaline-ju))
55
+
56
+ ## :bug: Fixes
57
+
58
+ - [#4614](https://github.com/mochajs/mocha/issues/4614): Watch: fix crash when reloading files ([**@outsideris**](https://github.com/outsideris))
59
+
60
+ ## :book: Documentation
61
+
62
+ - [#4630](https://github.com/mochajs/mocha/issues/4630): Add `options.require` to Mocha constructor for `root hook` plugins on parallel runs ([**@juergba**](https://github.com/juergba))
63
+ - [#4617](https://github.com/mochajs/mocha/issues/4617): Dynamically generating tests with `top-level await` and ESM test files ([**@juergba**](https://github.com/juergba))
64
+ - [#4608](https://github.com/mochajs/mocha/issues/4608): Update default file extensions ([**@outsideris**](https://github.com/outsideris))
65
+
66
+ Also thanks to [**@outsideris**](https://github.com/outsideris) for various improvements on our GH actions workflows.
67
+
1
68
  # 8.3.2 / 2021-03-12
2
69
 
3
70
  ## :bug: Fixes
package/README.md CHANGED
@@ -9,8 +9,8 @@
9
9
  <a href="https://coveralls.io/github/mochajs/mocha"><img src="https://coveralls.io/repos/github/mochajs/mocha/badge.svg" alt="Coverage Status"></a>
10
10
  <a href="https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmochajs%2Fmocha?ref=badge_shield"><img src="https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmochajs%2Fmocha.svg?type=shield" alt="FOSSA Status"></a>
11
11
  <a href="https://gitter.im/mochajs/mocha?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"><img src="https://badges.gitter.im/Join%20Chat.svg" alt="Gitter"></a>
12
- <a href="https://github.com/mochajs/mocha#backers"><img src="https://opencollective.com/mochajs/backers/badge.svg" alt="OpenCollective"></a>
13
- <a href="https://github.com/mochajs/mocha#sponsors"><img src="https://opencollective.com/mochajs/sponsors/badge.svg" alt="OpenCollective"></a>
12
+ <a href="https://github.com/mochajs/mocha#sponsors"><img src="https://opencollective.com/mochajs/tiers/sponsors/badge.svg" alt="OpenCollective"></a>
13
+ <a href="https://github.com/mochajs/mocha#backers"><img src="https://opencollective.com/mochajs/tiers/backers/badge.svg" alt="OpenCollective"></a>
14
14
  </p>
15
15
 
16
16
  <p align="center">
@@ -27,74 +27,28 @@
27
27
  - [Code of Conduct](https://github.com/mochajs/mocha/blob/master/.github/CODE_OF_CONDUCT.md)
28
28
  - [Contributing](https://github.com/mochajs/mocha/blob/master/.github/CONTRIBUTING.md)
29
29
  - [Gitter Chatroom](https://gitter.im/mochajs/mocha) (ask questions here!)
30
- - [Google Group](https://groups.google.com/group/mochajs)
31
30
  - [Issue Tracker](https://github.com/mochajs/mocha/issues)
32
31
 
33
32
  ## Backers
34
33
 
35
- [Become a backer](https://opencollective.com/mochajs#backer) and show your support to our open source project.
36
-
37
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/0/avatar)](https://opencollective.com/mochajs/backer/0/website)
38
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/1/avatar)](https://opencollective.com/mochajs/backer/1/website)
39
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/2/avatar)](https://opencollective.com/mochajs/backer/2/website)
40
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/3/avatar)](https://opencollective.com/mochajs/backer/3/website)
41
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/4/avatar)](https://opencollective.com/mochajs/backer/4/website)
42
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/5/avatar)](https://opencollective.com/mochajs/backer/5/website)
43
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/6/avatar)](https://opencollective.com/mochajs/backer/6/website)
44
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/7/avatar)](https://opencollective.com/mochajs/backer/7/website)
45
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/8/avatar)](https://opencollective.com/mochajs/backer/8/website)
46
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/9/avatar)](https://opencollective.com/mochajs/backer/9/website)
47
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/10/avatar)](https://opencollective.com/mochajs/backer/10/website)
48
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/11/avatar)](https://opencollective.com/mochajs/backer/11/website)
49
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/12/avatar)](https://opencollective.com/mochajs/backer/12/website)
50
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/13/avatar)](https://opencollective.com/mochajs/backer/13/website)
51
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/14/avatar)](https://opencollective.com/mochajs/backer/14/website)
52
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/15/avatar)](https://opencollective.com/mochajs/backer/15/website)
53
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/16/avatar)](https://opencollective.com/mochajs/backer/16/website)
54
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/17/avatar)](https://opencollective.com/mochajs/backer/17/website)
55
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/18/avatar)](https://opencollective.com/mochajs/backer/18/website)
56
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/19/avatar)](https://opencollective.com/mochajs/backer/19/website)
57
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/20/avatar)](https://opencollective.com/mochajs/backer/20/website)
58
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/21/avatar)](https://opencollective.com/mochajs/backer/21/website)
59
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/22/avatar)](https://opencollective.com/mochajs/backer/22/website)
60
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/23/avatar)](https://opencollective.com/mochajs/backer/23/website)
61
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/24/avatar)](https://opencollective.com/mochajs/backer/24/website)
62
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/25/avatar)](https://opencollective.com/mochajs/backer/25/website)
63
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/26/avatar)](https://opencollective.com/mochajs/backer/26/website)
64
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/27/avatar)](https://opencollective.com/mochajs/backer/27/website)
65
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/28/avatar)](https://opencollective.com/mochajs/backer/28/website)
66
- [![MochaJS Backer](https://opencollective.com/mochajs/backer/29/avatar)](https://opencollective.com/mochajs/backer/29/website)
34
+ [Become a backer](https://opencollective.com/mochajs) and show your support to our open source project on [our site](https://mochajs.org/#backers).
35
+
36
+ <a href="https://opencollective.com/mochajs"><img src="https://opencollective.com/mochajs/tiers/backers.svg?limit=30&button=false&avatarHeight=46&width=750"></a>
67
37
 
68
38
  ## Sponsors
69
39
 
70
- Does your company use Mocha? Ask your manager or marketing team if your company would be interested in supporting our project. Support will allow the maintainers to dedicate more time for maintenance and new features for everyone. Also, your company's logo will show [on GitHub](https://github.com/mochajs/mocha#readme) and on [our site](https://mochajs.org) - who doesn't want a little extra exposure? [Here's the info](https://opencollective.com/mochajs#sponsor).
71
-
72
- [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/0/avatar)](https://opencollective.com/mochajs/sponsor/0/website)
73
- [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/1/avatar)](https://opencollective.com/mochajs/sponsor/1/website)
74
- [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/2/avatar)](https://opencollective.com/mochajs/sponsor/2/website)
75
- [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/3/avatar)](https://opencollective.com/mochajs/sponsor/3/website)
76
- [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/4/avatar)](https://opencollective.com/mochajs/sponsor/4/website)
77
- [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/5/avatar)](https://opencollective.com/mochajs/sponsor/5/website)
78
- [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/6/avatar)](https://opencollective.com/mochajs/sponsor/6/website)
79
- [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/7/avatar)](https://opencollective.com/mochajs/sponsor/7/website)
80
- [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/8/avatar)](https://opencollective.com/mochajs/sponsor/8/website)
81
- [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/9/avatar)](https://opencollective.com/mochajs/sponsor/9/website)
82
- [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/10/avatar)](https://opencollective.com/mochajs/sponsor/10/website)
83
- [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/11/avatar)](https://opencollective.com/mochajs/sponsor/11/website)
84
- [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/12/avatar)](https://opencollective.com/mochajs/sponsor/12/website)
85
- [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/13/avatar)](https://opencollective.com/mochajs/sponsor/13/website)
86
- [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/14/avatar)](https://opencollective.com/mochajs/sponsor/14/website)
87
- [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/15/avatar)](https://opencollective.com/mochajs/sponsor/15/website)
88
- [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/16/avatar)](https://opencollective.com/mochajs/sponsor/16/website)
89
- [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/17/avatar)](https://opencollective.com/mochajs/sponsor/17/website)
90
- [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/18/avatar)](https://opencollective.com/mochajs/sponsor/18/website)
91
- [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/19/avatar)](https://opencollective.com/mochajs/sponsor/19/website)
40
+ Does your company use Mocha? Ask your manager or marketing team if your company would be interested in supporting our project. Support will allow the maintainers to dedicate more time for maintenance and new features for everyone. Also, your company's logo will show [on GitHub](https://github.com/mochajs/mocha#readme) and on [our site](https://mochajs.org#sponsors) - who doesn't want a little extra exposure? [Here's the info](https://opencollective.com/mochajs).
41
+
42
+ [![MochaJS Sponsor](https://opencollective.com/mochajs/tiers/sponsors/0/avatar)](https://opencollective.com/mochajs/tiers/sponsors/0/website)
43
+ [![MochaJS Sponsor](https://opencollective.com/mochajs/tiers/sponsors/1/avatar)](https://opencollective.com/mochajs/tiers/sponsors/1/website)
44
+ [![MochaJS Sponsor](https://opencollective.com/mochajs/tiers/sponsors/2/avatar)](https://opencollective.com/mochajs/tiers/sponsors/2/website)
45
+ [![MochaJS Sponsor](https://opencollective.com/mochajs/tiers/sponsors/3/avatar)](https://opencollective.com/mochajs/tiers/sponsors/3/website)
92
46
 
93
47
  ## Development
94
48
 
95
49
  You might want to know that:
96
50
 
97
- - Mocha is the _most-depended-upon_ module on npm (source: [libraries.io](https://libraries.io/search?order=desc&platforms=NPM&sort=dependents_count)), and
51
+ - Mocha is one of the _most-depended-upon_ modules on npm (source: [libraries.io](https://libraries.io/search?order=desc&platforms=NPM&sort=dependents_count)), and
98
52
  - Mocha is an _independent_ open-source project, maintained exclusively by volunteers.
99
53
 
100
54
  You might want to help:
package/lib/cli/config.js CHANGED
@@ -11,6 +11,7 @@ const fs = require('fs');
11
11
  const path = require('path');
12
12
  const debug = require('debug')('mocha:cli:config');
13
13
  const findUp = require('find-up');
14
+ const {createUnparsableFileError} = require('../errors');
14
15
  const utils = require('../utils');
15
16
 
16
17
  /**
@@ -81,7 +82,10 @@ exports.loadConfig = filepath => {
81
82
  config = parsers.json(filepath);
82
83
  }
83
84
  } catch (err) {
84
- throw new Error(`failed to parse config "${filepath}": ${err}`);
85
+ throw createUnparsableFileError(
86
+ `Unable to read/parse ${filepath}: ${err}`,
87
+ filepath
88
+ );
85
89
  }
86
90
  return config;
87
91
  };
@@ -8,11 +8,9 @@
8
8
  var fs = require('fs');
9
9
  var path = require('path');
10
10
  var glob = require('glob');
11
- var {format} = require('util');
12
11
  var errors = require('../errors');
13
12
  var createNoFilesMatchPatternError = errors.createNoFilesMatchPatternError;
14
13
  var createMissingArgumentError = errors.createMissingArgumentError;
15
- var {sQuote, dQuote} = require('../utils');
16
14
  const debug = require('debug')('mocha:cli:lookup-files');
17
15
 
18
16
  /**
@@ -91,7 +89,7 @@ module.exports = function lookupFiles(
91
89
  files.push(...glob.sync(pattern, {nodir: true}));
92
90
  if (!files.length) {
93
91
  throw createNoFilesMatchPatternError(
94
- 'Cannot find any files matching pattern ' + dQuote(filepath),
92
+ `Cannot find any files matching pattern "${filepath}"`,
95
93
  filepath
96
94
  );
97
95
  }
@@ -127,11 +125,7 @@ module.exports = function lookupFiles(
127
125
  }
128
126
  if (!extensions.length) {
129
127
  throw createMissingArgumentError(
130
- format(
131
- 'Argument %s required when argument %s is a directory',
132
- sQuote('extensions'),
133
- sQuote('filepath')
134
- ),
128
+ `Argument '${extensions}' required when argument '${filepath}' is a directory`,
135
129
  'extensions',
136
130
  'array'
137
131
  );
@@ -18,6 +18,7 @@ const {loadConfig, findConfig} = require('./config');
18
18
  const findUp = require('find-up');
19
19
  const debug = require('debug')('mocha:cli:options');
20
20
  const {isNodeFlag} = require('./node-flags');
21
+ const {createUnparsableFileError} = require('../errors');
21
22
 
22
23
  /**
23
24
  * The `yargs-parser` namespace
@@ -190,7 +191,10 @@ const loadPkgRc = (args = {}) => {
190
191
  }
191
192
  } catch (err) {
192
193
  if (args.package) {
193
- throw new Error(`Unable to read/parse ${filepath}: ${err}`);
194
+ throw createUnparsableFileError(
195
+ `Unable to read/parse ${filepath}: ${err}`,
196
+ filepath
197
+ );
194
198
  }
195
199
  debug('failed to read default package.json at %s; ignoring', filepath);
196
200
  }
@@ -32,6 +32,7 @@ const TYPES = (exports.types = {
32
32
  'color',
33
33
  'delay',
34
34
  'diff',
35
+ 'dry-run',
35
36
  'exit',
36
37
  'forbid-only',
37
38
  'forbid-pending',
package/lib/cli/run.js CHANGED
@@ -83,6 +83,10 @@ exports.builder = yargs =>
83
83
  description: 'Show diff on failure',
84
84
  group: GROUPS.OUTPUT
85
85
  },
86
+ 'dry-run': {
87
+ description: 'Report tests without executing them',
88
+ group: GROUPS.RULES
89
+ },
86
90
  exit: {
87
91
  description: 'Force Mocha to quit after tests complete',
88
92
  group: GROUPS.RULES
@@ -261,17 +261,21 @@ const createRerunner = (mocha, watcher, {beforeRun} = {}) => {
261
261
  let rerunScheduled = false;
262
262
 
263
263
  const run = () => {
264
- mocha = beforeRun ? beforeRun({mocha, watcher}) || mocha : mocha;
265
- runner = mocha.run(() => {
266
- debug('finished watch run');
267
- runner = null;
268
- blastCache(watcher);
269
- if (rerunScheduled) {
270
- rerun();
271
- } else {
272
- console.error(`${logSymbols.info} [mocha] waiting for changes...`);
273
- }
274
- });
264
+ try {
265
+ mocha = beforeRun ? beforeRun({mocha, watcher}) || mocha : mocha;
266
+ runner = mocha.run(() => {
267
+ debug('finished watch run');
268
+ runner = null;
269
+ blastCache(watcher);
270
+ if (rerunScheduled) {
271
+ rerun();
272
+ } else {
273
+ console.error(`${logSymbols.info} [mocha] waiting for changes...`);
274
+ }
275
+ });
276
+ } catch (e) {
277
+ console.error(e.stack);
278
+ }
275
279
  };
276
280
 
277
281
  const scheduleRun = () => {
package/lib/errors.js CHANGED
@@ -163,7 +163,14 @@ var constants = {
163
163
  * @constant
164
164
  * @default
165
165
  */
166
- TIMEOUT: 'ERR_MOCHA_TIMEOUT'
166
+ TIMEOUT: 'ERR_MOCHA_TIMEOUT',
167
+
168
+ /**
169
+ * Input file is not able to be parsed
170
+ * @constant
171
+ * @default
172
+ */
173
+ UNPARSABLE_FILE: 'ERR_MOCHA_UNPARSABLE_FILE'
167
174
  };
168
175
 
169
176
  /**
@@ -495,6 +502,20 @@ function createTimeoutError(msg, timeout, file) {
495
502
  return err;
496
503
  }
497
504
 
505
+ /**
506
+ * Creates an error object to be thrown when file is unparsable
507
+ * @public
508
+ * @static
509
+ * @param {string} message - Error message to be displayed.
510
+ * @param {string} filename - File name
511
+ * @returns {Error} Error with code {@link constants.UNPARSABLE_FILE}
512
+ */
513
+ function createUnparsableFileError(message, filename) {
514
+ var err = new Error(message);
515
+ err.code = constants.UNPARSABLE_FILE;
516
+ return err;
517
+ }
518
+
498
519
  /**
499
520
  * Returns `true` if an error came out of Mocha.
500
521
  * _Can suffer from false negatives, but not false positives._
@@ -525,6 +546,7 @@ module.exports = {
525
546
  createMultipleDoneError,
526
547
  createNoFilesMatchPatternError,
527
548
  createTimeoutError,
549
+ createUnparsableFileError,
528
550
  createUnsupportedError,
529
551
  deprecate,
530
552
  isMochaError,
package/lib/esm-utils.js CHANGED
@@ -30,14 +30,59 @@ const formattedImport = async file => {
30
30
  return import(file);
31
31
  };
32
32
 
33
- exports.requireOrImport = async file => {
33
+ const hasStableEsmImplementation = (() => {
34
+ const [major, minor] = process.version.split('.');
35
+ // ESM is stable from v12.22.0 onward
36
+ // https://nodejs.org/api/esm.html#esm_modules_ecmascript_modules
37
+ const majorNumber = parseInt(major.slice(1), 10);
38
+ const minorNumber = parseInt(minor, 10);
39
+ return majorNumber > 12 || (majorNumber === 12 && minorNumber >= 22);
40
+ })();
41
+
42
+ exports.requireOrImport = hasStableEsmImplementation
43
+ ? async file => {
44
+ if (path.extname(file) === '.mjs') {
45
+ return formattedImport(file);
46
+ }
47
+ try {
48
+ return dealWithExports(await formattedImport(file));
49
+ } catch (err) {
50
+ if (
51
+ err.code === 'ERR_MODULE_NOT_FOUND' ||
52
+ err.code === 'ERR_UNKNOWN_FILE_EXTENSION' ||
53
+ err.code === 'ERR_UNSUPPORTED_DIR_IMPORT'
54
+ ) {
55
+ return require(file);
56
+ } else {
57
+ throw err;
58
+ }
59
+ }
60
+ }
61
+ : implementationOfRequireOrImportForUnstableEsm;
62
+
63
+ function dealWithExports(module) {
64
+ if (module.default) {
65
+ return module.default;
66
+ } else {
67
+ return {...module, default: undefined};
68
+ }
69
+ }
70
+
71
+ exports.loadFilesAsync = async (files, preLoadFunc, postLoadFunc) => {
72
+ for (const file of files) {
73
+ preLoadFunc(file);
74
+ const result = await exports.requireOrImport(path.resolve(file));
75
+ postLoadFunc(file, result);
76
+ }
77
+ };
78
+
79
+ /* istanbul ignore next */
80
+ async function implementationOfRequireOrImportForUnstableEsm(file) {
34
81
  if (path.extname(file) === '.mjs') {
35
82
  return formattedImport(file);
36
83
  }
37
- // This is currently the only known way of figuring out whether a file is CJS or ESM.
38
- // If Node.js or the community establish a better procedure for that, we can fix this code.
39
- // Another option here would be to always use `import()`, as this also supports CJS, but I would be
40
- // wary of using it for _all_ existing test files, till ESM is fully stable.
84
+ // This is currently the only known way of figuring out whether a file is CJS or ESM in
85
+ // Node.js that doesn't necessitate calling `import` first.
41
86
  try {
42
87
  return require(file);
43
88
  } catch (err) {
@@ -47,12 +92,4 @@ exports.requireOrImport = async file => {
47
92
  throw err;
48
93
  }
49
94
  }
50
- };
51
-
52
- exports.loadFilesAsync = async (files, preLoadFunc, postLoadFunc) => {
53
- for (const file of files) {
54
- preLoadFunc(file);
55
- const result = await exports.requireOrImport(path.resolve(file));
56
- postLoadFunc(file, result);
57
- }
58
- };
95
+ }
@@ -105,13 +105,6 @@ module.exports = function bddInterface(suite) {
105
105
  context.xit = context.xspecify = context.it.skip = function(title) {
106
106
  return context.it(title);
107
107
  };
108
-
109
- /**
110
- * Number of attempts to retry.
111
- */
112
- context.it.retries = function(n) {
113
- context.retries(n);
114
- };
115
108
  });
116
109
  };
117
110
 
@@ -187,15 +187,6 @@ module.exports = function(suites, context, mocha) {
187
187
  */
188
188
  skip: function(title) {
189
189
  context.test(title);
190
- },
191
-
192
- /**
193
- * Number of retry attempts
194
- *
195
- * @param {number} n
196
- */
197
- retries: function(n) {
198
- context.retries(n);
199
190
  }
200
191
  }
201
192
  };
@@ -92,7 +92,6 @@ module.exports = function qUnitInterface(suite) {
92
92
  };
93
93
 
94
94
  context.test.skip = common.test.skip;
95
- context.test.retries = common.test.retries;
96
95
  });
97
96
  };
98
97
 
@@ -99,7 +99,6 @@ module.exports = function(suite) {
99
99
  };
100
100
 
101
101
  context.test.skip = common.test.skip;
102
- context.test.retries = common.test.retries;
103
102
  });
104
103
  };
105
104
 
package/lib/mocha.js CHANGED
@@ -30,7 +30,6 @@ const {
30
30
  EVENT_FILE_POST_REQUIRE,
31
31
  EVENT_FILE_REQUIRE
32
32
  } = Suite.constants;
33
- var sQuote = utils.sQuote;
34
33
  var debug = require('debug')('mocha:mocha');
35
34
 
36
35
  exports = module.exports = Mocha;
@@ -164,6 +163,7 @@ exports.run = function(...args) {
164
163
  * @param {boolean} [options.color] - Color TTY output from reporter?
165
164
  * @param {boolean} [options.delay] - Delay root suite execution?
166
165
  * @param {boolean} [options.diff] - Show diff on failure?
166
+ * @param {boolean} [options.dryRun] - Report tests without running them?
167
167
  * @param {string} [options.fgrep] - Test filter given string.
168
168
  * @param {boolean} [options.forbidOnly] - Tests marked `only` fail the suite?
169
169
  * @param {boolean} [options.forbidPending] - Pending tests fail the suite?
@@ -180,10 +180,10 @@ exports.run = function(...args) {
180
180
  * @param {number} [options.slow] - Slow threshold value.
181
181
  * @param {number|string} [options.timeout] - Timeout threshold value.
182
182
  * @param {string} [options.ui] - Interface name.
183
- * @param {boolean} [options.parallel] - Run jobs in parallel
184
- * @param {number} [options.jobs] - Max number of worker processes for parallel runs
185
- * @param {MochaRootHookObject} [options.rootHooks] - Hooks to bootstrap the root
186
- * suite with
183
+ * @param {boolean} [options.parallel] - Run jobs in parallel.
184
+ * @param {number} [options.jobs] - Max number of worker processes for parallel runs.
185
+ * @param {MochaRootHookObject} [options.rootHooks] - Hooks to bootstrap the root suite with.
186
+ * @param {string[]} [options.require] - Pathname of `rootHooks` plugin for parallel runs.
187
187
  * @param {boolean} [options.isWorker] - Should be `true` if `Mocha` process is running in a worker process.
188
188
  */
189
189
  function Mocha(options = {}) {
@@ -200,7 +200,7 @@ function Mocha(options = {}) {
200
200
  .ui(options.ui)
201
201
  .reporter(
202
202
  options.reporter,
203
- options.reporterOption || options.reporterOptions // reporterOptions was previously the only way to specify options to reporter
203
+ options.reporterOption || options.reporterOptions // for backwards compability
204
204
  )
205
205
  .slow(options.slow)
206
206
  .global(options.global);
@@ -222,6 +222,7 @@ function Mocha(options = {}) {
222
222
  'color',
223
223
  'delay',
224
224
  'diff',
225
+ 'dryRun',
225
226
  'forbidOnly',
226
227
  'forbidPending',
227
228
  'fullTrace',
@@ -346,23 +347,19 @@ Mocha.prototype.reporter = function(reporterName, reporterOptions) {
346
347
  reporter = require(path.resolve(utils.cwd(), reporterName));
347
348
  } catch (_err) {
348
349
  _err.code === 'MODULE_NOT_FOUND'
349
- ? warn(sQuote(reporterName) + ' reporter not found')
350
+ ? warn(`'${reporterName}' reporter not found`)
350
351
  : warn(
351
- sQuote(reporterName) +
352
- ' reporter blew up with error:\n' +
353
- err.stack
352
+ `'${reporterName}' reporter blew up with error:\n ${err.stack}`
354
353
  );
355
354
  }
356
355
  } else {
357
- warn(
358
- sQuote(reporterName) + ' reporter blew up with error:\n' + err.stack
359
- );
356
+ warn(`'${reporterName}' reporter blew up with error:\n ${err.stack}`);
360
357
  }
361
358
  }
362
359
  }
363
360
  if (!reporter) {
364
361
  throw createInvalidReporterError(
365
- 'invalid reporter ' + sQuote(reporterName),
362
+ `invalid reporter '${reporterName}'`,
366
363
  reporterName
367
364
  );
368
365
  }
@@ -396,10 +393,7 @@ Mocha.prototype.ui = function(ui) {
396
393
  try {
397
394
  bindInterface = require(ui);
398
395
  } catch (err) {
399
- throw createInvalidInterfaceError(
400
- 'invalid interface ' + sQuote(ui),
401
- ui
402
- );
396
+ throw createInvalidInterfaceError(`invalid interface '${ui}'`, ui);
403
397
  }
404
398
  }
405
399
  }
@@ -784,6 +778,20 @@ Mocha.prototype.diff = function(diff) {
784
778
  return this;
785
779
  };
786
780
 
781
+ /**
782
+ * Enables or disables running tests in dry-run mode.
783
+ *
784
+ * @public
785
+ * @see [CLI option](../#-dry-run)
786
+ * @param {boolean} [dryRun=true] - Whether to activate dry-run mode.
787
+ * @return {Mocha} this
788
+ * @chainable
789
+ */
790
+ Mocha.prototype.dryRun = function(dryRun) {
791
+ this.options.dryRun = dryRun !== false;
792
+ return this;
793
+ };
794
+
787
795
  /**
788
796
  * @summary
789
797
  * Sets timeout threshold value.
@@ -1016,6 +1024,7 @@ Mocha.prototype.run = function(fn) {
1016
1024
  options.files = this.files;
1017
1025
  const runner = new this._runnerClass(suite, {
1018
1026
  delay: options.delay,
1027
+ dryRun: options.dryRun,
1019
1028
  cleanReferencesAfterRun: this._cleanReferencesAfterRun
1020
1029
  });
1021
1030
  createStatsCollector(runner);
@@ -10,6 +10,7 @@ var diff = require('diff');
10
10
  var milliseconds = require('ms');
11
11
  var utils = require('../utils');
12
12
  var supportsColor = require('supports-color');
13
+ var symbols = require('log-symbols');
13
14
  var constants = require('../runner').constants;
14
15
  var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
15
16
  var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
@@ -88,20 +89,13 @@ exports.colors = {
88
89
  */
89
90
 
90
91
  exports.symbols = {
91
- ok: '✓',
92
- err: '✖',
93
- dot: '',
92
+ ok: symbols.success,
93
+ err: symbols.err,
94
+ dot: '.',
94
95
  comma: ',',
95
96
  bang: '!'
96
97
  };
97
98
 
98
- // With node.js on Windows: use symbols available in terminal default fonts
99
- if (process.platform === 'win32') {
100
- exports.symbols.ok = '\u221A';
101
- exports.symbols.err = '\u00D7';
102
- exports.symbols.dot = '.';
103
- }
104
-
105
99
  /**
106
100
  * Color `str` with the given `type`,
107
101
  * allowing colors to be disabled,
@@ -196,6 +190,13 @@ function stringifyDiffObjs(err) {
196
190
  */
197
191
  var generateDiff = (exports.generateDiff = function(actual, expected) {
198
192
  try {
193
+ const diffSize = 2048;
194
+ if (actual.length > diffSize) {
195
+ actual = actual.substring(0, diffSize) + ' ... Lines skipped';
196
+ }
197
+ if (expected.length > diffSize) {
198
+ expected = expected.substring(0, diffSize) + ' ... Lines skipped';
199
+ }
199
200
  return exports.inlineDiffs
200
201
  ? inlineDiff(actual, expected)
201
202
  : unifiedDiff(actual, expected);
@@ -242,10 +243,10 @@ exports.list = function(failures) {
242
243
  err = test.err;
243
244
  }
244
245
  var message;
245
- if (err.message && typeof err.message.toString === 'function') {
246
- message = err.message + '';
247
- } else if (typeof err.inspect === 'function') {
246
+ if (typeof err.inspect === 'function') {
248
247
  message = err.inspect() + '';
248
+ } else if (err.message && typeof err.message.toString === 'function') {
249
+ message = err.message + '';
249
250
  } else {
250
251
  message = '';
251
252
  }