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 +69 -0
- package/README.md +12 -58
- package/lib/cli/config.js +5 -1
- package/lib/cli/lookup-files.js +2 -8
- package/lib/cli/options.js +5 -1
- package/lib/cli/run-option-metadata.js +1 -0
- package/lib/cli/run.js +4 -0
- package/lib/cli/watch-run.js +15 -11
- package/lib/errors.js +23 -1
- package/lib/esm-utils.js +50 -14
- package/lib/interfaces/bdd.js +0 -7
- package/lib/interfaces/common.js +0 -9
- package/lib/interfaces/qunit.js +0 -1
- package/lib/interfaces/tdd.js +0 -1
- package/lib/mocha.js +50 -32
- package/lib/reporters/base.js +14 -13
- package/lib/runner.js +16 -14
- package/lib/utils.js +0 -68
- package/mocha-es2018.js +19698 -0
- package/mocha.js +4256 -4017
- package/mocha.js.map +1 -1
- package/package.json +13 -8
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#
|
|
13
|
-
<a href="https://github.com/mochajs/mocha#
|
|
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
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
[](https://opencollective.com/mochajs/backer/1/website)
|
|
39
|
-
[](https://opencollective.com/mochajs/backer/2/website)
|
|
40
|
-
[](https://opencollective.com/mochajs/backer/3/website)
|
|
41
|
-
[](https://opencollective.com/mochajs/backer/4/website)
|
|
42
|
-
[](https://opencollective.com/mochajs/backer/5/website)
|
|
43
|
-
[](https://opencollective.com/mochajs/backer/6/website)
|
|
44
|
-
[](https://opencollective.com/mochajs/backer/7/website)
|
|
45
|
-
[](https://opencollective.com/mochajs/backer/8/website)
|
|
46
|
-
[](https://opencollective.com/mochajs/backer/9/website)
|
|
47
|
-
[](https://opencollective.com/mochajs/backer/10/website)
|
|
48
|
-
[](https://opencollective.com/mochajs/backer/11/website)
|
|
49
|
-
[](https://opencollective.com/mochajs/backer/12/website)
|
|
50
|
-
[](https://opencollective.com/mochajs/backer/13/website)
|
|
51
|
-
[](https://opencollective.com/mochajs/backer/14/website)
|
|
52
|
-
[](https://opencollective.com/mochajs/backer/15/website)
|
|
53
|
-
[](https://opencollective.com/mochajs/backer/16/website)
|
|
54
|
-
[](https://opencollective.com/mochajs/backer/17/website)
|
|
55
|
-
[](https://opencollective.com/mochajs/backer/18/website)
|
|
56
|
-
[](https://opencollective.com/mochajs/backer/19/website)
|
|
57
|
-
[](https://opencollective.com/mochajs/backer/20/website)
|
|
58
|
-
[](https://opencollective.com/mochajs/backer/21/website)
|
|
59
|
-
[](https://opencollective.com/mochajs/backer/22/website)
|
|
60
|
-
[](https://opencollective.com/mochajs/backer/23/website)
|
|
61
|
-
[](https://opencollective.com/mochajs/backer/24/website)
|
|
62
|
-
[](https://opencollective.com/mochajs/backer/25/website)
|
|
63
|
-
[](https://opencollective.com/mochajs/backer/26/website)
|
|
64
|
-
[](https://opencollective.com/mochajs/backer/27/website)
|
|
65
|
-
[](https://opencollective.com/mochajs/backer/28/website)
|
|
66
|
-
[](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
|
|
71
|
-
|
|
72
|
-
[](https://opencollective.com/mochajs/sponsor/4/website)
|
|
77
|
-
[](https://opencollective.com/mochajs/sponsor/5/website)
|
|
78
|
-
[](https://opencollective.com/mochajs/sponsor/6/website)
|
|
79
|
-
[](https://opencollective.com/mochajs/sponsor/7/website)
|
|
80
|
-
[](https://opencollective.com/mochajs/sponsor/8/website)
|
|
81
|
-
[](https://opencollective.com/mochajs/sponsor/9/website)
|
|
82
|
-
[](https://opencollective.com/mochajs/sponsor/10/website)
|
|
83
|
-
[](https://opencollective.com/mochajs/sponsor/11/website)
|
|
84
|
-
[](https://opencollective.com/mochajs/sponsor/12/website)
|
|
85
|
-
[](https://opencollective.com/mochajs/sponsor/13/website)
|
|
86
|
-
[](https://opencollective.com/mochajs/sponsor/14/website)
|
|
87
|
-
[](https://opencollective.com/mochajs/sponsor/15/website)
|
|
88
|
-
[](https://opencollective.com/mochajs/sponsor/16/website)
|
|
89
|
-
[](https://opencollective.com/mochajs/sponsor/17/website)
|
|
90
|
-
[](https://opencollective.com/mochajs/sponsor/18/website)
|
|
91
|
-
[](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
|
+
[](https://opencollective.com/mochajs/tiers/sponsors/0/website)
|
|
43
|
+
[](https://opencollective.com/mochajs/tiers/sponsors/1/website)
|
|
44
|
+
[](https://opencollective.com/mochajs/tiers/sponsors/2/website)
|
|
45
|
+
[](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_
|
|
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
|
|
85
|
+
throw createUnparsableFileError(
|
|
86
|
+
`Unable to read/parse ${filepath}: ${err}`,
|
|
87
|
+
filepath
|
|
88
|
+
);
|
|
85
89
|
}
|
|
86
90
|
return config;
|
|
87
91
|
};
|
package/lib/cli/lookup-files.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
);
|
package/lib/cli/options.js
CHANGED
|
@@ -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
|
|
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
|
}
|
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
|
package/lib/cli/watch-run.js
CHANGED
|
@@ -261,17 +261,21 @@ const createRerunner = (mocha, watcher, {beforeRun} = {}) => {
|
|
|
261
261
|
let rerunScheduled = false;
|
|
262
262
|
|
|
263
263
|
const run = () => {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
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
|
+
}
|
package/lib/interfaces/bdd.js
CHANGED
|
@@ -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
|
|
package/lib/interfaces/common.js
CHANGED
|
@@ -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
|
};
|
package/lib/interfaces/qunit.js
CHANGED