mocha-compat 3.6.5 → 10.8.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/LICENSE +1 -1
- package/README.md +61 -110
- package/bin/_mocha +10 -0
- package/bin/mocha.js +142 -0
- package/browser-entry.js +61 -22
- package/lib/browser/highlight-tags.js +39 -0
- package/lib/browser/parse-query.js +24 -0
- package/lib/{template.html → browser/template.html} +7 -5
- package/lib/cli/cli.js +89 -0
- package/lib/cli/collect-files.js +137 -0
- package/lib/cli/commands.js +14 -0
- package/lib/cli/config.js +100 -0
- package/lib/cli/index.js +3 -0
- package/lib/cli/init.js +36 -0
- package/lib/cli/lookup-files.js +150 -0
- package/lib/cli/node-flags.js +85 -0
- package/lib/cli/one-and-dones.js +69 -0
- package/lib/cli/options.js +284 -0
- package/lib/cli/run-helpers.js +304 -0
- package/lib/cli/run-option-metadata.js +116 -0
- package/lib/cli/run.js +380 -0
- package/lib/cli/watch-run.js +377 -0
- package/lib/context.js +16 -42
- package/lib/errors.js +563 -0
- package/lib/hook.js +50 -9
- package/lib/interfaces/bdd.js +28 -29
- package/lib/interfaces/common.js +56 -21
- package/lib/interfaces/exports.js +4 -7
- package/lib/interfaces/qunit.js +10 -11
- package/lib/interfaces/tdd.js +15 -15
- package/lib/mocha.js +1073 -292
- package/lib/mocharc.json +10 -0
- package/lib/nodejs/buffered-worker-pool.js +188 -0
- package/lib/nodejs/esm-utils.js +106 -0
- package/lib/nodejs/file-unloader.js +15 -0
- package/lib/nodejs/parallel-buffered-runner.js +433 -0
- package/lib/nodejs/reporters/parallel-buffered.js +165 -0
- package/lib/nodejs/serializer.js +414 -0
- package/lib/nodejs/worker.js +151 -0
- package/lib/pending.js +3 -3
- package/lib/plugin-loader.js +286 -0
- package/lib/reporters/base.js +305 -205
- package/lib/reporters/doc.js +52 -21
- package/lib/reporters/dot.js +31 -18
- package/lib/reporters/html.js +153 -81
- package/lib/reporters/json-stream.js +53 -24
- package/lib/reporters/json.js +88 -18
- package/lib/reporters/landing.js +38 -16
- package/lib/reporters/list.js +34 -19
- package/lib/reporters/markdown.js +28 -15
- package/lib/reporters/min.js +22 -8
- package/lib/reporters/nyan.js +62 -58
- package/lib/reporters/progress.js +32 -19
- package/lib/reporters/spec.js +41 -23
- package/lib/reporters/tap.js +255 -32
- package/lib/reporters/xunit.js +89 -39
- package/lib/runnable.js +233 -148
- package/lib/runner.js +679 -380
- package/lib/stats-collector.js +83 -0
- package/lib/suite.js +376 -112
- package/lib/test.js +82 -21
- package/lib/utils.js +364 -477
- package/mocha.css +183 -54
- package/mocha.js +19319 -19984
- package/mocha.js.map +1 -0
- package/package.json +164 -332
- package/vendor/glob/README.md +8 -396
- package/vendor/glob/common.js +1 -1
- package/vendor/glob/glob.js +3 -1
- package/vendor/glob/package.json +1 -27
- package/vendor/glob/sync.js +1 -1
- package/vendor/inflight/README.md +7 -34
- package/vendor/inflight/package.json +1 -10
- package/{lib/to-iso-string → vendor/serialize-javascript}/LICENSE +8 -6
- package/vendor/serialize-javascript/README.md +10 -0
- package/vendor/serialize-javascript/index.js +349 -0
- package/bin/_mocha-compat +0 -572
- package/bin/mocha-compat +0 -87
- package/bin/options.js +0 -41
- package/lib/browser/debug.js +0 -7
- package/lib/browser/events.js +0 -195
- package/lib/browser/progress.js +0 -119
- package/lib/browser/tty.js +0 -13
- package/lib/ms.js +0 -130
- package/lib/to-iso-string/index.js +0 -37
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
(The MIT License)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2011-
|
|
3
|
+
Copyright (c) 2011-2024 OpenJS Foundation and contributors, https://openjsf.org
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
a copy of this software and associated documentation files (the
|
package/README.md
CHANGED
|
@@ -1,137 +1,88 @@
|
|
|
1
|
-
|
|
1
|
+
## mocha-compat
|
|
2
2
|
|
|
3
|
-
This is mocha-compat
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
This is `mocha-compat`, the 10.x line: a fork of mocha 10.8.2 with `serialize-javascript`
|
|
4
|
+
vendored (carrying the 7.1.1 fixes) so `npm audit --omit=dev` is clean, for Node 12.17
|
|
5
|
+
through 26. Install it as an alias next to `mocha`:
|
|
6
|
+
|
|
7
|
+
"mocha-compat-10": "npm:mocha-compat@^10"
|
|
8
|
+
|
|
9
|
+
Its bins are `mocha-compat-10` and `_mocha-compat-10`. A 3.x line also exists, on the
|
|
10
|
+
`support/3.x` branch, installed as `"mocha-compat-3": "npm:mocha-compat@^3.6.4"` for Node
|
|
11
|
+
0.10 through 26. Repo: <https://github.com/kmalakoff/mocha-compat>.
|
|
9
12
|
|
|
10
13
|
---
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
<p align="center">
|
|
16
|
+
<img src="assets/mocha-logo.svg" alt="Mocha test framework logo"/>
|
|
17
|
+
</p>
|
|
13
18
|
|
|
14
|
-
|
|
19
|
+
<p align="center">☕️ Simple, flexible, fun JavaScript test framework for Node.js & The Browser ☕️</p>
|
|
15
20
|
|
|
16
|
-
|
|
21
|
+
<div align="center">
|
|
17
22
|
|
|
18
|
-
|
|
23
|
+
<a href="https://www.npmjs.com/package/mocha"><img src="https://img.shields.io/npm/v/mocha.svg" alt="NPM Version"></a>
|
|
24
|
+
<a href="https://github.com/mochajs/mocha"><img src="https://img.shields.io/node/v/mocha.svg" alt="Node Version"></a>
|
|
25
|
+
[](https://github.com/mochajs/mocha/actions/workflows/mocha.yml)
|
|
26
|
+
<a href="https://coveralls.io/github/mochajs/mocha"><img src="https://coveralls.io/repos/github/mochajs/mocha/badge.svg" alt="Coverage Status"></a>
|
|
19
27
|
|
|
20
|
-
|
|
28
|
+
</div>
|
|
21
29
|
|
|
22
|
-
|
|
30
|
+
<div align="center">
|
|
23
31
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
- ~~Filesystem-based reporters must be tested in Node.js context~~
|
|
29
|
-
- **UPDATE - May 24 2017**: Thanks to [community contributions](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#mag-coverage), the coverage on most reporters has increased dramatically! The `html` reporter is still in [dire need of coverage](https://coveralls.io/builds/11674428/source?filename=lib%2Freporters%2Fhtml.js).
|
|
30
|
-
- Increase coverage against all interfaces (`exports` in particular). Ideally this becomes a "matrix" where we repeat sets of integration tests across all interfaces.
|
|
31
|
-
- Refactor non-Node.js-specific tests to allow them to run in a browser context. Node.js-specific tests include those which *require* the CLI or filesystem. Most everything else is fair game.
|
|
32
|
-
2. Review current open pull requests
|
|
33
|
-
- We need individuals familiar with Mocha's codebase. Got questions? Ask them in [our chat room](https://gitter.im/mochajs/mocha).
|
|
34
|
-
- Pull requests **must** have supporting tests. The only exceptions are pure cosmetic or non-functional changes.
|
|
35
|
-
- Pull request contributors must sign the CLA.
|
|
36
|
-
3. Close old, inactive issues and pull requests
|
|
37
|
-
- ~~A bot should do this. We need a bot. Got a bot?~~ We now use GitHub's own [probot-stale](https://www.npmjs.com/package/probot-stale).
|
|
38
|
-
4. Triage issues
|
|
39
|
-
- If we run into "critical" bugs, they need fixing.
|
|
40
|
-
- "Critical" means Mocha is broken w/o workarounds for a *large percentage* of users
|
|
41
|
-
- Otherwise: respond to issues, close new dupe issues, confirm bugs, ask for more info, etc.
|
|
32
|
+
<a href="https://discord.gg/KeDn2uXhER"><img alt="Chat - Discord" src="https://img.shields.io/badge/Chat-Discord-5765F2.svg" /></a>
|
|
33
|
+
<a href="https://github.com/mochajs/mocha#sponsors"><img src="https://opencollective.com/mochajs/tiers/sponsors/badge.svg" alt="OpenCollective Sponsors"></a>
|
|
34
|
+
<a href="https://github.com/mochajs/mocha#backers"><img src="https://opencollective.com/mochajs/tiers/backers/badge.svg" alt="OpenCollective Backers"></a>
|
|
35
|
+
[](https://github.com/collective-funds/guidelines)
|
|
42
36
|
|
|
43
|
-
|
|
37
|
+
</div>
|
|
44
38
|
|
|
45
|
-
|
|
39
|
+
## Links
|
|
46
40
|
|
|
47
|
-
|
|
41
|
+
- **[Documentation](https://mochajs.org)**
|
|
42
|
+
- **[Release Notes / History / Changes](https://github.com/mochajs/mocha/blob/main/CHANGELOG.md)**
|
|
43
|
+
- [Code of Conduct](https://github.com/mochajs/mocha/blob/main/.github/CODE_OF_CONDUCT.md)
|
|
44
|
+
- [Contributing](https://github.com/mochajs/mocha/blob/main/.github/CONTRIBUTING.md)
|
|
45
|
+
- [Development](https://github.com/mochajs/mocha/blob/main/.github/DEVELOPMENT.md)
|
|
46
|
+
- [Discord](https://discord.gg/KeDn2uXhER) (ask questions here!)
|
|
47
|
+
- [Issue Tracker](https://github.com/mochajs/mocha/issues)
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
<p align="center">
|
|
51
|
-
<img src="https://cldup.com/xFVFxOioAU.svg" alt="Mocha test framework"/>
|
|
52
|
-
</p>
|
|
49
|
+
## Backers
|
|
53
50
|
|
|
54
|
-
[
|
|
55
|
-
[](https://coveralls.io/github/mochajs/mocha)
|
|
56
|
-
[](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmochajs%2Fmocha?ref=badge_shield)
|
|
57
|
-
[](https://gitter.im/mochajs/mocha?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
58
|
-
[](#backers)
|
|
59
|
-
[](#sponsors)
|
|
60
|
-
<br><img alt="Mocha Browser Support h/t SauceLabs" src="https://saucelabs.com/browser-matrix/mochajs.svg" width="354">
|
|
51
|
+
[Become a backer](https://opencollective.com/mochajs) and show your support to our open source project on [our site](https://mochajs.org/#backers).
|
|
61
52
|
|
|
62
|
-
|
|
53
|
+
<a href="https://opencollective.com/mochajs"><img src="https://opencollective.com/mochajs/tiers/backers.svg?limit=30&button=false&avatarHeight=46&width=750"></a>
|
|
63
54
|
|
|
64
|
-
##
|
|
55
|
+
## Sponsors
|
|
65
56
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
57
|
+
Does your company use Mocha? Ask your manager or marketing team if your company would be interested in supporting our project.
|
|
58
|
+
Support will allow the maintainers to dedicate more time for maintenance and new features for everyone.
|
|
59
|
+
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?
|
|
60
|
+
[Here's the info](https://opencollective.com/mochajs).
|
|
70
61
|
|
|
62
|
+
[](https://opencollective.com/mochajs/tiers/sponsors/0/website)
|
|
63
|
+
[](https://opencollective.com/mochajs/tiers/sponsors/1/website)
|
|
64
|
+
[](https://opencollective.com/mochajs/tiers/sponsors/2/website)
|
|
65
|
+
[](https://opencollective.com/mochajs/tiers/sponsors/3/website)
|
|
71
66
|
|
|
72
|
-
##
|
|
67
|
+
## Development
|
|
73
68
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
<a href="https://opencollective.com/mochajs/backer/0/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/0/avatar"></a>
|
|
77
|
-
<a href="https://opencollective.com/mochajs/backer/1/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/1/avatar"></a>
|
|
78
|
-
<a href="https://opencollective.com/mochajs/backer/2/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/2/avatar"></a>
|
|
79
|
-
<a href="https://opencollective.com/mochajs/backer/3/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/3/avatar"></a>
|
|
80
|
-
<a href="https://opencollective.com/mochajs/backer/4/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/4/avatar"></a>
|
|
81
|
-
<a href="https://opencollective.com/mochajs/backer/5/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/5/avatar"></a>
|
|
82
|
-
<a href="https://opencollective.com/mochajs/backer/6/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/6/avatar"></a>
|
|
83
|
-
<a href="https://opencollective.com/mochajs/backer/7/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/7/avatar"></a>
|
|
84
|
-
<a href="https://opencollective.com/mochajs/backer/8/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/8/avatar"></a>
|
|
85
|
-
<a href="https://opencollective.com/mochajs/backer/9/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/9/avatar"></a>
|
|
86
|
-
<a href="https://opencollective.com/mochajs/backer/10/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/10/avatar"></a>
|
|
87
|
-
<a href="https://opencollective.com/mochajs/backer/11/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/11/avatar"></a>
|
|
88
|
-
<a href="https://opencollective.com/mochajs/backer/12/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/12/avatar"></a>
|
|
89
|
-
<a href="https://opencollective.com/mochajs/backer/13/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/13/avatar"></a>
|
|
90
|
-
<a href="https://opencollective.com/mochajs/backer/14/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/14/avatar"></a>
|
|
91
|
-
<a href="https://opencollective.com/mochajs/backer/15/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/15/avatar"></a>
|
|
92
|
-
<a href="https://opencollective.com/mochajs/backer/16/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/16/avatar"></a>
|
|
93
|
-
<a href="https://opencollective.com/mochajs/backer/17/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/17/avatar"></a>
|
|
94
|
-
<a href="https://opencollective.com/mochajs/backer/18/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/18/avatar"></a>
|
|
95
|
-
<a href="https://opencollective.com/mochajs/backer/19/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/19/avatar"></a>
|
|
96
|
-
<a href="https://opencollective.com/mochajs/backer/20/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/20/avatar"></a>
|
|
97
|
-
<a href="https://opencollective.com/mochajs/backer/21/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/21/avatar"></a>
|
|
98
|
-
<a href="https://opencollective.com/mochajs/backer/22/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/22/avatar"></a>
|
|
99
|
-
<a href="https://opencollective.com/mochajs/backer/23/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/23/avatar"></a>
|
|
100
|
-
<a href="https://opencollective.com/mochajs/backer/24/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/24/avatar"></a>
|
|
101
|
-
<a href="https://opencollective.com/mochajs/backer/25/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/25/avatar"></a>
|
|
102
|
-
<a href="https://opencollective.com/mochajs/backer/26/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/26/avatar"></a>
|
|
103
|
-
<a href="https://opencollective.com/mochajs/backer/27/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/27/avatar"></a>
|
|
104
|
-
<a href="https://opencollective.com/mochajs/backer/28/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/28/avatar"></a>
|
|
105
|
-
<a href="https://opencollective.com/mochajs/backer/29/website" target="_blank"><img src="https://opencollective.com/mochajs/backer/29/avatar"></a>
|
|
69
|
+
You might want to know that:
|
|
106
70
|
|
|
71
|
+
- 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
|
|
72
|
+
- Mocha is an _independent_ open-source project, maintained exclusively by volunteers.
|
|
107
73
|
|
|
108
|
-
|
|
74
|
+
You might want to help:
|
|
109
75
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
<a href="https://opencollective.com/mochajs/sponsor/1/website" target="_blank"><img src="https://opencollective.com/mochajs/sponsor/1/avatar"></a>
|
|
114
|
-
<a href="https://opencollective.com/mochajs/sponsor/2/website" target="_blank"><img src="https://opencollective.com/mochajs/sponsor/2/avatar"></a>
|
|
115
|
-
<a href="https://opencollective.com/mochajs/sponsor/3/website" target="_blank"><img src="https://opencollective.com/mochajs/sponsor/3/avatar"></a>
|
|
116
|
-
<a href="https://opencollective.com/mochajs/sponsor/4/website" target="_blank"><img src="https://opencollective.com/mochajs/sponsor/4/avatar"></a>
|
|
117
|
-
<a href="https://opencollective.com/mochajs/sponsor/5/website" target="_blank"><img src="https://opencollective.com/mochajs/sponsor/5/avatar"></a>
|
|
118
|
-
<a href="https://opencollective.com/mochajs/sponsor/6/website" target="_blank"><img src="https://opencollective.com/mochajs/sponsor/6/avatar"></a>
|
|
119
|
-
<a href="https://opencollective.com/mochajs/sponsor/7/website" target="_blank"><img src="https://opencollective.com/mochajs/sponsor/7/avatar"></a>
|
|
120
|
-
<a href="https://opencollective.com/mochajs/sponsor/8/website" target="_blank"><img src="https://opencollective.com/mochajs/sponsor/8/avatar"></a>
|
|
121
|
-
<a href="https://opencollective.com/mochajs/sponsor/9/website" target="_blank"><img src="https://opencollective.com/mochajs/sponsor/9/avatar"></a>
|
|
122
|
-
<a href="https://opencollective.com/mochajs/sponsor/10/website" target="_blank"><img src="https://opencollective.com/mochajs/sponsor/10/avatar"></a>
|
|
123
|
-
<a href="https://opencollective.com/mochajs/sponsor/11/website" target="_blank"><img src="https://opencollective.com/mochajs/sponsor/11/avatar"></a>
|
|
124
|
-
<a href="https://opencollective.com/mochajs/sponsor/12/website" target="_blank"><img src="https://opencollective.com/mochajs/sponsor/12/avatar"></a>
|
|
125
|
-
<a href="https://opencollective.com/mochajs/sponsor/13/website" target="_blank"><img src="https://opencollective.com/mochajs/sponsor/13/avatar"></a>
|
|
126
|
-
<a href="https://opencollective.com/mochajs/sponsor/14/website" target="_blank"><img src="https://opencollective.com/mochajs/sponsor/14/avatar"></a>
|
|
127
|
-
<a href="https://opencollective.com/mochajs/sponsor/15/website" target="_blank"><img src="https://opencollective.com/mochajs/sponsor/15/avatar"></a>
|
|
128
|
-
<a href="https://opencollective.com/mochajs/sponsor/16/website" target="_blank"><img src="https://opencollective.com/mochajs/sponsor/16/avatar"></a>
|
|
129
|
-
<a href="https://opencollective.com/mochajs/sponsor/17/website" target="_blank"><img src="https://opencollective.com/mochajs/sponsor/17/avatar"></a>
|
|
130
|
-
<a href="https://opencollective.com/mochajs/sponsor/18/website" target="_blank"><img src="https://opencollective.com/mochajs/sponsor/18/avatar"></a>
|
|
131
|
-
<a href="https://opencollective.com/mochajs/sponsor/19/website" target="_blank"><img src="https://opencollective.com/mochajs/sponsor/19/avatar"></a>
|
|
76
|
+
- New to contributing to Mocha? Check out this list of [good first issues](https://github.com/mochajs/mocha/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22)
|
|
77
|
+
- Mocha could use a hand with [these issues](https://github.com/mochajs/mocha/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
|
|
78
|
+
- The [maintainer's handbook](https://github.com/mochajs/mocha/blob/main/MAINTAINERS.md) explains how things get done
|
|
132
79
|
|
|
133
|
-
|
|
80
|
+
Finally, come [chat with the maintainers on Discord](https://discord.gg/KeDn2uXhER) if you want to help with:
|
|
81
|
+
|
|
82
|
+
- Triaging issues, answering questions
|
|
83
|
+
- Review, merging, and closing pull requests
|
|
84
|
+
- Other project-maintenance-y things
|
|
134
85
|
|
|
135
|
-
|
|
86
|
+
## License
|
|
136
87
|
|
|
137
|
-
[
|
|
88
|
+
Copyright 2011-2024 OpenJS Foundation and contributors. Licensed [MIT](https://github.com/mochajs/mocha/blob/main/LICENSE).
|
package/bin/_mocha
ADDED
package/bin/mocha.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This wrapper executable checks for known node flags and appends them when found,
|
|
7
|
+
* before invoking the "real" executable (`lib/cli/cli.js`)
|
|
8
|
+
*
|
|
9
|
+
* @module bin/mocha
|
|
10
|
+
* @private
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const {loadOptions} = require('../lib/cli/options');
|
|
14
|
+
const {
|
|
15
|
+
unparseNodeFlags,
|
|
16
|
+
isNodeFlag,
|
|
17
|
+
impliesNoTimeouts
|
|
18
|
+
} = require('../lib/cli/node-flags');
|
|
19
|
+
const unparse = require('yargs-unparser');
|
|
20
|
+
const debug = require('debug')('mocha:cli:mocha');
|
|
21
|
+
const {aliases} = require('../lib/cli/run-option-metadata');
|
|
22
|
+
|
|
23
|
+
const mochaArgs = {};
|
|
24
|
+
const nodeArgs = {};
|
|
25
|
+
let hasInspect = false;
|
|
26
|
+
|
|
27
|
+
const opts = loadOptions(process.argv.slice(2));
|
|
28
|
+
debug('loaded opts', opts);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Given option/command `value`, disable timeouts if applicable
|
|
32
|
+
* @param {string} [value] - Value to check
|
|
33
|
+
* @ignore
|
|
34
|
+
*/
|
|
35
|
+
const disableTimeouts = value => {
|
|
36
|
+
if (impliesNoTimeouts(value)) {
|
|
37
|
+
debug('option %s disabled timeouts', value);
|
|
38
|
+
mochaArgs.timeout = 0;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* If `value` begins with `v8-` and is not explicitly `v8-options`, remove prefix
|
|
44
|
+
* @param {string} [value] - Value to check
|
|
45
|
+
* @returns {string} `value` with prefix (maybe) removed
|
|
46
|
+
* @ignore
|
|
47
|
+
*/
|
|
48
|
+
const trimV8Option = value =>
|
|
49
|
+
value !== 'v8-options' && /^v8-/.test(value) ? value.slice(3) : value;
|
|
50
|
+
|
|
51
|
+
// sort options into "node" and "mocha" buckets
|
|
52
|
+
Object.keys(opts).forEach(opt => {
|
|
53
|
+
if (isNodeFlag(opt)) {
|
|
54
|
+
nodeArgs[trimV8Option(opt)] = opts[opt];
|
|
55
|
+
} else {
|
|
56
|
+
mochaArgs[opt] = opts[opt];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// disable 'timeout' for debugFlags
|
|
61
|
+
Object.keys(nodeArgs).forEach(opt => disableTimeouts(opt));
|
|
62
|
+
mochaArgs['node-option'] &&
|
|
63
|
+
mochaArgs['node-option'].forEach(opt => disableTimeouts(opt));
|
|
64
|
+
|
|
65
|
+
// Native debugger handling
|
|
66
|
+
// see https://nodejs.org/api/debugger.html#debugger_debugger
|
|
67
|
+
// look for 'inspect' that would launch this debugger,
|
|
68
|
+
// remove it from Mocha's opts and prepend it to Node's opts.
|
|
69
|
+
// A deprecation warning will be printed by node, if applicable.
|
|
70
|
+
// (mochaArgs._ are "positional" arguments, not prefixed with - or --)
|
|
71
|
+
if (mochaArgs._) {
|
|
72
|
+
const i = mochaArgs._.findIndex(val => val === 'inspect');
|
|
73
|
+
if (i > -1) {
|
|
74
|
+
mochaArgs._.splice(i, 1);
|
|
75
|
+
disableTimeouts('inspect');
|
|
76
|
+
hasInspect = true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (mochaArgs['node-option'] || Object.keys(nodeArgs).length || hasInspect) {
|
|
81
|
+
const {spawn} = require('child_process');
|
|
82
|
+
const mochaPath = require.resolve('../lib/cli/cli.js');
|
|
83
|
+
|
|
84
|
+
const nodeArgv =
|
|
85
|
+
(mochaArgs['node-option'] && mochaArgs['node-option'].map(v => '--' + v)) ||
|
|
86
|
+
unparseNodeFlags(nodeArgs);
|
|
87
|
+
|
|
88
|
+
if (hasInspect) nodeArgv.unshift('inspect');
|
|
89
|
+
delete mochaArgs['node-option'];
|
|
90
|
+
|
|
91
|
+
debug('final node argv', nodeArgv);
|
|
92
|
+
|
|
93
|
+
const args = [].concat(
|
|
94
|
+
nodeArgv,
|
|
95
|
+
mochaPath,
|
|
96
|
+
unparse(mochaArgs, {alias: aliases})
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
debug(
|
|
100
|
+
'forking child process via command: %s %s',
|
|
101
|
+
process.execPath,
|
|
102
|
+
args.join(' ')
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const proc = spawn(process.execPath, args, {
|
|
106
|
+
stdio: 'inherit'
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
proc.on('exit', (code, signal) => {
|
|
110
|
+
process.on('exit', () => {
|
|
111
|
+
if (signal) {
|
|
112
|
+
process.kill(process.pid, signal);
|
|
113
|
+
} else {
|
|
114
|
+
process.exit(code);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// terminate children.
|
|
120
|
+
process.on('SIGINT', () => {
|
|
121
|
+
// XXX: a previous comment said this would abort the runner, but I can't see that it does
|
|
122
|
+
// anything with the default runner.
|
|
123
|
+
debug('main process caught SIGINT');
|
|
124
|
+
proc.kill('SIGINT');
|
|
125
|
+
// if running in parallel mode, we will have a proper SIGINT handler, so the below won't
|
|
126
|
+
// be needed.
|
|
127
|
+
if (!args.parallel || args.jobs < 2) {
|
|
128
|
+
// win32 does not support SIGTERM, so use next best thing.
|
|
129
|
+
if (require('os').platform() === 'win32') {
|
|
130
|
+
proc.kill('SIGKILL');
|
|
131
|
+
} else {
|
|
132
|
+
// using SIGKILL won't cleanly close the output streams, which can result
|
|
133
|
+
// in cut-off text or a befouled terminal.
|
|
134
|
+
debug('sending SIGTERM to child process');
|
|
135
|
+
proc.kill('SIGTERM');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
} else {
|
|
140
|
+
debug('running Mocha in-process');
|
|
141
|
+
require('../lib/cli/cli').main([], mochaArgs);
|
|
142
|
+
}
|
package/browser-entry.js
CHANGED
|
@@ -7,8 +7,10 @@
|
|
|
7
7
|
* Shim process.stdout.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
process.stdout = require('browser-stdout')();
|
|
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
|
/**
|
|
@@ -17,7 +19,7 @@ var Mocha = require('./lib/mocha');
|
|
|
17
19
|
* @return {undefined}
|
|
18
20
|
*/
|
|
19
21
|
|
|
20
|
-
var mocha = new Mocha({
|
|
22
|
+
var mocha = new Mocha({reporter: 'html'});
|
|
21
23
|
|
|
22
24
|
/**
|
|
23
25
|
* Save timer references to avoid Sinon interfering (see GH-237).
|
|
@@ -45,27 +47,45 @@ process.removeListener = function (e, fn) {
|
|
|
45
47
|
} else {
|
|
46
48
|
global.onerror = function () {};
|
|
47
49
|
}
|
|
48
|
-
var i =
|
|
50
|
+
var i = uncaughtExceptionHandlers.indexOf(fn);
|
|
49
51
|
if (i !== -1) {
|
|
50
52
|
uncaughtExceptionHandlers.splice(i, 1);
|
|
51
53
|
}
|
|
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
|
*/
|
|
58
71
|
|
|
59
72
|
process.on = function (e, fn) {
|
|
60
73
|
if (e === 'uncaughtException') {
|
|
61
|
-
global.onerror = function (
|
|
62
|
-
fn(new Error(
|
|
63
|
-
return !mocha.allowUncaught;
|
|
74
|
+
global.onerror = function (msg, url, line, col, err) {
|
|
75
|
+
fn(err || new Error(msg + ' (' + url + ':' + line + ':' + col + ')'));
|
|
76
|
+
return !mocha.options.allowUncaught;
|
|
64
77
|
};
|
|
65
78
|
uncaughtExceptionHandlers.push(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.
|
|
@@ -74,9 +94,9 @@ mocha.suite.removeAllListeners('pre-require');
|
|
|
74
94
|
var immediateQueue = [];
|
|
75
95
|
var immediateTimeout;
|
|
76
96
|
|
|
77
|
-
function timeslice
|
|
97
|
+
function timeslice() {
|
|
78
98
|
var immediateStart = new Date().getTime();
|
|
79
|
-
while (immediateQueue.length &&
|
|
99
|
+
while (immediateQueue.length && new Date().getTime() - immediateStart < 100) {
|
|
80
100
|
immediateQueue.shift()();
|
|
81
101
|
}
|
|
82
102
|
if (immediateQueue.length) {
|
|
@@ -103,7 +123,7 @@ Mocha.Runner.immediately = function (callback) {
|
|
|
103
123
|
* only receive the 'message' attribute of the Error.
|
|
104
124
|
*/
|
|
105
125
|
mocha.throwError = function (err) {
|
|
106
|
-
|
|
126
|
+
uncaughtExceptionHandlers.forEach(function (fn) {
|
|
107
127
|
fn(err);
|
|
108
128
|
});
|
|
109
129
|
throw err;
|
|
@@ -126,13 +146,21 @@ mocha.ui = function (ui) {
|
|
|
126
146
|
|
|
127
147
|
mocha.setup = function (opts) {
|
|
128
148
|
if (typeof opts === 'string') {
|
|
129
|
-
opts = {
|
|
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
|
}
|
|
@@ -158,8 +186,12 @@ mocha.run = function (fn) {
|
|
|
158
186
|
return Mocha.prototype.run.call(mocha, function (err) {
|
|
159
187
|
// The DOM Document is not available in Web Workers.
|
|
160
188
|
var document = global.document;
|
|
161
|
-
if (
|
|
162
|
-
|
|
189
|
+
if (
|
|
190
|
+
document &&
|
|
191
|
+
document.getElementById('mocha') &&
|
|
192
|
+
options.noHighlighting !== true
|
|
193
|
+
) {
|
|
194
|
+
highlightTags('code');
|
|
163
195
|
}
|
|
164
196
|
if (fn) {
|
|
165
197
|
fn(err);
|
|
@@ -177,11 +209,18 @@ Mocha.process = process;
|
|
|
177
209
|
/**
|
|
178
210
|
* Expose mocha.
|
|
179
211
|
*/
|
|
180
|
-
|
|
181
212
|
global.Mocha = Mocha;
|
|
182
213
|
global.mocha = mocha;
|
|
183
214
|
|
|
184
|
-
//
|
|
185
|
-
//
|
|
186
|
-
//
|
|
187
|
-
|
|
215
|
+
// for bundlers: enable `import {describe, it} from 'mocha'`
|
|
216
|
+
// `bdd` interface only
|
|
217
|
+
// prettier-ignore
|
|
218
|
+
[
|
|
219
|
+
'describe', 'context', 'it', 'specify',
|
|
220
|
+
'xdescribe', 'xcontext', 'xit', 'xspecify',
|
|
221
|
+
'before', 'beforeEach', 'afterEach', 'after'
|
|
222
|
+
].forEach(function(key) {
|
|
223
|
+
mocha[key] = global[key];
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
module.exports = mocha;
|
|
@@ -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
|
+
};
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
2
|
+
<html lang="en">
|
|
3
3
|
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
4
5
|
<title>Mocha</title>
|
|
5
|
-
<meta
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
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>
|