mocha 7.1.2 → 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 +143 -2
- package/bin/mocha +24 -4
- package/browser-entry.js +37 -9
- package/lib/browser/growl.js +2 -1
- 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 +6 -3
- package/lib/cli/collect-files.js +17 -10
- package/lib/cli/config.js +6 -6
- package/lib/cli/init.js +1 -2
- package/lib/cli/lookup-files.js +145 -0
- package/lib/cli/node-flags.js +2 -2
- package/lib/cli/options.js +14 -90
- package/lib/cli/run-helpers.js +133 -36
- package/lib/cli/run-option-metadata.js +4 -2
- package/lib/cli/run.js +71 -11
- package/lib/cli/watch-run.js +211 -51
- package/lib/context.js +0 -15
- package/lib/errors.js +202 -9
- package/lib/esm-utils.js +11 -6
- package/lib/hook.js +32 -0
- package/lib/interfaces/common.js +21 -10
- package/lib/mocha.js +301 -126
- package/lib/mocharc.json +0 -1
- package/lib/nodejs/buffered-worker-pool.js +174 -0
- package/lib/{growl.js → nodejs/growl.js} +3 -2
- package/lib/nodejs/parallel-buffered-runner.js +295 -0
- package/lib/nodejs/reporters/parallel-buffered.js +133 -0
- package/lib/nodejs/serializer.js +404 -0
- package/lib/nodejs/worker.js +154 -0
- package/lib/pending.js +4 -0
- package/lib/reporters/base.js +25 -12
- package/lib/reporters/doc.js +6 -0
- package/lib/reporters/json-stream.js +1 -0
- package/lib/reporters/json.js +1 -0
- package/lib/reporters/landing.js +11 -3
- package/lib/reporters/tap.js +1 -2
- package/lib/reporters/xunit.js +3 -2
- package/lib/runnable.js +39 -47
- package/lib/runner.js +219 -118
- package/lib/suite.js +61 -27
- package/lib/test.js +48 -3
- package/lib/utils.js +33 -209
- package/mocha.js +25522 -17715
- package/mocha.js.map +1 -0
- package/package.json +87 -68
- package/lib/browser/tty.js +0 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,138 @@
|
|
|
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
|
+
|
|
40
|
+
# 8.0.1 / 2020-06-10
|
|
41
|
+
|
|
42
|
+
The obligatory patch after a major.
|
|
43
|
+
|
|
44
|
+
## :bug: Fixes
|
|
45
|
+
|
|
46
|
+
- [#4328](https://github.com/mochajs/mocha/issues/4328): Fix `--parallel` when combined with `--watch` ([**@boneskull**](https://github.com/boneskull))
|
|
47
|
+
|
|
48
|
+
# 8.0.0 / 2020-06-10
|
|
49
|
+
|
|
50
|
+
In this major release, Mocha adds the ability to _run tests in parallel_. Better late than never! Please note the **breaking changes** detailed below.
|
|
51
|
+
|
|
52
|
+
Let's welcome [**@giltayar**](https://github.com/giltayar) and [**@nicojs**](https://github.com/nicojs) to the maintenance team!
|
|
53
|
+
|
|
54
|
+
## :boom: Breaking Changes
|
|
55
|
+
|
|
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))
|
|
57
|
+
|
|
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))
|
|
59
|
+
|
|
60
|
+
:sparkles: **WORKAROUND:** Replace `mocha.opts` with a [configuration file](https://mochajs.org/#configuring-mocha-nodejs).
|
|
61
|
+
|
|
62
|
+
- [#4260](https://github.com/mochajs/mocha/issues/4260): Remove `enableTimeout()` (`this.enableTimeout()`) from the context object ([**@craigtaub**](https://github.com/craigtaub))
|
|
63
|
+
|
|
64
|
+
:sparkles: **WORKAROUND:** Replace usage of `this.enableTimeout(false)` in your tests with `this.timeout(0)`.
|
|
65
|
+
|
|
66
|
+
- [#4315](https://github.com/mochajs/mocha/issues/4315): The `spec` option no longer supports a comma-delimited list of files ([**@juergba**](https://github.com/juergba))
|
|
67
|
+
|
|
68
|
+
:sparkles: **WORKAROUND**: Use an array instead (e.g., `"spec": "foo.js,bar.js"` becomes `"spec": ["foo.js", "bar.js"]`).
|
|
69
|
+
|
|
70
|
+
- [#4309](https://github.com/mochajs/mocha/issues/4309): Drop support for Node.js v13.x line, which is now End-of-Life ([**@juergba**](https://github.com/juergba))
|
|
71
|
+
|
|
72
|
+
- [#4282](https://github.com/mochajs/mocha/issues/4282): `--forbid-only` will throw an error even if exclusive tests are avoided via `--grep` or other means ([**@arvidOtt**](https://github.com/arvidOtt))
|
|
73
|
+
|
|
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))
|
|
75
|
+
|
|
76
|
+
- [#4178](https://github.com/mochajs/mocha/issues/4178): Remove previously soft-deprecated APIs ([**@wnghdcjfe**](https://github.com/wnghdcjfe)):
|
|
77
|
+
|
|
78
|
+
- `Mocha.prototype.ignoreLeaks()`
|
|
79
|
+
- `Mocha.prototype.useColors()`
|
|
80
|
+
- `Mocha.prototype.useInlineDiffs()`
|
|
81
|
+
- `Mocha.prototype.hideDiff()`
|
|
82
|
+
|
|
83
|
+
## :tada: Enhancements
|
|
84
|
+
|
|
85
|
+
- [#4245](https://github.com/mochajs/mocha/issues/4245): Add ability to run tests in parallel for Node.js (see [docs](https://mochajs.org/#parallel-tests)) ([**@boneskull**](https://github.com/boneskull))
|
|
86
|
+
|
|
87
|
+
:exclamation: See also [#4244](https://github.com/mochajs/mocha/issues/4244); [Root Hook Plugins (docs)](https://mochajs.org/#root-hook-plugins) -- _root hooks must be defined via Root Hook Plugins to work in parallel mode_
|
|
88
|
+
|
|
89
|
+
- [#4304](https://github.com/mochajs/mocha/issues/4304): `--require` now works with ES modules ([**@JacobLey**](https://github.com/JacobLey))
|
|
90
|
+
|
|
91
|
+
- [#4299](https://github.com/mochajs/mocha/issues/4299): In some circumstances, Mocha can run ES modules under Node.js v10 -- _use at your own risk!_ ([**@giltayar**](https://github.com/giltayar))
|
|
92
|
+
|
|
93
|
+
## :book: Documentation
|
|
94
|
+
|
|
95
|
+
- [#4246](https://github.com/mochajs/mocha/issues/4246): Add documentation for parallel mode and Root Hook plugins ([**@boneskull**](https://github.com/boneskull))
|
|
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
|
+
|
|
101
|
+
## :bug: Fixes
|
|
102
|
+
|
|
103
|
+
(All bug fixes in Mocha v8.0.0 are also breaking changes, and are listed above)
|
|
104
|
+
|
|
105
|
+
# 7.2.0 / 2020-05-22
|
|
106
|
+
|
|
107
|
+
## :tada: Enhancements
|
|
108
|
+
|
|
109
|
+
- [#4234](https://github.com/mochajs/mocha/issues/4234): Add ability to run tests in a mocha instance multiple times ([**@nicojs**](https://github.com/nicojs))
|
|
110
|
+
- [#4219](https://github.com/mochajs/mocha/issues/4219): Exposing filename in JSON, doc, and json-stream reporters ([**@Daniel0113**](https://github.com/Daniel0113))
|
|
111
|
+
- [#4244](https://github.com/mochajs/mocha/issues/4244): Add Root Hook Plugins ([**@boneskull**](https://github.com/boneskull))
|
|
112
|
+
|
|
113
|
+
## :bug: Fixes
|
|
114
|
+
|
|
115
|
+
- [#4258](https://github.com/mochajs/mocha/issues/4258): Fix missing dot in name of configuration file ([**@sonicdoe**](https://github.com/sonicdoe))
|
|
116
|
+
- [#4194](https://github.com/mochajs/mocha/issues/4194): Check if module.paths really exists ([**@ematipico**](https://github.com/ematipico))
|
|
117
|
+
- [#4256](https://github.com/mochajs/mocha/issues/4256): `--forbid-only` does not recognize `it.only` when `before` crashes ([**@arvidOtt**](https://github.com/arvidOtt))
|
|
118
|
+
- [#4152](https://github.com/mochajs/mocha/issues/4152): Bug with multiple async done() calls ([**@boneskull**](https://github.com/boneskull))
|
|
119
|
+
- [#4275](https://github.com/mochajs/mocha/issues/4275): Improper warnings for invalid reporters ([**@boneskull**](https://github.com/boneskull))
|
|
120
|
+
- [#4288](https://github.com/mochajs/mocha/issues/4288): Broken hook.spec.js test for IE11 ([**@boneskull**](https://github.com/boneskull))
|
|
121
|
+
|
|
122
|
+
## :book: Documentation
|
|
123
|
+
|
|
124
|
+
- [#4081](https://github.com/mochajs/mocha/issues/4081): Insufficient white space for API docs in view on mobile ([**@HyunSangHan**](https://github.com/HyunSangHan))
|
|
125
|
+
- [#4255](https://github.com/mochajs/mocha/issues/4255): Update mocha-docdash for UI fixes on API docs ([**@craigtaub**](https://github.com/craigtaub))
|
|
126
|
+
- [#4235](https://github.com/mochajs/mocha/issues/4235): Enable emoji on website; enable normal ul elements ([**@boneskull**](https://github.com/boneskull))
|
|
127
|
+
- [#4272](https://github.com/mochajs/mocha/issues/4272): Fetch sponsors at build time, show ALL non-skeevy sponsors ([**@boneskull**](https://github.com/boneskull))
|
|
128
|
+
|
|
129
|
+
## :nut_and_bolt: Other
|
|
130
|
+
|
|
131
|
+
- [#4249](https://github.com/mochajs/mocha/issues/4249): Refactoring improving encapsulation ([**@arvidOtt**](https://github.com/arvidOtt))
|
|
132
|
+
- [#4242](https://github.com/mochajs/mocha/issues/4242): CI add job names, add Node.js v14 to matrix ([**@boneskull**](https://github.com/boneskull))
|
|
133
|
+
- [#4237](https://github.com/mochajs/mocha/issues/4237): Refactor validatePlugins to throw coded errors ([**@boneskull**](https://github.com/boneskull))
|
|
134
|
+
- [#4236](https://github.com/mochajs/mocha/issues/4236): Better debug output ([**@boneskull**](https://github.com/boneskull))
|
|
135
|
+
|
|
1
136
|
# 7.1.2 / 2020-04-26
|
|
2
137
|
|
|
3
138
|
## :nut_and_bolt: Other
|
|
@@ -128,6 +263,12 @@ These are _soft_-deprecated, and will emit a warning upon use. Support will be r
|
|
|
128
263
|
- [#4089](https://github.com/mochajs/mocha/issues/4089): Add funding information to `package.json` ([**@Munter**](https://github.com/Munter))
|
|
129
264
|
- [#4077](https://github.com/mochajs/mocha/issues/4077): Improve integration tests ([**@soobing**](https://github.com/soobing))
|
|
130
265
|
|
|
266
|
+
# 6.2.3 / 2020-03-25
|
|
267
|
+
|
|
268
|
+
## :lock: Security Fixes
|
|
269
|
+
|
|
270
|
+
- [848d6fb8](https://github.com/mochajs/mocha/commit/848d6fb8feef659564b296db457312d38176910d): Update dependencies mkdirp, yargs-parser and yargs ([**@juergba**](https://github.com/juergba))
|
|
271
|
+
|
|
131
272
|
# 6.2.2 / 2019-10-18
|
|
132
273
|
|
|
133
274
|
## :bug: Fixes
|
|
@@ -546,7 +687,7 @@ This release fixes a class of tests which report as _false positives_. **Certain
|
|
|
546
687
|
|
|
547
688
|
- [#3226](https://github.com/mochajs/mocha/issues/3226): Do not swallow errors that are thrown asynchronously from passing tests ([@boneskull](https://github.com/boneskull)). Example:
|
|
548
689
|
|
|
549
|
-
|
|
690
|
+
\`\`\`js
|
|
550
691
|
it('should actually fail, sorry!', function (done) {
|
|
551
692
|
// passing assertion
|
|
552
693
|
assert(true === true);
|
|
@@ -559,7 +700,7 @@ This release fixes a class of tests which report as _false positives_. **Certain
|
|
|
559
700
|
throw new Error('chaos!');
|
|
560
701
|
}, 100);
|
|
561
702
|
});
|
|
562
|
-
|
|
703
|
+
\`\`\`
|
|
563
704
|
|
|
564
705
|
Previously to this version, Mocha would have _silently swallowed_ the `chaos!` exception, and you wouldn't know. Well, _now you know_. Mocha cannot recover from this gracefully, so it will exit with a nonzero code.
|
|
565
706
|
|
package/bin/mocha
CHANGED
|
@@ -34,7 +34,7 @@ debug('loaded opts', opts);
|
|
|
34
34
|
*/
|
|
35
35
|
const disableTimeouts = value => {
|
|
36
36
|
if (impliesNoTimeouts(value)) {
|
|
37
|
-
debug(
|
|
37
|
+
debug('option %s disabled timeouts', value);
|
|
38
38
|
mochaArgs.timeout = 0;
|
|
39
39
|
delete mochaArgs.timeouts;
|
|
40
40
|
delete mochaArgs.t;
|
|
@@ -108,7 +108,11 @@ if (Object.keys(nodeArgs).length) {
|
|
|
108
108
|
unparse(mochaArgs, {alias: aliases})
|
|
109
109
|
);
|
|
110
110
|
|
|
111
|
-
debug(
|
|
111
|
+
debug(
|
|
112
|
+
'forking child process via command: %s %s',
|
|
113
|
+
process.execPath,
|
|
114
|
+
args.join(' ')
|
|
115
|
+
);
|
|
112
116
|
|
|
113
117
|
const proc = spawn(process.execPath, args, {
|
|
114
118
|
stdio: 'inherit'
|
|
@@ -126,9 +130,25 @@ if (Object.keys(nodeArgs).length) {
|
|
|
126
130
|
|
|
127
131
|
// terminate children.
|
|
128
132
|
process.on('SIGINT', () => {
|
|
129
|
-
|
|
130
|
-
|
|
133
|
+
// XXX: a previous comment said this would abort the runner, but I can't see that it does
|
|
134
|
+
// anything with the default runner.
|
|
135
|
+
debug('main process caught SIGINT');
|
|
136
|
+
proc.kill('SIGINT');
|
|
137
|
+
// if running in parallel mode, we will have a proper SIGINT handler, so the below won't
|
|
138
|
+
// be needed.
|
|
139
|
+
if (!args.parallel || args.jobs < 2) {
|
|
140
|
+
// win32 does not support SIGTERM, so use next best thing.
|
|
141
|
+
if (require('os').platform() === 'win32') {
|
|
142
|
+
proc.kill('SIGKILL');
|
|
143
|
+
} else {
|
|
144
|
+
// using SIGKILL won't cleanly close the output streams, which can result
|
|
145
|
+
// in cut-off text or a befouled terminal.
|
|
146
|
+
debug('sending SIGTERM to child process');
|
|
147
|
+
proc.kill('SIGTERM');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
131
150
|
});
|
|
132
151
|
} else {
|
|
152
|
+
debug('running Mocha in-process');
|
|
133
153
|
require('../lib/cli/cli').main(unparse(mochaArgs, {alias: aliases}));
|
|
134
154
|
}
|
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
|
/**
|
|
@@ -52,6 +54,17 @@ process.removeListener = function(e, fn) {
|
|
|
52
54
|
}
|
|
53
55
|
};
|
|
54
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Implements listenerCount for 'uncaughtException'.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
process.listenerCount = function(name) {
|
|
62
|
+
if (name === 'uncaughtException') {
|
|
63
|
+
return uncaughtExceptionHandlers.length;
|
|
64
|
+
}
|
|
65
|
+
return 0;
|
|
66
|
+
};
|
|
67
|
+
|
|
55
68
|
/**
|
|
56
69
|
* Implements uncaughtException listener.
|
|
57
70
|
*/
|
|
@@ -66,6 +79,13 @@ process.on = function(e, fn) {
|
|
|
66
79
|
}
|
|
67
80
|
};
|
|
68
81
|
|
|
82
|
+
process.listeners = function(e) {
|
|
83
|
+
if (e === 'uncaughtException') {
|
|
84
|
+
return uncaughtExceptionHandlers;
|
|
85
|
+
}
|
|
86
|
+
return [];
|
|
87
|
+
};
|
|
88
|
+
|
|
69
89
|
// The BDD UI is registered by default, but no UI will be functional in the
|
|
70
90
|
// browser without an explicit call to the overridden `mocha.ui` (see below).
|
|
71
91
|
// Ensure that this default UI does not expose its methods to the global scope.
|
|
@@ -128,11 +148,19 @@ mocha.setup = function(opts) {
|
|
|
128
148
|
if (typeof opts === 'string') {
|
|
129
149
|
opts = {ui: opts};
|
|
130
150
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
this[opt](opts[opt]);
|
|
134
|
-
}
|
|
151
|
+
if (opts.delay === true) {
|
|
152
|
+
this.delay();
|
|
135
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
|
+
});
|
|
136
164
|
return this;
|
|
137
165
|
};
|
|
138
166
|
|
|
@@ -144,7 +172,7 @@ mocha.run = function(fn) {
|
|
|
144
172
|
var options = mocha.options;
|
|
145
173
|
mocha.globals('location');
|
|
146
174
|
|
|
147
|
-
var query =
|
|
175
|
+
var query = parseQuery(global.location.search || '');
|
|
148
176
|
if (query.grep) {
|
|
149
177
|
mocha.grep(query.grep);
|
|
150
178
|
}
|
|
@@ -163,7 +191,7 @@ mocha.run = function(fn) {
|
|
|
163
191
|
document.getElementById('mocha') &&
|
|
164
192
|
options.noHighlighting !== true
|
|
165
193
|
) {
|
|
166
|
-
|
|
194
|
+
highlightTags('code');
|
|
167
195
|
}
|
|
168
196
|
if (fn) {
|
|
169
197
|
fn(err);
|
|
@@ -182,10 +210,10 @@ Mocha.process = process;
|
|
|
182
210
|
* Expose mocha.
|
|
183
211
|
*/
|
|
184
212
|
|
|
185
|
-
|
|
186
|
-
|
|
213
|
+
mocha.Mocha = Mocha;
|
|
214
|
+
mocha.mocha = mocha;
|
|
187
215
|
|
|
188
216
|
// this allows test/acceptance/required-tokens.js to pass; thus,
|
|
189
217
|
// you can now do `const describe = require('mocha').describe` in a
|
|
190
218
|
// browser context (assuming browserification). should fix #880
|
|
191
|
-
module.exports = global;
|
|
219
|
+
module.exports = Object.assign(mocha, global);
|
package/lib/browser/growl.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
var Date = global.Date;
|
|
12
12
|
var setTimeout = global.setTimeout;
|
|
13
13
|
var EVENT_RUN_END = require('../runner').constants.EVENT_RUN_END;
|
|
14
|
+
var isBrowser = require('../utils').isBrowser;
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Checks if browser notification support exists.
|
|
@@ -25,7 +26,7 @@ var EVENT_RUN_END = require('../runner').constants.EVENT_RUN_END;
|
|
|
25
26
|
exports.isCapable = function() {
|
|
26
27
|
var hasNotificationSupport = 'Notification' in window;
|
|
27
28
|
var hasPromiseSupport = typeof Promise === 'function';
|
|
28
|
-
return
|
|
29
|
+
return isBrowser() && hasNotificationSupport && hasPromiseSupport;
|
|
29
30
|
};
|
|
30
31
|
|
|
31
32
|
/**
|
|
@@ -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
|
@@ -19,6 +19,7 @@ const {loadOptions, YARGS_PARSER_CONFIG} = require('./options');
|
|
|
19
19
|
const commands = require('./commands');
|
|
20
20
|
const ansi = require('ansi-colors');
|
|
21
21
|
const {repository, homepage, version, gitter} = require('../../package.json');
|
|
22
|
+
const {cwd} = require('../utils');
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* - Accepts an `Array` of arguments
|
|
@@ -30,7 +31,9 @@ const {repository, homepage, version, gitter} = require('../../package.json');
|
|
|
30
31
|
exports.main = (argv = process.argv.slice(2)) => {
|
|
31
32
|
debug('entered main with raw args', argv);
|
|
32
33
|
// ensure we can require() from current working directory
|
|
33
|
-
module.paths
|
|
34
|
+
if (typeof module.paths !== 'undefined') {
|
|
35
|
+
module.paths.push(cwd(), path.resolve('node_modules'));
|
|
36
|
+
}
|
|
34
37
|
|
|
35
38
|
Error.stackTraceLimit = Infinity; // configurable via --stack-trace-limit?
|
|
36
39
|
|
|
@@ -46,10 +49,10 @@ exports.main = (argv = process.argv.slice(2)) => {
|
|
|
46
49
|
'Commands:': 'Commands'
|
|
47
50
|
})
|
|
48
51
|
.fail((msg, err, yargs) => {
|
|
49
|
-
debug(err);
|
|
52
|
+
debug('caught error sometime before command handler: %O', err);
|
|
50
53
|
yargs.showHelp();
|
|
51
54
|
console.error(`\n${symbols.error} ${ansi.red('ERROR:')} ${msg}`);
|
|
52
|
-
process.
|
|
55
|
+
process.exitCode = 1;
|
|
53
56
|
})
|
|
54
57
|
.help('help', 'Show usage information & exit')
|
|
55
58
|
.alias('help', 'h')
|
package/lib/cli/collect-files.js
CHANGED
|
@@ -4,7 +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
|
|
7
|
+
const {NO_FILES_MATCH_PATTERN} = require('../errors').constants;
|
|
8
|
+
const lookupFiles = require('./lookup-files');
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Exports a function that collects test files from CLI parameters.
|
|
@@ -16,13 +17,7 @@ const utils = require('../utils');
|
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Smash together an array of test files in the correct order
|
|
19
|
-
* @param {
|
|
20
|
-
* @param {string[]} opts.extension - File extensions to use
|
|
21
|
-
* @param {string[]} opts.spec - Files, dirs, globs to run
|
|
22
|
-
* @param {string[]} opts.ignore - Files, dirs, globs to ignore
|
|
23
|
-
* @param {string[]} opts.file - List of additional files to include
|
|
24
|
-
* @param {boolean} opts.recursive - Find files recursively
|
|
25
|
-
* @param {boolean} opts.sort - Sort test files
|
|
20
|
+
* @param {FileCollectionOptions} [opts] - Options
|
|
26
21
|
* @returns {string[]} List of files to test
|
|
27
22
|
* @private
|
|
28
23
|
*/
|
|
@@ -32,9 +27,9 @@ module.exports = ({ignore, extension, file, recursive, sort, spec} = {}) => {
|
|
|
32
27
|
spec.forEach(arg => {
|
|
33
28
|
let newFiles;
|
|
34
29
|
try {
|
|
35
|
-
newFiles =
|
|
30
|
+
newFiles = lookupFiles(arg, extension, recursive);
|
|
36
31
|
} catch (err) {
|
|
37
|
-
if (err.code ===
|
|
32
|
+
if (err.code === NO_FILES_MATCH_PATTERN) {
|
|
38
33
|
unmatched.push({message: err.message, pattern: err.pattern});
|
|
39
34
|
return;
|
|
40
35
|
}
|
|
@@ -83,3 +78,15 @@ module.exports = ({ignore, extension, file, recursive, sort, spec} = {}) => {
|
|
|
83
78
|
|
|
84
79
|
return files;
|
|
85
80
|
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* An object to configure how Mocha gathers test files
|
|
84
|
+
* @private
|
|
85
|
+
* @typedef {Object} FileCollectionOptions
|
|
86
|
+
* @property {string[]} extension - File extensions to use
|
|
87
|
+
* @property {string[]} spec - Files, dirs, globs to run
|
|
88
|
+
* @property {string[]} ignore - Files, dirs, globs to ignore
|
|
89
|
+
* @property {string[]} file - List of additional files to include
|
|
90
|
+
* @property {boolean} recursive - Find files recursively
|
|
91
|
+
* @property {boolean} sort - Sort test files
|
|
92
|
+
*/
|
package/lib/cli/config.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Responsible for loading / finding Mocha's "rc" files.
|
|
5
|
-
* This doesn't have anything to do with `mocha.opts`.
|
|
6
5
|
*
|
|
7
6
|
* @private
|
|
8
7
|
* @module
|
|
@@ -12,6 +11,7 @@ const fs = require('fs');
|
|
|
12
11
|
const path = require('path');
|
|
13
12
|
const debug = require('debug')('mocha:cli:config');
|
|
14
13
|
const findUp = require('find-up');
|
|
14
|
+
const utils = require('../utils');
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* These are the valid config files, in order of precedence;
|
|
@@ -43,11 +43,11 @@ const parsers = (exports.parsers = {
|
|
|
43
43
|
js: filepath => {
|
|
44
44
|
const cwdFilepath = path.resolve(filepath);
|
|
45
45
|
try {
|
|
46
|
-
debug(
|
|
46
|
+
debug('parsers: load using cwd-relative path: "%s"', cwdFilepath);
|
|
47
47
|
return require(cwdFilepath);
|
|
48
48
|
} catch (err) {
|
|
49
49
|
if (isModuleNotFoundError(err)) {
|
|
50
|
-
debug(
|
|
50
|
+
debug('parsers: retry load as module-relative path: "%s"', filepath);
|
|
51
51
|
return require(filepath);
|
|
52
52
|
} else {
|
|
53
53
|
throw err; // rethrow
|
|
@@ -70,7 +70,7 @@ const parsers = (exports.parsers = {
|
|
|
70
70
|
*/
|
|
71
71
|
exports.loadConfig = filepath => {
|
|
72
72
|
let config = {};
|
|
73
|
-
debug(
|
|
73
|
+
debug('loadConfig: trying to parse config at %s', filepath);
|
|
74
74
|
|
|
75
75
|
const ext = path.extname(filepath);
|
|
76
76
|
try {
|
|
@@ -93,10 +93,10 @@ exports.loadConfig = filepath => {
|
|
|
93
93
|
* @param {string} [cwd] - Current working directory
|
|
94
94
|
* @returns {string|null} Filepath to config, if found
|
|
95
95
|
*/
|
|
96
|
-
exports.findConfig = (cwd =
|
|
96
|
+
exports.findConfig = (cwd = utils.cwd()) => {
|
|
97
97
|
const filepath = findUp.sync(exports.CONFIG_FILES, {cwd});
|
|
98
98
|
if (filepath) {
|
|
99
|
-
debug(
|
|
99
|
+
debug('findConfig: found config file %s', filepath);
|
|
100
100
|
}
|
|
101
101
|
return filepath;
|
|
102
102
|
};
|
package/lib/cli/init.js
CHANGED
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
|
|
10
10
|
const fs = require('fs');
|
|
11
11
|
const path = require('path');
|
|
12
|
-
const mkdirp = require('mkdirp');
|
|
13
12
|
|
|
14
13
|
exports.command = 'init <path>';
|
|
15
14
|
|
|
@@ -24,7 +23,7 @@ exports.builder = yargs =>
|
|
|
24
23
|
exports.handler = argv => {
|
|
25
24
|
const destdir = argv.path;
|
|
26
25
|
const srcdir = path.join(__dirname, '..', '..');
|
|
27
|
-
|
|
26
|
+
fs.mkdirSync(destdir, {recursive: true});
|
|
28
27
|
const css = fs.readFileSync(path.join(srcdir, 'mocha.css'));
|
|
29
28
|
const js = fs.readFileSync(path.join(srcdir, 'mocha.js'));
|
|
30
29
|
const tmpl = fs.readFileSync(
|