mocha 8.0.1 → 8.1.3
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 +73 -2
- package/browser-entry.js +24 -7
- package/lib/browser/highlight-tags.js +39 -0
- package/lib/browser/parse-query.js +24 -0
- package/lib/browser/progress.js +4 -0
- package/lib/browser/template.html +7 -5
- package/lib/cli/cli.js +20 -9
- package/lib/cli/collect-files.js +3 -2
- package/lib/cli/index.js +0 -6
- package/lib/cli/lookup-files.js +151 -0
- package/lib/cli/node-flags.js +6 -7
- package/lib/cli/options.js +5 -4
- package/lib/cli/run-option-metadata.js +25 -2
- package/lib/cli/watch-run.js +11 -3
- package/lib/errors.js +2 -2
- package/lib/interfaces/common.js +5 -0
- package/lib/mocha.js +29 -17
- package/lib/nodejs/file-unloader.js +15 -0
- package/lib/nodejs/parallel-buffered-runner.js +2 -0
- package/lib/nodejs/serializer.js +3 -1
- package/lib/pending.js +4 -0
- package/lib/reporters/base.js +25 -12
- package/lib/runnable.js +1 -0
- package/lib/runner.js +38 -42
- package/lib/suite.js +1 -0
- package/lib/utils.js +33 -204
- package/mocha.js +25933 -18341
- package/mocha.js.map +1 -0
- package/package.json +68 -57
- package/lib/browser/tty.js +0 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,76 @@
|
|
|
1
|
+
# 8.1.3 / 2020-08-28
|
|
2
|
+
|
|
3
|
+
## :bug: Fixes
|
|
4
|
+
|
|
5
|
+
- [#4425](https://github.com/mochajs/mocha/issues/4425): Restore `Mocha.utils.lookupFiles()` and Webpack compatibility (both broken since v8.1.0); `Mocha.utils.lookupFiles()` is now **deprecated** and will be removed in the next major revision of Mocha; use `require('mocha/lib/cli').lookupFiles` instead ([**@boneskull**](https://github.com/boneskull))
|
|
6
|
+
|
|
7
|
+
# 8.1.2 / 2020-08-25
|
|
8
|
+
|
|
9
|
+
## :bug: Fixes
|
|
10
|
+
|
|
11
|
+
- [#4418](https://github.com/mochajs/mocha/issues/4418): Fix command-line flag incompatibility in forthcoming Node.js v14.9.0 ([**@boneskull**](https://github.com/boneskull))
|
|
12
|
+
- [#4401](https://github.com/mochajs/mocha/issues/4401): Fix missing global variable in browser ([**@irrationelle**](https://github.com/irrationelle))
|
|
13
|
+
|
|
14
|
+
## :lock: Security Fixes
|
|
15
|
+
|
|
16
|
+
- [#4396](https://github.com/mochajs/mocha/issues/4396): Update many dependencies ([**@GChuf**](https://github.com/GChuf))
|
|
17
|
+
|
|
18
|
+
## :book: Documentation
|
|
19
|
+
|
|
20
|
+
- Various fixes by [**@sujin-park**](https://github.com/sujin-park), [**@wwhurin**](https://github.com/wwhurin) & [**@Donghoon759**](https://github.com/Donghoon759)
|
|
21
|
+
|
|
22
|
+
# 8.1.1 / 2020-08-04
|
|
23
|
+
|
|
24
|
+
## :bug: Fixes
|
|
25
|
+
|
|
26
|
+
- [#4394](https://github.com/mochajs/mocha/issues/4394): Fix regression wherein certain reporters did not correctly detect terminal width ([**@boneskull**](https://github.com/boneskull))
|
|
27
|
+
|
|
28
|
+
# 8.1.0 / 2020-07-30
|
|
29
|
+
|
|
30
|
+
In this release, Mocha now builds its browser bundle with Rollup and Babel, which will provide the project's codebase more flexibility and consistency.
|
|
31
|
+
|
|
32
|
+
While we've been diligent about backwards compatibility, it's _possible_ consumers of the browser bundle will encounter differences (other than an increase in the bundle size). If you _do_ encounter an issue with the build, please [report it here](https://github.com/mochajs/mocha/issues/new?labels=unconfirmed-bug&template=bug_report.md&title=).
|
|
33
|
+
|
|
34
|
+
This release **does not** drop support for IE11.
|
|
35
|
+
|
|
36
|
+
Other community contributions came from [**@Devjeel**](https://github.com/Devjeel), [**@Harsha509**](https://github.com/Harsha509) and [**@sharath2106**](https://github.com/sharath2106). _Thank you_ to everyone who contributed to this release!
|
|
37
|
+
|
|
38
|
+
> Do you read Korean? See [this guide to running parallel tests in Mocha](https://blog.outsider.ne.kr/1489), translated by our maintainer, [**@outsideris**](https://github.com/outsideris).
|
|
39
|
+
|
|
40
|
+
## :tada: Enhancements
|
|
41
|
+
|
|
42
|
+
- [#4287](https://github.com/mochajs/mocha/issues/4287): Use background colors with inline diffs for better visual distinction ([**@michael-brade**](https://github.com/michael-brade))
|
|
43
|
+
|
|
44
|
+
## :bug: Fixes
|
|
45
|
+
|
|
46
|
+
- [#4328](https://github.com/mochajs/mocha/issues/4328): Fix "watch" mode when Mocha run in parallel ([**@boneskull**](https://github.com/boneskull))
|
|
47
|
+
- [#4382](https://github.com/mochajs/mocha/issues/4382): Fix root hook execution in "watch" mode ([**@indieisaconcept**](https://github.com/indieisaconcept))
|
|
48
|
+
- [#4383](https://github.com/mochajs/mocha/issues/4383): Consistent auto-generated hook titles ([**@cspotcode**](https://github.com/cspotcode))
|
|
49
|
+
- [#4359](https://github.com/mochajs/mocha/issues/4359): Better errors when running `mocha init` ([**@boneskull**](https://github.com/boneskull))
|
|
50
|
+
- [#4341](https://github.com/mochajs/mocha/issues/4341): Fix weirdness when using `delay` option in browser ([**@craigtaub**](https://github.com/craigtaub))
|
|
51
|
+
|
|
52
|
+
## :lock: Security Fixes
|
|
53
|
+
|
|
54
|
+
- [#4378](https://github.com/mochajs/mocha/issues/4378), [#4333](https://github.com/mochajs/mocha/issues/4333): Update [javascript-serialize](https://npm.im/javascript-serialize) ([**@martinoppitz**](https://github.com/martinoppitz), [**@wnghdcjfe**](https://github.com/wnghdcjfe))
|
|
55
|
+
- [#4354](https://github.com/mochajs/mocha/issues/4354): Update [yargs-unparser](https://npm.im/yargs-unparser) ([**@martinoppitz**](https://github.com/martinoppitz))
|
|
56
|
+
|
|
57
|
+
## :book: Documentation & Website
|
|
58
|
+
|
|
59
|
+
- [#4173](https://github.com/mochajs/mocha/issues/4173): Document how to use `--enable-source-maps` with Mocha ([**@bcoe**](https://github.com/bcoe))
|
|
60
|
+
- [#4343](https://github.com/mochajs/mocha/issues/4343): Clean up some API docs ([**@craigtaub**](https://github.com/craigtaub))
|
|
61
|
+
- [#4318](https://github.com/mochajs/mocha/issues/4318): Sponsor images are now self-hosted ([**@Munter**](https://github.com/Munter))
|
|
62
|
+
|
|
63
|
+
## :nut_and_bolt: Other
|
|
64
|
+
|
|
65
|
+
- [#4293](https://github.com/mochajs/mocha/issues/4293): Use Rollup and Babel in build pipeline; add source map to published files ([**@Munter**](https://github.com/Munter))
|
|
66
|
+
|
|
1
67
|
# 8.0.1 / 2020-06-10
|
|
2
68
|
|
|
3
69
|
The obligatory patch after a major.
|
|
4
70
|
|
|
5
71
|
## :bug: Fixes
|
|
6
72
|
|
|
7
|
-
- [#4328]
|
|
73
|
+
- [#4328](https://github.com/mochajs/mocha/issues/4328): Fix `--parallel` when combined with `--watch` ([**@boneskull**](https://github.com/boneskull))
|
|
8
74
|
|
|
9
75
|
# 8.0.0 / 2020-06-10
|
|
10
76
|
|
|
@@ -14,7 +80,7 @@ Let's welcome [**@giltayar**](https://github.com/giltayar) and [**@nicojs**](htt
|
|
|
14
80
|
|
|
15
81
|
## :boom: Breaking Changes
|
|
16
82
|
|
|
17
|
-
- [#4164](https://github.com/mochajs/mocha/issues/4164): **Mocha v8.0.0 now requires Node.js v10.
|
|
83
|
+
- [#4164](https://github.com/mochajs/mocha/issues/4164): **Mocha v8.0.0 now requires Node.js v10.12.0 or newer.** Mocha no longer supports the Node.js v8.x line ("Carbon"), which entered End-of-Life at the end of 2019 ([**@UlisesGascon**](https://github.com/UlisesGascon))
|
|
18
84
|
|
|
19
85
|
- [#4175](https://github.com/mochajs/mocha/issues/4175): Having been deprecated with a warning since v7.0.0, **`mocha.opts` is no longer supported** ([**@juergba**](https://github.com/juergba))
|
|
20
86
|
|
|
@@ -35,6 +101,7 @@ Let's welcome [**@giltayar**](https://github.com/giltayar) and [**@nicojs**](htt
|
|
|
35
101
|
- [#4223](https://github.com/mochajs/mocha/issues/4223): The context object's `skip()` (`this.skip()`) in a "before all" (`before()`) hook will no longer execute subsequent sibling hooks, in addition to hooks in child suites ([**@juergba**](https://github.com/juergba))
|
|
36
102
|
|
|
37
103
|
- [#4178](https://github.com/mochajs/mocha/issues/4178): Remove previously soft-deprecated APIs ([**@wnghdcjfe**](https://github.com/wnghdcjfe)):
|
|
104
|
+
|
|
38
105
|
- `Mocha.prototype.ignoreLeaks()`
|
|
39
106
|
- `Mocha.prototype.useColors()`
|
|
40
107
|
- `Mocha.prototype.useInlineDiffs()`
|
|
@@ -54,6 +121,10 @@ Let's welcome [**@giltayar**](https://github.com/giltayar) and [**@nicojs**](htt
|
|
|
54
121
|
|
|
55
122
|
- [#4246](https://github.com/mochajs/mocha/issues/4246): Add documentation for parallel mode and Root Hook plugins ([**@boneskull**](https://github.com/boneskull))
|
|
56
123
|
|
|
124
|
+
## :nut_and_bolt: Other
|
|
125
|
+
|
|
126
|
+
- [#4200](https://github.com/mochajs/mocha/issues/4200): Drop mkdirp and replace it with fs.mkdirSync ([**@HyunSangHan**](https://github.com/HyunSangHan))
|
|
127
|
+
|
|
57
128
|
## :bug: Fixes
|
|
58
129
|
|
|
59
130
|
(All bug fixes in Mocha v8.0.0 are also breaking changes, and are listed above)
|
package/browser-entry.js
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
process.stdout = require('browser-stdout')({label: false});
|
|
11
11
|
|
|
12
|
+
var parseQuery = require('./lib/browser/parse-query');
|
|
13
|
+
var highlightTags = require('./lib/browser/highlight-tags');
|
|
12
14
|
var Mocha = require('./lib/mocha');
|
|
13
15
|
|
|
14
16
|
/**
|
|
@@ -77,6 +79,13 @@ process.on = function(e, fn) {
|
|
|
77
79
|
}
|
|
78
80
|
};
|
|
79
81
|
|
|
82
|
+
process.listeners = function(e) {
|
|
83
|
+
if (e === 'uncaughtException') {
|
|
84
|
+
return uncaughtExceptionHandlers;
|
|
85
|
+
}
|
|
86
|
+
return [];
|
|
87
|
+
};
|
|
88
|
+
|
|
80
89
|
// The BDD UI is registered by default, but no UI will be functional in the
|
|
81
90
|
// browser without an explicit call to the overridden `mocha.ui` (see below).
|
|
82
91
|
// Ensure that this default UI does not expose its methods to the global scope.
|
|
@@ -139,11 +148,19 @@ mocha.setup = function(opts) {
|
|
|
139
148
|
if (typeof opts === 'string') {
|
|
140
149
|
opts = {ui: opts};
|
|
141
150
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
this[opt](opts[opt]);
|
|
145
|
-
}
|
|
151
|
+
if (opts.delay === true) {
|
|
152
|
+
this.delay();
|
|
146
153
|
}
|
|
154
|
+
var self = this;
|
|
155
|
+
Object.keys(opts)
|
|
156
|
+
.filter(function(opt) {
|
|
157
|
+
return opt !== 'delay';
|
|
158
|
+
})
|
|
159
|
+
.forEach(function(opt) {
|
|
160
|
+
if (Object.prototype.hasOwnProperty.call(opts, opt)) {
|
|
161
|
+
self[opt](opts[opt]);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
147
164
|
return this;
|
|
148
165
|
};
|
|
149
166
|
|
|
@@ -155,7 +172,7 @@ mocha.run = function(fn) {
|
|
|
155
172
|
var options = mocha.options;
|
|
156
173
|
mocha.globals('location');
|
|
157
174
|
|
|
158
|
-
var query =
|
|
175
|
+
var query = parseQuery(global.location.search || '');
|
|
159
176
|
if (query.grep) {
|
|
160
177
|
mocha.grep(query.grep);
|
|
161
178
|
}
|
|
@@ -174,7 +191,7 @@ mocha.run = function(fn) {
|
|
|
174
191
|
document.getElementById('mocha') &&
|
|
175
192
|
options.noHighlighting !== true
|
|
176
193
|
) {
|
|
177
|
-
|
|
194
|
+
highlightTags('code');
|
|
178
195
|
}
|
|
179
196
|
if (fn) {
|
|
180
197
|
fn(err);
|
|
@@ -199,4 +216,4 @@ global.mocha = mocha;
|
|
|
199
216
|
// this allows test/acceptance/required-tokens.js to pass; thus,
|
|
200
217
|
// you can now do `const describe = require('mocha').describe` in a
|
|
201
218
|
// browser context (assuming browserification). should fix #880
|
|
202
|
-
module.exports = global;
|
|
219
|
+
module.exports = Object.assign(mocha, global);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Highlight the given string of `js`.
|
|
5
|
+
*
|
|
6
|
+
* @private
|
|
7
|
+
* @param {string} js
|
|
8
|
+
* @return {string}
|
|
9
|
+
*/
|
|
10
|
+
function highlight(js) {
|
|
11
|
+
return js
|
|
12
|
+
.replace(/</g, '<')
|
|
13
|
+
.replace(/>/g, '>')
|
|
14
|
+
.replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>')
|
|
15
|
+
.replace(/('.*?')/gm, '<span class="string">$1</span>')
|
|
16
|
+
.replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
|
|
17
|
+
.replace(/(\d+)/gm, '<span class="number">$1</span>')
|
|
18
|
+
.replace(
|
|
19
|
+
/\bnew[ \t]+(\w+)/gm,
|
|
20
|
+
'<span class="keyword">new</span> <span class="init">$1</span>'
|
|
21
|
+
)
|
|
22
|
+
.replace(
|
|
23
|
+
/\b(function|new|throw|return|var|if|else)\b/gm,
|
|
24
|
+
'<span class="keyword">$1</span>'
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Highlight the contents of tag `name`.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {string} name
|
|
33
|
+
*/
|
|
34
|
+
module.exports = function highlightTags(name) {
|
|
35
|
+
var code = document.getElementById('mocha').getElementsByTagName(name);
|
|
36
|
+
for (var i = 0, len = code.length; i < len; ++i) {
|
|
37
|
+
code[i].innerHTML = highlight(code[i].innerHTML);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parse the given `qs`.
|
|
5
|
+
*
|
|
6
|
+
* @private
|
|
7
|
+
* @param {string} qs
|
|
8
|
+
* @return {Object<string, string>}
|
|
9
|
+
*/
|
|
10
|
+
module.exports = function parseQuery(qs) {
|
|
11
|
+
return qs
|
|
12
|
+
.replace('?', '')
|
|
13
|
+
.split('&')
|
|
14
|
+
.reduce(function(obj, pair) {
|
|
15
|
+
var i = pair.indexOf('=');
|
|
16
|
+
var key = pair.slice(0, i);
|
|
17
|
+
var val = pair.slice(++i);
|
|
18
|
+
|
|
19
|
+
// Due to how the URLSearchParams API treats spaces
|
|
20
|
+
obj[key] = decodeURIComponent(val.replace(/\+/g, '%20'));
|
|
21
|
+
|
|
22
|
+
return obj;
|
|
23
|
+
}, {});
|
|
24
|
+
};
|
package/lib/browser/progress.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
3
|
<head>
|
|
4
|
-
<meta charset="utf-8"
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
5
|
<title>Mocha</title>
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0"
|
|
7
|
-
<link rel="stylesheet" href="mocha.css"
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<link rel="stylesheet" href="mocha.css" />
|
|
8
8
|
</head>
|
|
9
9
|
<body>
|
|
10
10
|
<div id="mocha"></div>
|
|
11
11
|
<script src="mocha.js"></script>
|
|
12
|
-
<script>
|
|
13
|
-
|
|
12
|
+
<script>
|
|
13
|
+
mocha.setup('bdd');
|
|
14
|
+
</script>
|
|
15
|
+
<script src="tests.spec.js"></script>
|
|
14
16
|
<script>
|
|
15
17
|
mocha.run();
|
|
16
18
|
</script>
|
package/lib/cli/cli.js
CHANGED
|
@@ -3,19 +3,24 @@
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* Option parsing is handled by {@link https://npm.im/yargs yargs}.
|
|
8
|
-
* If executed via `node`, this module will run {@linkcode module:lib/cli
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
11
|
-
* @module
|
|
6
|
+
* Contains CLI entry point and public API for programmatic usage in Node.js.
|
|
7
|
+
* - Option parsing is handled by {@link https://npm.im/yargs yargs}.
|
|
8
|
+
* - If executed via `node`, this module will run {@linkcode module:lib/cli.main main()}.
|
|
9
|
+
* @public
|
|
10
|
+
* @module lib/cli
|
|
12
11
|
*/
|
|
13
12
|
|
|
14
13
|
const debug = require('debug')('mocha:cli:cli');
|
|
15
14
|
const symbols = require('log-symbols');
|
|
16
15
|
const yargs = require('yargs/yargs');
|
|
17
16
|
const path = require('path');
|
|
18
|
-
const {
|
|
17
|
+
const {
|
|
18
|
+
loadRc,
|
|
19
|
+
loadPkgRc,
|
|
20
|
+
loadOptions,
|
|
21
|
+
YARGS_PARSER_CONFIG
|
|
22
|
+
} = require('./options');
|
|
23
|
+
const lookupFiles = require('./lookup-files');
|
|
19
24
|
const commands = require('./commands');
|
|
20
25
|
const ansi = require('ansi-colors');
|
|
21
26
|
const {repository, homepage, version, gitter} = require('../../package.json');
|
|
@@ -25,7 +30,8 @@ const {cwd} = require('../utils');
|
|
|
25
30
|
* - Accepts an `Array` of arguments
|
|
26
31
|
* - Modifies {@link https://nodejs.org/api/modules.html#modules_module_paths Node.js' search path} for easy loading of consumer modules
|
|
27
32
|
* - Sets {@linkcode https://nodejs.org/api/errors.html#errors_error_stacktracelimit Error.stackTraceLimit} to `Infinity`
|
|
28
|
-
* @
|
|
33
|
+
* @public
|
|
34
|
+
* @summary Mocha's main command-line entry-point.
|
|
29
35
|
* @param {string[]} argv - Array of arguments to parse, or by default the lovely `process.argv.slice(2)`
|
|
30
36
|
*/
|
|
31
37
|
exports.main = (argv = process.argv.slice(2)) => {
|
|
@@ -52,7 +58,7 @@ exports.main = (argv = process.argv.slice(2)) => {
|
|
|
52
58
|
debug('caught error sometime before command handler: %O', err);
|
|
53
59
|
yargs.showHelp();
|
|
54
60
|
console.error(`\n${symbols.error} ${ansi.red('ERROR:')} ${msg}`);
|
|
55
|
-
|
|
61
|
+
process.exitCode = 1;
|
|
56
62
|
})
|
|
57
63
|
.help('help', 'Show usage information & exit')
|
|
58
64
|
.alias('help', 'h')
|
|
@@ -71,6 +77,11 @@ exports.main = (argv = process.argv.slice(2)) => {
|
|
|
71
77
|
.parse(args._);
|
|
72
78
|
};
|
|
73
79
|
|
|
80
|
+
exports.lookupFiles = lookupFiles;
|
|
81
|
+
exports.loadOptions = loadOptions;
|
|
82
|
+
exports.loadPkgRc = loadPkgRc;
|
|
83
|
+
exports.loadRc = loadRc;
|
|
84
|
+
|
|
74
85
|
// allow direct execution
|
|
75
86
|
if (require.main === module) {
|
|
76
87
|
exports.main();
|
package/lib/cli/collect-files.js
CHANGED
|
@@ -4,8 +4,8 @@ const path = require('path');
|
|
|
4
4
|
const ansi = require('ansi-colors');
|
|
5
5
|
const debug = require('debug')('mocha:cli:run:helpers');
|
|
6
6
|
const minimatch = require('minimatch');
|
|
7
|
-
const utils = require('../utils');
|
|
8
7
|
const {NO_FILES_MATCH_PATTERN} = require('../errors').constants;
|
|
8
|
+
const lookupFiles = require('./lookup-files');
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Exports a function that collects test files from CLI parameters.
|
|
@@ -27,7 +27,7 @@ module.exports = ({ignore, extension, file, recursive, sort, spec} = {}) => {
|
|
|
27
27
|
spec.forEach(arg => {
|
|
28
28
|
let newFiles;
|
|
29
29
|
try {
|
|
30
|
-
newFiles =
|
|
30
|
+
newFiles = lookupFiles(arg, extension, recursive);
|
|
31
31
|
} catch (err) {
|
|
32
32
|
if (err.code === NO_FILES_MATCH_PATTERN) {
|
|
33
33
|
unmatched.push({message: err.message, pattern: err.pattern});
|
|
@@ -81,6 +81,7 @@ module.exports = ({ignore, extension, file, recursive, sort, spec} = {}) => {
|
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
83
|
* An object to configure how Mocha gathers test files
|
|
84
|
+
* @private
|
|
84
85
|
* @typedef {Object} FileCollectionOptions
|
|
85
86
|
* @property {string[]} extension - File extensions to use
|
|
86
87
|
* @property {string[]} spec - Files, dirs, globs to run
|
package/lib/cli/index.js
CHANGED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Contains `lookupFiles`, which takes some globs/dirs/options and returns a list of files.
|
|
5
|
+
* @module
|
|
6
|
+
* @private
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
var fs = require('fs');
|
|
10
|
+
var path = require('path');
|
|
11
|
+
var glob = require('glob');
|
|
12
|
+
var {format} = require('util');
|
|
13
|
+
var errors = require('../errors');
|
|
14
|
+
var createNoFilesMatchPatternError = errors.createNoFilesMatchPatternError;
|
|
15
|
+
var createMissingArgumentError = errors.createMissingArgumentError;
|
|
16
|
+
var {sQuote, dQuote} = require('../utils');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Determines if pathname would be a "hidden" file (or directory) on UN*X.
|
|
20
|
+
*
|
|
21
|
+
* @description
|
|
22
|
+
* On UN*X, pathnames beginning with a full stop (aka dot) are hidden during
|
|
23
|
+
* typical usage. Dotfiles, plain-text configuration files, are prime examples.
|
|
24
|
+
*
|
|
25
|
+
* @see {@link http://xahlee.info/UnixResource_dir/writ/unix_origin_of_dot_filename.html|Origin of Dot File Names}
|
|
26
|
+
*
|
|
27
|
+
* @private
|
|
28
|
+
* @param {string} pathname - Pathname to check for match.
|
|
29
|
+
* @return {boolean} whether pathname would be considered a hidden file.
|
|
30
|
+
* @example
|
|
31
|
+
* isHiddenOnUnix('.profile'); // => true
|
|
32
|
+
*/
|
|
33
|
+
function isHiddenOnUnix(pathname) {
|
|
34
|
+
return path.basename(pathname)[0] === '.';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Determines if pathname has a matching file extension.
|
|
39
|
+
*
|
|
40
|
+
* @private
|
|
41
|
+
* @param {string} pathname - Pathname to check for match.
|
|
42
|
+
* @param {string[]} exts - List of file extensions (sans period).
|
|
43
|
+
* @return {boolean} whether file extension matches.
|
|
44
|
+
* @example
|
|
45
|
+
* hasMatchingExtname('foo.html', ['js', 'css']); // => false
|
|
46
|
+
*/
|
|
47
|
+
function hasMatchingExtname(pathname, exts) {
|
|
48
|
+
var suffix = path.extname(pathname).slice(1);
|
|
49
|
+
return exts.some(function(element) {
|
|
50
|
+
return suffix === element;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Lookup file names at the given `path`.
|
|
56
|
+
*
|
|
57
|
+
* @description
|
|
58
|
+
* Filenames are returned in _traversal_ order by the OS/filesystem.
|
|
59
|
+
* **Make no assumption that the names will be sorted in any fashion.**
|
|
60
|
+
*
|
|
61
|
+
* @public
|
|
62
|
+
* @alias module:lib/cli.lookupFiles
|
|
63
|
+
* @param {string} filepath - Base path to start searching from.
|
|
64
|
+
* @param {string[]} [extensions=[]] - File extensions to look for.
|
|
65
|
+
* @param {boolean} [recursive=false] - Whether to recurse into subdirectories.
|
|
66
|
+
* @return {string[]} An array of paths.
|
|
67
|
+
* @throws {Error} if no files match pattern.
|
|
68
|
+
* @throws {TypeError} if `filepath` is directory and `extensions` not provided.
|
|
69
|
+
*/
|
|
70
|
+
module.exports = function lookupFiles(filepath, extensions, recursive) {
|
|
71
|
+
extensions = extensions || [];
|
|
72
|
+
recursive = recursive || false;
|
|
73
|
+
var files = [];
|
|
74
|
+
var stat;
|
|
75
|
+
|
|
76
|
+
if (!fs.existsSync(filepath)) {
|
|
77
|
+
var pattern;
|
|
78
|
+
if (glob.hasMagic(filepath)) {
|
|
79
|
+
// Handle glob as is without extensions
|
|
80
|
+
pattern = filepath;
|
|
81
|
+
} else {
|
|
82
|
+
// glob pattern e.g. 'filepath+(.js|.ts)'
|
|
83
|
+
var strExtensions = extensions
|
|
84
|
+
.map(function(v) {
|
|
85
|
+
return '.' + v;
|
|
86
|
+
})
|
|
87
|
+
.join('|');
|
|
88
|
+
pattern = filepath + '+(' + strExtensions + ')';
|
|
89
|
+
}
|
|
90
|
+
files = glob.sync(pattern, {nodir: true});
|
|
91
|
+
if (!files.length) {
|
|
92
|
+
throw createNoFilesMatchPatternError(
|
|
93
|
+
'Cannot find any files matching pattern ' + dQuote(filepath),
|
|
94
|
+
filepath
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
return files;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Handle file
|
|
101
|
+
try {
|
|
102
|
+
stat = fs.statSync(filepath);
|
|
103
|
+
if (stat.isFile()) {
|
|
104
|
+
return filepath;
|
|
105
|
+
}
|
|
106
|
+
} catch (err) {
|
|
107
|
+
// ignore error
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Handle directory
|
|
112
|
+
fs.readdirSync(filepath).forEach(function(dirent) {
|
|
113
|
+
var pathname = path.join(filepath, dirent);
|
|
114
|
+
var stat;
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
stat = fs.statSync(pathname);
|
|
118
|
+
if (stat.isDirectory()) {
|
|
119
|
+
if (recursive) {
|
|
120
|
+
files = files.concat(lookupFiles(pathname, extensions, recursive));
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
} catch (err) {
|
|
125
|
+
// ignore error
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (!extensions.length) {
|
|
129
|
+
throw createMissingArgumentError(
|
|
130
|
+
format(
|
|
131
|
+
'Argument %s required when argument %s is a directory',
|
|
132
|
+
sQuote('extensions'),
|
|
133
|
+
sQuote('filepath')
|
|
134
|
+
),
|
|
135
|
+
'extensions',
|
|
136
|
+
'array'
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (
|
|
141
|
+
!stat.isFile() ||
|
|
142
|
+
!hasMatchingExtname(pathname, extensions) ||
|
|
143
|
+
isHiddenOnUnix(pathname)
|
|
144
|
+
) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
files.push(pathname);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
return files;
|
|
151
|
+
};
|
package/lib/cli/node-flags.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
const nodeFlags = process.allowedNodeEnvironmentFlags;
|
|
10
|
+
const {isMochaFlag} = require('./run-option-metadata');
|
|
10
11
|
const unparse = require('yargs-unparser');
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -43,16 +44,14 @@ exports.isNodeFlag = (flag, bareword = true) => {
|
|
|
43
44
|
flag = flag.replace(/^--?/, '');
|
|
44
45
|
}
|
|
45
46
|
return (
|
|
46
|
-
// treat --require/-r as Mocha flag even though it's also a node flag
|
|
47
|
-
!(flag === 'require' || flag === 'r') &&
|
|
48
47
|
// check actual node flags from `process.allowedNodeEnvironmentFlags`,
|
|
49
48
|
// then historical support for various V8 and non-`NODE_OPTIONS` flags
|
|
50
49
|
// and also any V8 flags with `--v8-` prefix
|
|
51
|
-
((nodeFlags && nodeFlags.has(flag)) ||
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
(!isMochaFlag(flag) && nodeFlags && nodeFlags.has(flag)) ||
|
|
51
|
+
debugFlags.has(flag) ||
|
|
52
|
+
/(?:preserve-symlinks(?:-main)?|harmony(?:[_-]|$)|(?:trace[_-].+$)|gc(?:[_-]global)?$|es[_-]staging$|use[_-]strict$|v8[_-](?!options).+?$)/.test(
|
|
53
|
+
flag
|
|
54
|
+
)
|
|
56
55
|
);
|
|
57
56
|
};
|
|
58
57
|
|
package/lib/cli/options.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Main entry point for handling filesystem-based configuration,
|
|
5
5
|
* whether that's a config file or `package.json` or whatever.
|
|
6
|
-
* @module
|
|
6
|
+
* @module lib/cli/options
|
|
7
|
+
* @private
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
const fs = require('fs');
|
|
@@ -150,7 +151,7 @@ const parse = (args = [], defaultValues = {}, ...configObjects) => {
|
|
|
150
151
|
* @param {Object} [args] - Arguments object
|
|
151
152
|
* @param {string|boolean} [args.config] - Path to config file or `false` to skip
|
|
152
153
|
* @public
|
|
153
|
-
* @
|
|
154
|
+
* @alias module:lib/cli.loadRc
|
|
154
155
|
* @returns {external:yargsParser.Arguments|void} Parsed config, or nothing if `args.config` is `false`
|
|
155
156
|
*/
|
|
156
157
|
const loadRc = (args = {}) => {
|
|
@@ -167,7 +168,7 @@ module.exports.loadRc = loadRc;
|
|
|
167
168
|
* @param {Object} [args] - Arguments object
|
|
168
169
|
* @param {string|boolean} [args.config] - Path to `package.json` or `false` to skip
|
|
169
170
|
* @public
|
|
170
|
-
* @
|
|
171
|
+
* @alias module:lib/cli.loadPkgRc
|
|
171
172
|
* @returns {external:yargsParser.Arguments|void} Parsed config, or nothing if `args.package` is `false`
|
|
172
173
|
*/
|
|
173
174
|
const loadPkgRc = (args = {}) => {
|
|
@@ -210,7 +211,7 @@ module.exports.loadPkgRc = loadPkgRc;
|
|
|
210
211
|
* @summary Parses options read from `.mocharc.*` and `package.json`.
|
|
211
212
|
* @param {string|string[]} [argv] - Arguments to parse
|
|
212
213
|
* @public
|
|
213
|
-
* @
|
|
214
|
+
* @alias module:lib/cli.loadOptions
|
|
214
215
|
* @returns {external:yargsParser.Arguments} Parsed args from everything
|
|
215
216
|
*/
|
|
216
217
|
const loadOptions = (argv = []) => {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* @type {{string:string[]}}
|
|
13
13
|
* @private
|
|
14
14
|
*/
|
|
15
|
-
exports.types = {
|
|
15
|
+
const TYPES = (exports.types = {
|
|
16
16
|
array: [
|
|
17
17
|
'extension',
|
|
18
18
|
'file',
|
|
@@ -58,7 +58,7 @@ exports.types = {
|
|
|
58
58
|
'slow',
|
|
59
59
|
'timeout'
|
|
60
60
|
]
|
|
61
|
-
};
|
|
61
|
+
});
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* Option aliases keyed by canonical option name.
|
|
@@ -88,3 +88,26 @@ exports.aliases = {
|
|
|
88
88
|
ui: ['u'],
|
|
89
89
|
watch: ['w']
|
|
90
90
|
};
|
|
91
|
+
|
|
92
|
+
const ALL_MOCHA_FLAGS = Object.keys(TYPES).reduce((acc, key) => {
|
|
93
|
+
// gets all flags from each of the fields in `types`, adds those,
|
|
94
|
+
// then adds aliases of each flag (if any)
|
|
95
|
+
TYPES[key].forEach(flag => {
|
|
96
|
+
acc.add(flag);
|
|
97
|
+
const aliases = exports.aliases[flag] || [];
|
|
98
|
+
aliases.forEach(alias => {
|
|
99
|
+
acc.add(alias);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
return acc;
|
|
103
|
+
}, new Set());
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Returns `true` if the provided `flag` is known to Mocha.
|
|
107
|
+
* @param {string} flag - Flag to check
|
|
108
|
+
* @returns {boolean} If `true`, this is a Mocha flag
|
|
109
|
+
* @private
|
|
110
|
+
*/
|
|
111
|
+
exports.isMochaFlag = flag => {
|
|
112
|
+
return ALL_MOCHA_FLAGS.has(flag.replace(/^--?/, ''));
|
|
113
|
+
};
|