mocha 8.3.1 → 9.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 CHANGED
@@ -1,3 +1,72 @@
1
+ # 9.0.1 / 2021-06-18
2
+
3
+ ## :nut_and_bolt: Other
4
+
5
+ - [#4657](https://github.com/mochajs/mocha/issues/4657): Browser: add separate bundle for modern browsers ([**@juergba**](https://github.com/juergba))
6
+
7
+ 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**.
8
+
9
+ - [#4653](https://github.com/mochajs/mocha/issues/4653): ESM: proper version check in `hasStableEsmImplementation` ([**@alexander-fenster**](https://github.com/alexander-fenster))
10
+
11
+ # 9.0.0 / 2021-06-07
12
+
13
+ ## :boom: Breaking Changes
14
+
15
+ - [#4633](https://github.com/mochajs/mocha/issues/4633): **Drop Node.js v10.x support** ([**@juergba**](https://github.com/juergba))
16
+
17
+ - [#4635](https://github.com/mochajs/mocha/issues/4635): `import`-first loading of test files ([**@giltayar**](https://github.com/giltayar))
18
+
19
+ **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.
20
+
21
+ - [#4636](https://github.com/mochajs/mocha/issues/4636): Remove deprecated `utils.lookupFiles()` ([**@juergba**](https://github.com/juergba))
22
+
23
+ - [#4638](https://github.com/mochajs/mocha/issues/4638): Limit the size of `actual`/`expected` for `diff` generation ([**@juergba**](https://github.com/juergba))
24
+
25
+ - [#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))
26
+
27
+ ## :tada: Enhancements
28
+
29
+ - [#4640](https://github.com/mochajs/mocha/issues/4640): Add new option `--dry-run` ([**@juergba**](https://github.com/juergba))
30
+
31
+ ## :bug: Fixes
32
+
33
+ - [#4128](https://github.com/mochajs/mocha/issues/4128): Fix: control stringification of error message ([**@syeutyu**](https://github.com/syeutyu))
34
+
35
+ ## :nut_and_bolt: Other
36
+
37
+ - [#4646](https://github.com/mochajs/mocha/issues/4646): Deprecate `Runner(suite: Suite, delay: boolean)` signature ([**@juergba**](https://github.com/juergba))
38
+ - [#4643](https://github.com/mochajs/mocha/issues/4643): Update production dependencies ([**@juergba**](https://github.com/juergba))
39
+
40
+ # 8.4.0 / 2021-05-07
41
+
42
+ ## :tada: Enhancements
43
+
44
+ - [#4502](https://github.com/mochajs/mocha/issues/4502): CLI file parsing errors now have error codes ([**@evaline-ju**](https://github.com/evaline-ju))
45
+
46
+ ## :bug: Fixes
47
+
48
+ - [#4614](https://github.com/mochajs/mocha/issues/4614): Watch: fix crash when reloading files ([**@outsideris**](https://github.com/outsideris))
49
+
50
+ ## :book: Documentation
51
+
52
+ - [#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))
53
+ - [#4617](https://github.com/mochajs/mocha/issues/4617): Dynamically generating tests with `top-level await` and ESM test files ([**@juergba**](https://github.com/juergba))
54
+ - [#4608](https://github.com/mochajs/mocha/issues/4608): Update default file extensions ([**@outsideris**](https://github.com/outsideris))
55
+
56
+ Also thanks to [**@outsideris**](https://github.com/outsideris) for various improvements on our GH actions workflows.
57
+
58
+ # 8.3.2 / 2021-03-12
59
+
60
+ ## :bug: Fixes
61
+
62
+ - [#4599](https://github.com/mochajs/mocha/issues/4599): Fix regression in `require` interface ([**@alexander-fenster**](https://github.com/alexander-fenster))
63
+
64
+ ## :book: Documentation
65
+
66
+ - [#4601](https://github.com/mochajs/mocha/issues/4601): Add build to GH actions run ([**@christian-bromann**](https://github.com/christian-bromann))
67
+ - [#4596](https://github.com/mochajs/mocha/issues/4596): Filter active sponsors/backers ([**@juergba**](https://github.com/juergba))
68
+ - [#4225](https://github.com/mochajs/mocha/issues/4225): Update config file examples ([**@pkuczynski**](https://github.com/pkuczynski))
69
+
1
70
  # 8.3.1 / 2021-03-06
2
71
 
3
72
  ## :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,58 @@ 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
+ ) {
54
+ return require(file);
55
+ } else {
56
+ throw err;
57
+ }
58
+ }
59
+ }
60
+ : implementationOfRequireOrImportForUnstableEsm;
61
+
62
+ function dealWithExports(module) {
63
+ if (module.default) {
64
+ return module.default;
65
+ } else {
66
+ return {...module, default: undefined};
67
+ }
68
+ }
69
+
70
+ exports.loadFilesAsync = async (files, preLoadFunc, postLoadFunc) => {
71
+ for (const file of files) {
72
+ preLoadFunc(file);
73
+ const result = await exports.requireOrImport(path.resolve(file));
74
+ postLoadFunc(file, result);
75
+ }
76
+ };
77
+
78
+ /* istanbul ignore next */
79
+ async function implementationOfRequireOrImportForUnstableEsm(file) {
34
80
  if (path.extname(file) === '.mjs') {
35
81
  return formattedImport(file);
36
82
  }
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.
83
+ // This is currently the only known way of figuring out whether a file is CJS or ESM in
84
+ // Node.js that doesn't necessitate calling `import` first.
41
85
  try {
42
86
  return require(file);
43
87
  } catch (err) {
@@ -47,12 +91,4 @@ exports.requireOrImport = async file => {
47
91
  throw err;
48
92
  }
49
93
  }
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
- };
94
+ }
@@ -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