mocha 8.0.1 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -2
- package/browser-entry.js +26 -9
- 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 +1 -1
- package/lib/cli/collect-files.js +3 -2
- package/lib/cli/lookup-files.js +145 -0
- 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 +12 -3
- package/lib/nodejs/parallel-buffered-runner.js +2 -0
- package/lib/nodejs/serializer.js +2 -0
- package/lib/pending.js +4 -0
- package/lib/reporters/base.js +24 -11
- package/lib/runnable.js +1 -0
- package/lib/runner.js +37 -41
- package/lib/suite.js +1 -0
- package/lib/utils.js +1 -201
- package/mocha.js +25866 -18341
- package/mocha.js.map +1 -0
- package/package.json +24 -20
- package/lib/browser/tty.js +0 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,49 @@
|
|
|
1
|
+
# 8.1.0 / 2020-07-30
|
|
2
|
+
|
|
3
|
+
In this release, Mocha now builds its browser bundle with Rollup and Babel, which will provide the project's codebase more flexibility and consistency.
|
|
4
|
+
|
|
5
|
+
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=).
|
|
6
|
+
|
|
7
|
+
This release **does not** drop support for IE11.
|
|
8
|
+
|
|
9
|
+
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!
|
|
10
|
+
|
|
11
|
+
> 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).
|
|
12
|
+
|
|
13
|
+
## :tada: Enhancements
|
|
14
|
+
|
|
15
|
+
- [#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))
|
|
16
|
+
|
|
17
|
+
## :bug: Fixes
|
|
18
|
+
|
|
19
|
+
- [#4328](https://github.com/mochajs/mocha/issues/4328): Fix "watch" mode when Mocha run in parallel ([**@boneskull**](https://github.com/boneskull))
|
|
20
|
+
- [#4382](https://github.com/mochajs/mocha/issues/4382): Fix root hook execution in "watch" mode ([**@indieisaconcept**](https://github.com/indieisaconcept))
|
|
21
|
+
- [#4383](https://github.com/mochajs/mocha/issues/4383): Consistent auto-generated hook titles ([**@cspotcode**](https://github.com/cspotcode))
|
|
22
|
+
- [#4359](https://github.com/mochajs/mocha/issues/4359): Better errors when running `mocha init` ([**@boneskull**](https://github.com/boneskull))
|
|
23
|
+
- [#4341](https://github.com/mochajs/mocha/issues/4341): Fix weirdness when using `delay` option in browser ([**@craigtaub**](https://github.com/craigtaub))
|
|
24
|
+
|
|
25
|
+
## :lock: Security Fixes
|
|
26
|
+
|
|
27
|
+
- [#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))
|
|
28
|
+
- [#4354](https://github.com/mochajs/mocha/issues/4354): Update [yargs-unparser](https://npm.im/yargs-unparser) ([**@martinoppitz**](https://github.com/martinoppitz))
|
|
29
|
+
|
|
30
|
+
## :book: Documentation & Website
|
|
31
|
+
|
|
32
|
+
- [#4173](https://github.com/mochajs/mocha/issues/4173): Document how to use `--enable-source-maps` with Mocha ([**@bcoe**](https://github.com/bcoe))
|
|
33
|
+
- [#4343](https://github.com/mochajs/mocha/issues/4343): Clean up some API docs ([**@craigtaub**](https://github.com/craigtaub))
|
|
34
|
+
- [#4318](https://github.com/mochajs/mocha/issues/4318): Sponsor images are now self-hosted ([**@Munter**](https://github.com/Munter))
|
|
35
|
+
|
|
36
|
+
## :nut_and_bolt: Other
|
|
37
|
+
|
|
38
|
+
- [#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))
|
|
39
|
+
|
|
1
40
|
# 8.0.1 / 2020-06-10
|
|
2
41
|
|
|
3
42
|
The obligatory patch after a major.
|
|
4
43
|
|
|
5
44
|
## :bug: Fixes
|
|
6
45
|
|
|
7
|
-
- [#4328]
|
|
46
|
+
- [#4328](https://github.com/mochajs/mocha/issues/4328): Fix `--parallel` when combined with `--watch` ([**@boneskull**](https://github.com/boneskull))
|
|
8
47
|
|
|
9
48
|
# 8.0.0 / 2020-06-10
|
|
10
49
|
|
|
@@ -14,7 +53,7 @@ Let's welcome [**@giltayar**](https://github.com/giltayar) and [**@nicojs**](htt
|
|
|
14
53
|
|
|
15
54
|
## :boom: Breaking Changes
|
|
16
55
|
|
|
17
|
-
- [#4164](https://github.com/mochajs/mocha/issues/4164): **Mocha v8.0.0 now requires Node.js v10.
|
|
56
|
+
- [#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
57
|
|
|
19
58
|
- [#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
59
|
|
|
@@ -35,6 +74,7 @@ Let's welcome [**@giltayar**](https://github.com/giltayar) and [**@nicojs**](htt
|
|
|
35
74
|
- [#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
75
|
|
|
37
76
|
- [#4178](https://github.com/mochajs/mocha/issues/4178): Remove previously soft-deprecated APIs ([**@wnghdcjfe**](https://github.com/wnghdcjfe)):
|
|
77
|
+
|
|
38
78
|
- `Mocha.prototype.ignoreLeaks()`
|
|
39
79
|
- `Mocha.prototype.useColors()`
|
|
40
80
|
- `Mocha.prototype.useInlineDiffs()`
|
|
@@ -54,6 +94,10 @@ Let's welcome [**@giltayar**](https://github.com/giltayar) and [**@nicojs**](htt
|
|
|
54
94
|
|
|
55
95
|
- [#4246](https://github.com/mochajs/mocha/issues/4246): Add documentation for parallel mode and Root Hook plugins ([**@boneskull**](https://github.com/boneskull))
|
|
56
96
|
|
|
97
|
+
## :nut_and_bolt: Other
|
|
98
|
+
|
|
99
|
+
- [#4200](https://github.com/mochajs/mocha/issues/4200): Drop mkdirp and replace it with fs.mkdirSync ([**@HyunSangHan**](https://github.com/HyunSangHan))
|
|
100
|
+
|
|
57
101
|
## :bug: Fixes
|
|
58
102
|
|
|
59
103
|
(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);
|
|
@@ -193,10 +210,10 @@ Mocha.process = process;
|
|
|
193
210
|
* Expose mocha.
|
|
194
211
|
*/
|
|
195
212
|
|
|
196
|
-
|
|
197
|
-
|
|
213
|
+
mocha.Mocha = Mocha;
|
|
214
|
+
mocha.mocha = mocha;
|
|
198
215
|
|
|
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
|
@@ -52,7 +52,7 @@ exports.main = (argv = process.argv.slice(2)) => {
|
|
|
52
52
|
debug('caught error sometime before command handler: %O', err);
|
|
53
53
|
yargs.showHelp();
|
|
54
54
|
console.error(`\n${symbols.error} ${ansi.red('ERROR:')} ${msg}`);
|
|
55
|
-
|
|
55
|
+
process.exitCode = 1;
|
|
56
56
|
})
|
|
57
57
|
.help('help', 'Show usage information & exit')
|
|
58
58
|
.alias('help', 'h')
|
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
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var glob = require('glob');
|
|
6
|
+
var {format} = require('util');
|
|
7
|
+
var errors = require('../errors');
|
|
8
|
+
var createNoFilesMatchPatternError = errors.createNoFilesMatchPatternError;
|
|
9
|
+
var createMissingArgumentError = errors.createMissingArgumentError;
|
|
10
|
+
var {sQuote, dQuote} = require('../utils');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Determines if pathname would be a "hidden" file (or directory) on UN*X.
|
|
14
|
+
*
|
|
15
|
+
* @description
|
|
16
|
+
* On UN*X, pathnames beginning with a full stop (aka dot) are hidden during
|
|
17
|
+
* typical usage. Dotfiles, plain-text configuration files, are prime examples.
|
|
18
|
+
*
|
|
19
|
+
* @see {@link http://xahlee.info/UnixResource_dir/writ/unix_origin_of_dot_filename.html|Origin of Dot File Names}
|
|
20
|
+
*
|
|
21
|
+
* @private
|
|
22
|
+
* @param {string} pathname - Pathname to check for match.
|
|
23
|
+
* @return {boolean} whether pathname would be considered a hidden file.
|
|
24
|
+
* @example
|
|
25
|
+
* isHiddenOnUnix('.profile'); // => true
|
|
26
|
+
*/
|
|
27
|
+
function isHiddenOnUnix(pathname) {
|
|
28
|
+
return path.basename(pathname)[0] === '.';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Determines if pathname has a matching file extension.
|
|
33
|
+
*
|
|
34
|
+
* @private
|
|
35
|
+
* @param {string} pathname - Pathname to check for match.
|
|
36
|
+
* @param {string[]} exts - List of file extensions (sans period).
|
|
37
|
+
* @return {boolean} whether file extension matches.
|
|
38
|
+
* @example
|
|
39
|
+
* hasMatchingExtname('foo.html', ['js', 'css']); // => false
|
|
40
|
+
*/
|
|
41
|
+
function hasMatchingExtname(pathname, exts) {
|
|
42
|
+
var suffix = path.extname(pathname).slice(1);
|
|
43
|
+
return exts.some(function(element) {
|
|
44
|
+
return suffix === element;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Lookup file names at the given `path`.
|
|
50
|
+
*
|
|
51
|
+
* @description
|
|
52
|
+
* Filenames are returned in _traversal_ order by the OS/filesystem.
|
|
53
|
+
* **Make no assumption that the names will be sorted in any fashion.**
|
|
54
|
+
*
|
|
55
|
+
* @public
|
|
56
|
+
* @memberof Mocha.utils
|
|
57
|
+
* @param {string} filepath - Base path to start searching from.
|
|
58
|
+
* @param {string[]} [extensions=[]] - File extensions to look for.
|
|
59
|
+
* @param {boolean} [recursive=false] - Whether to recurse into subdirectories.
|
|
60
|
+
* @return {string[]} An array of paths.
|
|
61
|
+
* @throws {Error} if no files match pattern.
|
|
62
|
+
* @throws {TypeError} if `filepath` is directory and `extensions` not provided.
|
|
63
|
+
*/
|
|
64
|
+
module.exports = function lookupFiles(filepath, extensions, recursive) {
|
|
65
|
+
extensions = extensions || [];
|
|
66
|
+
recursive = recursive || false;
|
|
67
|
+
var files = [];
|
|
68
|
+
var stat;
|
|
69
|
+
|
|
70
|
+
if (!fs.existsSync(filepath)) {
|
|
71
|
+
var pattern;
|
|
72
|
+
if (glob.hasMagic(filepath)) {
|
|
73
|
+
// Handle glob as is without extensions
|
|
74
|
+
pattern = filepath;
|
|
75
|
+
} else {
|
|
76
|
+
// glob pattern e.g. 'filepath+(.js|.ts)'
|
|
77
|
+
var strExtensions = extensions
|
|
78
|
+
.map(function(v) {
|
|
79
|
+
return '.' + v;
|
|
80
|
+
})
|
|
81
|
+
.join('|');
|
|
82
|
+
pattern = filepath + '+(' + strExtensions + ')';
|
|
83
|
+
}
|
|
84
|
+
files = glob.sync(pattern, {nodir: true});
|
|
85
|
+
if (!files.length) {
|
|
86
|
+
throw createNoFilesMatchPatternError(
|
|
87
|
+
'Cannot find any files matching pattern ' + dQuote(filepath),
|
|
88
|
+
filepath
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
return files;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Handle file
|
|
95
|
+
try {
|
|
96
|
+
stat = fs.statSync(filepath);
|
|
97
|
+
if (stat.isFile()) {
|
|
98
|
+
return filepath;
|
|
99
|
+
}
|
|
100
|
+
} catch (err) {
|
|
101
|
+
// ignore error
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Handle directory
|
|
106
|
+
fs.readdirSync(filepath).forEach(function(dirent) {
|
|
107
|
+
var pathname = path.join(filepath, dirent);
|
|
108
|
+
var stat;
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
stat = fs.statSync(pathname);
|
|
112
|
+
if (stat.isDirectory()) {
|
|
113
|
+
if (recursive) {
|
|
114
|
+
files = files.concat(lookupFiles(pathname, extensions, recursive));
|
|
115
|
+
}
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
} catch (err) {
|
|
119
|
+
// ignore error
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (!extensions.length) {
|
|
123
|
+
throw createMissingArgumentError(
|
|
124
|
+
format(
|
|
125
|
+
'Argument %s required when argument %s is a directory',
|
|
126
|
+
sQuote('extensions'),
|
|
127
|
+
sQuote('filepath')
|
|
128
|
+
),
|
|
129
|
+
'extensions',
|
|
130
|
+
'array'
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (
|
|
135
|
+
!stat.isFile() ||
|
|
136
|
+
!hasMatchingExtname(pathname, extensions) ||
|
|
137
|
+
isHiddenOnUnix(pathname)
|
|
138
|
+
) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
files.push(pathname);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
return files;
|
|
145
|
+
};
|
package/lib/cli/watch-run.js
CHANGED
|
@@ -19,7 +19,7 @@ const collectFiles = require('./collect-files');
|
|
|
19
19
|
* @param {Object} opts - Options
|
|
20
20
|
* @param {string[]} [opts.watchFiles] - List of paths and patterns to
|
|
21
21
|
* watch. If not provided all files with an extension included in
|
|
22
|
-
* `
|
|
22
|
+
* `fileCollectionParams.extension` are watched. See first argument of
|
|
23
23
|
* `chokidar.watch`.
|
|
24
24
|
* @param {string[]} opts.watchIgnore - List of paths and patterns to
|
|
25
25
|
* exclude from watching. See `ignored` option of `chokidar`.
|
|
@@ -59,6 +59,10 @@ exports.watchParallelRun = (
|
|
|
59
59
|
// in `createRerunner`), we need to call `mocha.ui()` again to set up the context/globals.
|
|
60
60
|
newMocha.ui(newMocha.options.ui);
|
|
61
61
|
|
|
62
|
+
// we need to call `newMocha.rootHooks` to set up rootHooks for the new
|
|
63
|
+
// suite
|
|
64
|
+
newMocha.rootHooks(newMocha.options.rootHooks);
|
|
65
|
+
|
|
62
66
|
// in parallel mode, the main Mocha process doesn't actually load the
|
|
63
67
|
// files. this flag prevents `mocha.run()` from autoloading.
|
|
64
68
|
newMocha.lazyLoadFiles(true);
|
|
@@ -77,7 +81,7 @@ exports.watchParallelRun = (
|
|
|
77
81
|
* @param {Object} opts - Options
|
|
78
82
|
* @param {string[]} [opts.watchFiles] - List of paths and patterns to
|
|
79
83
|
* watch. If not provided all files with an extension included in
|
|
80
|
-
* `
|
|
84
|
+
* `fileCollectionParams.extension` are watched. See first argument of
|
|
81
85
|
* `chokidar.watch`.
|
|
82
86
|
* @param {string[]} opts.watchIgnore - List of paths and patterns to
|
|
83
87
|
* exclude from watching. See `ignored` option of `chokidar`.
|
|
@@ -118,6 +122,10 @@ exports.watchRun = (mocha, {watchFiles, watchIgnore}, fileCollectParams) => {
|
|
|
118
122
|
// in `createRerunner`), we need to call `mocha.ui()` again to set up the context/globals.
|
|
119
123
|
newMocha.ui(newMocha.options.ui);
|
|
120
124
|
|
|
125
|
+
// we need to call `newMocha.rootHooks` to set up rootHooks for the new
|
|
126
|
+
// suite
|
|
127
|
+
newMocha.rootHooks(newMocha.options.rootHooks);
|
|
128
|
+
|
|
121
129
|
return newMocha;
|
|
122
130
|
},
|
|
123
131
|
afterRun({watcher}) {
|
|
@@ -136,7 +144,7 @@ exports.watchRun = (mocha, {watchFiles, watchIgnore}, fileCollectParams) => {
|
|
|
136
144
|
* @param {AfterWatchRun} [opts.afterRun] - Function to call after `mocha.run()`
|
|
137
145
|
* @param {string[]} [opts.watchFiles] - List of paths and patterns to watch. If
|
|
138
146
|
* not provided all files with an extension included in
|
|
139
|
-
* `
|
|
147
|
+
* `fileCollectionParams.extension` are watched. See first argument of
|
|
140
148
|
* `chokidar.watch`.
|
|
141
149
|
* @param {string[]} [opts.watchIgnore] - List of paths and patterns to exclude
|
|
142
150
|
* from watching. See `ignored` option of `chokidar`.
|
package/lib/errors.js
CHANGED
|
@@ -59,12 +59,12 @@ var constants = {
|
|
|
59
59
|
UNSUPPORTED: 'ERR_MOCHA_UNSUPPORTED',
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
|
-
* Invalid state transition
|
|
62
|
+
* Invalid state transition occurring in `Mocha` instance
|
|
63
63
|
*/
|
|
64
64
|
INSTANCE_ALREADY_RUNNING: 'ERR_MOCHA_INSTANCE_ALREADY_RUNNING',
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
|
-
* Invalid state transition
|
|
67
|
+
* Invalid state transition occurring in `Mocha` instance
|
|
68
68
|
*/
|
|
69
69
|
INSTANCE_ALREADY_DISPOSED: 'ERR_MOCHA_INSTANCE_ALREADY_DISPOSED',
|
|
70
70
|
|
package/lib/interfaces/common.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
@module interfaces/common
|
|
5
|
+
*/
|
|
6
|
+
|
|
3
7
|
var Suite = require('../suite');
|
|
4
8
|
var errors = require('../errors');
|
|
5
9
|
var createMissingArgumentError = errors.createMissingArgumentError;
|
|
@@ -9,6 +13,7 @@ var createForbiddenExclusivityError = errors.createForbiddenExclusivityError;
|
|
|
9
13
|
/**
|
|
10
14
|
* Functions common to more than one interface.
|
|
11
15
|
*
|
|
16
|
+
* @private
|
|
12
17
|
* @param {Suite[]} suites
|
|
13
18
|
* @param {Context} context
|
|
14
19
|
* @param {Mocha} mocha
|
package/lib/mocha.js
CHANGED
|
@@ -35,23 +35,28 @@ exports = module.exports = Mocha;
|
|
|
35
35
|
/**
|
|
36
36
|
* A Mocha instance is a finite state machine.
|
|
37
37
|
* These are the states it can be in.
|
|
38
|
+
* @private
|
|
38
39
|
*/
|
|
39
40
|
var mochaStates = utils.defineConstants({
|
|
40
41
|
/**
|
|
41
42
|
* Initial state of the mocha instance
|
|
43
|
+
* @private
|
|
42
44
|
*/
|
|
43
45
|
INIT: 'init',
|
|
44
46
|
/**
|
|
45
47
|
* Mocha instance is running tests
|
|
48
|
+
* @private
|
|
46
49
|
*/
|
|
47
50
|
RUNNING: 'running',
|
|
48
51
|
/**
|
|
49
52
|
* Mocha instance is done running tests and references to test functions and hooks are cleaned.
|
|
50
53
|
* You can reset this state by unloading the test files.
|
|
54
|
+
* @private
|
|
51
55
|
*/
|
|
52
56
|
REFERENCES_CLEANED: 'referencesCleaned',
|
|
53
57
|
/**
|
|
54
58
|
* Mocha instance is disposed and can no longer be used.
|
|
59
|
+
* @private
|
|
55
60
|
*/
|
|
56
61
|
DISPOSED: 'disposed'
|
|
57
62
|
});
|
|
@@ -67,6 +72,7 @@ if (!utils.isBrowser() && typeof module.paths !== 'undefined') {
|
|
|
67
72
|
|
|
68
73
|
/**
|
|
69
74
|
* Expose internals.
|
|
75
|
+
* @private
|
|
70
76
|
*/
|
|
71
77
|
|
|
72
78
|
exports.utils = utils;
|
|
@@ -246,7 +252,7 @@ Mocha.prototype.addFile = function(file) {
|
|
|
246
252
|
* @public
|
|
247
253
|
* @see [CLI option](../#-reporter-name-r-name)
|
|
248
254
|
* @see [Reporters](../#reporters)
|
|
249
|
-
* @param {String|Function}
|
|
255
|
+
* @param {String|Function} reporterName - Reporter name or constructor.
|
|
250
256
|
* @param {Object} [reporterOptions] - Options used to configure the reporter.
|
|
251
257
|
* @returns {Mocha} this
|
|
252
258
|
* @chainable
|
|
@@ -769,8 +775,8 @@ Mocha.prototype.timeout = function(msecs) {
|
|
|
769
775
|
* // Allow any failed test to retry one more time
|
|
770
776
|
* mocha.retries(1);
|
|
771
777
|
*/
|
|
772
|
-
Mocha.prototype.retries = function(
|
|
773
|
-
this.suite.retries(
|
|
778
|
+
Mocha.prototype.retries = function(retry) {
|
|
779
|
+
this.suite.retries(retry);
|
|
774
780
|
return this;
|
|
775
781
|
};
|
|
776
782
|
|
|
@@ -921,6 +927,7 @@ Object.defineProperty(Mocha.prototype, 'version', {
|
|
|
921
927
|
/**
|
|
922
928
|
* Callback to be invoked when test execution is complete.
|
|
923
929
|
*
|
|
930
|
+
* @private
|
|
924
931
|
* @callback DoneCB
|
|
925
932
|
* @param {number} failures - Number of failures that occurred.
|
|
926
933
|
*/
|
|
@@ -1091,6 +1098,7 @@ Mocha.prototype.lazyLoadFiles = function lazyLoadFiles(enable) {
|
|
|
1091
1098
|
|
|
1092
1099
|
/**
|
|
1093
1100
|
* An alternative way to define root hooks that works with parallel runs.
|
|
1101
|
+
* @private
|
|
1094
1102
|
* @typedef {Object} MochaRootHookObject
|
|
1095
1103
|
* @property {Function|Function[]} [beforeAll] - "Before all" hook(s)
|
|
1096
1104
|
* @property {Function|Function[]} [beforeEach] - "Before each" hook(s)
|
|
@@ -1100,6 +1108,7 @@ Mocha.prototype.lazyLoadFiles = function lazyLoadFiles(enable) {
|
|
|
1100
1108
|
|
|
1101
1109
|
/**
|
|
1102
1110
|
* An function that returns a {@link MochaRootHookObject}, either sync or async.
|
|
1111
|
+
* @private
|
|
1103
1112
|
* @callback MochaRootHookFunction
|
|
1104
1113
|
* @returns {MochaRootHookObject|Promise<MochaRootHookObject>}
|
|
1105
1114
|
*/
|
|
@@ -281,12 +281,14 @@ module.exports = ParallelBufferedRunner;
|
|
|
281
281
|
|
|
282
282
|
/**
|
|
283
283
|
* Listener function intended to be bound to `Process.SIGINT` event
|
|
284
|
+
* @private
|
|
284
285
|
* @callback SigIntListener
|
|
285
286
|
* @returns {Promise<void>}
|
|
286
287
|
*/
|
|
287
288
|
|
|
288
289
|
/**
|
|
289
290
|
* A function accepting a test file path and returning the results of a test run
|
|
291
|
+
* @private
|
|
290
292
|
* @callback FileRunner
|
|
291
293
|
* @param {string} filename - File to run
|
|
292
294
|
* @returns {Promise<SerializedWorkerResult>}
|
package/lib/nodejs/serializer.js
CHANGED
|
@@ -387,6 +387,7 @@ exports.SerializableWorkerResult = SerializableWorkerResult;
|
|
|
387
387
|
/**
|
|
388
388
|
* The result of calling `SerializableEvent.serialize`, as received
|
|
389
389
|
* by the deserializer.
|
|
390
|
+
* @private
|
|
390
391
|
* @typedef {Object} SerializedEvent
|
|
391
392
|
* @property {object?} data - Optional serialized data
|
|
392
393
|
* @property {object?} error - Optional serialized `Error`
|
|
@@ -395,6 +396,7 @@ exports.SerializableWorkerResult = SerializableWorkerResult;
|
|
|
395
396
|
/**
|
|
396
397
|
* The result of calling `SerializableWorkerResult.serialize` as received
|
|
397
398
|
* by the deserializer.
|
|
399
|
+
* @private
|
|
398
400
|
* @typedef {Object} SerializedWorkerResult
|
|
399
401
|
* @property {number} failureCount - Number of failures
|
|
400
402
|
* @property {SerializedEvent[]} events - Serialized events
|