Moved
This commit is contained in:
960
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/CHANGELOG.md
generated
vendored
Normal file
960
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/CHANGELOG.md
generated
vendored
Normal file
@ -0,0 +1,960 @@
|
||||
# 9.0.0 / 2021-06-07
|
||||
|
||||
## :boom: Breaking Changes
|
||||
|
||||
- [#4633](https://github.com/mochajs/mocha/issues/4633): **Drop Node.js v10.x support** ([**@juergba**](https://github.com/juergba))
|
||||
|
||||
- [#4635](https://github.com/mochajs/mocha/issues/4635): `import`-first loading of test files ([**@giltayar**](https://github.com/giltayar))
|
||||
|
||||
**Mocha is going ESM-first!** This means that it will now use ESM `import(test_file)` to load the test files, instead of the CommonJS `require(test_file)`. This is not a problem, as `import` can also load most files that `require` does. In the rare cases where this fails, it will fallback to `require(...)`. This ESM-first approach is the next step in Mocha's ESM migration, and allows ESM loaders to load and transform the test file.
|
||||
|
||||
- [#4636](https://github.com/mochajs/mocha/issues/4636): Remove deprecated `utils.lookupFiles()` ([**@juergba**](https://github.com/juergba))
|
||||
|
||||
- [#4638](https://github.com/mochajs/mocha/issues/4638): Limit the size of `actual`/`expected` for `diff` generation ([**@juergba**](https://github.com/juergba))
|
||||
|
||||
- [#4389](https://github.com/mochajs/mocha/issues/4389): Refactoring: Consuming log-symbols alternate to code for win32 in reporters/base ([**@MoonSupport**](https://github.com/MoonSupport))
|
||||
|
||||
## :tada: Enhancements
|
||||
|
||||
- [#4640](https://github.com/mochajs/mocha/issues/4640): Add new option `--dry-run` ([**@juergba**](https://github.com/juergba))
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#4128](https://github.com/mochajs/mocha/issues/4128): Fix: control stringification of error message ([**@syeutyu**](https://github.com/syeutyu))
|
||||
|
||||
## :nut_and_bolt: Other
|
||||
|
||||
- [#4646](https://github.com/mochajs/mocha/issues/4646): Deprecate `Runner(suite: Suite, delay: boolean)` signature ([**@juergba**](https://github.com/juergba))
|
||||
- [#4643](https://github.com/mochajs/mocha/issues/4643): Update production dependencies ([**@juergba**](https://github.com/juergba))
|
||||
|
||||
# 8.4.0 / 2021-05-07
|
||||
|
||||
## :tada: Enhancements
|
||||
|
||||
- [#4502](https://github.com/mochajs/mocha/issues/4502): CLI file parsing errors now have error codes ([**@evaline-ju**](https://github.com/evaline-ju))
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#4614](https://github.com/mochajs/mocha/issues/4614): Watch: fix crash when reloading files ([**@outsideris**](https://github.com/outsideris))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [#4630](https://github.com/mochajs/mocha/issues/4630): Add `options.require` to Mocha constructor for `root hook` plugins on parallel runs ([**@juergba**](https://github.com/juergba))
|
||||
- [#4617](https://github.com/mochajs/mocha/issues/4617): Dynamically generating tests with `top-level await` and ESM test files ([**@juergba**](https://github.com/juergba))
|
||||
- [#4608](https://github.com/mochajs/mocha/issues/4608): Update default file extensions ([**@outsideris**](https://github.com/outsideris))
|
||||
|
||||
Also thanks to [**@outsideris**](https://github.com/outsideris) for various improvements on our GH actions workflows.
|
||||
|
||||
# 8.3.2 / 2021-03-12
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#4599](https://github.com/mochajs/mocha/issues/4599): Fix regression in `require` interface ([**@alexander-fenster**](https://github.com/alexander-fenster))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [#4601](https://github.com/mochajs/mocha/issues/4601): Add build to GH actions run ([**@christian-bromann**](https://github.com/christian-bromann))
|
||||
- [#4596](https://github.com/mochajs/mocha/issues/4596): Filter active sponsors/backers ([**@juergba**](https://github.com/juergba))
|
||||
- [#4225](https://github.com/mochajs/mocha/issues/4225): Update config file examples ([**@pkuczynski**](https://github.com/pkuczynski))
|
||||
|
||||
# 8.3.1 / 2021-03-06
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#4577](https://github.com/mochajs/mocha/issues/4577): Browser: fix `EvalError` caused by regenerator-runtime ([**@snoack**](https://github.com/snoack))
|
||||
- [#4574](https://github.com/mochajs/mocha/issues/4574): ESM: allow `import` from mocha in parallel mode ([**@nicojs**](https://github.com/nicojs))
|
||||
|
||||
# 8.3.0 / 2021-02-11
|
||||
|
||||
## :tada: Enhancements
|
||||
|
||||
- [#4506](https://github.com/mochajs/mocha/issues/4506): Add error code for test timeout errors ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#4112](https://github.com/mochajs/mocha/issues/4112): Add BigInt support to stringify util function ([**@JosejeSinohui**](https://github.com/JosejeSinohui))
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#4557](https://github.com/mochajs/mocha/issues/4557): Add file location when SyntaxError happens in ESM ([**@giltayar**](https://github.com/giltayar))
|
||||
- [#4521](https://github.com/mochajs/mocha/issues/4521): Fix `require` error when bundling Mocha with Webpack ([**@devhazem**](https://github.com/devhazem))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [#4507](https://github.com/mochajs/mocha/issues/4507): Add support for typescript-style docstrings ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#4503](https://github.com/mochajs/mocha/issues/4503): Add GH Actions workflow status badge ([**@outsideris**](https://github.com/outsideris))
|
||||
- [#4494](https://github.com/mochajs/mocha/issues/4494): Add example of generating tests dynamically with a closure ([**@maxwellgerber**](https://github.com/maxwellgerber))
|
||||
|
||||
## :nut_and_bolt: Other
|
||||
|
||||
- [#4556](https://github.com/mochajs/mocha/issues/4556): Upgrade all dependencies to latest stable ([**@AviVahl**](https://github.com/AviVahl))
|
||||
- [#4543](https://github.com/mochajs/mocha/issues/4543): Update dependencies yargs and yargs-parser ([**@juergba**](https://github.com/juergba))
|
||||
|
||||
Also thanks to [**@outsideris**](https://github.com/outsideris) and [**@HyunSangHan**](https://github.com/HyunSangHan) for various fixes to our website and documentation.
|
||||
|
||||
# 8.2.1 / 2020-11-02
|
||||
|
||||
Fixed stuff.
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#4489](https://github.com/mochajs/mocha/issues/4489): Fix problematic handling of otherwise-unhandled `Promise` rejections and erroneous "`done()` called twice" errors ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#4496](https://github.com/mochajs/mocha/issues/4496): Avoid `MaxListenersExceededWarning` in watch mode ([**@boneskull**](https://github.com/boneskull))
|
||||
|
||||
Also thanks to [**@akeating**](https://github.com/akeating) for a documentation fix!
|
||||
|
||||
# 8.2.0 / 2020-10-16
|
||||
|
||||
The major feature added in v8.2.0 is addition of support for [_global fixtures_](https://mochajs.org/#global-fixtures).
|
||||
|
||||
While Mocha has always had the ability to run setup and teardown via a hook (e.g., a `before()` at the top level of a test file) when running tests in serial, Mocha v8.0.0 added support for parallel runs. Parallel runs are _incompatible_ with this strategy; e.g., a top-level `before()` would only run for the file in which it was defined.
|
||||
|
||||
With [global fixtures](https://mochajs.org/#global-fixtures), Mocha can now perform user-defined setup and teardown _regardless_ of mode, and these fixtures are guaranteed to run _once and only once_. This holds for parallel mode, serial mode, and even "watch" mode (the teardown will run once you hit Ctrl-C, just before Mocha finally exits). Tasks such as starting and stopping servers are well-suited to global fixtures, but not sharing resources--global fixtures do _not_ share context with your test files (but they do share context with each other).
|
||||
|
||||
Here's a short example of usage:
|
||||
|
||||
```js
|
||||
// fixtures.js
|
||||
|
||||
// can be async or not
|
||||
exports.mochaGlobalSetup = async function() {
|
||||
this.server = await startSomeServer({port: process.env.TEST_PORT});
|
||||
console.log(`server running on port ${this.server.port}`);
|
||||
};
|
||||
|
||||
exports.mochaGlobalTeardown = async function() {
|
||||
// the context (`this`) is shared, but not with the test files
|
||||
await this.server.stop();
|
||||
console.log(`server on port ${this.server.port} stopped`);
|
||||
};
|
||||
|
||||
// this file can contain root hook plugins as well!
|
||||
// exports.mochaHooks = { ... }
|
||||
```
|
||||
|
||||
Fixtures are loaded with `--require`, e.g., `mocha --require fixtures.js`.
|
||||
|
||||
For detailed information, please see the [documentation](https://mochajs.org/#global-fixtures) and this handy-dandy [flowchart](https://mochajs.org/#test-fixture-decision-tree-wizard-thing) to help understand the differences between hooks, root hook plugins, and global fixtures (and when you should use each).
|
||||
|
||||
## :tada: Enhancements
|
||||
|
||||
- [#4308](https://github.com/mochajs/mocha/issues/4308): Support run-once [global setup & teardown fixtures](https://mochajs.org/#global-fixtures) ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#4442](https://github.com/mochajs/mocha/issues/4442): Multi-part extensions (e.g., `test.js`) now usable with `--extension` option ([**@jordanstephens**](https://github.com/jordanstephens))
|
||||
- [#4472](https://github.com/mochajs/mocha/issues/4472): Leading dots (e.g., `.js`, `.test.js`) now usable with `--extension` option ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#4434](https://github.com/mochajs/mocha/issues/4434): Output of `json` reporter now contains `speed` ("fast"/"medium"/"slow") property ([**@wwhurin**](https://github.com/wwhurin))
|
||||
- [#4464](https://github.com/mochajs/mocha/issues/4464): Errors thrown by serializer in parallel mode now have error codes ([**@evaline-ju**](https://github.com/evaline-ju))
|
||||
|
||||
_For implementors of custom reporters:_
|
||||
|
||||
- [#4409](https://github.com/mochajs/mocha/issues/4409): Parallel mode and custom reporter improvements ([**@boneskull**](https://github.com/boneskull)):
|
||||
- Support custom worker-process-only reporters (`Runner.prototype.workerReporter()`); reporters should subclass `ParallelBufferedReporter` in `mocha/lib/nodejs/reporters/parallel-buffered`
|
||||
- Allow opt-in of object reference matching for "sufficiently advanced" custom reporters (`Runner.prototype.linkPartialObjects()`); use if strict object equality is needed when consuming `Runner` event data
|
||||
- Enable detection of parallel mode (`Runner.prototype.isParallelMode()`)
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#4476](https://github.com/mochajs/mocha/issues/4476): Workaround for profoundly bizarre issue affecting `npm` v6.x causing some of Mocha's deps to be installed when `mocha` is present in a package's `devDependencies` and `npm install --production` is run the package's working copy ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#4465](https://github.com/mochajs/mocha/issues/4465): Worker processes guaranteed (as opposed to "very likely") to exit before Mocha does; fixes a problem when using `nyc` with Mocha in parallel mode ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#4419](https://github.com/mochajs/mocha/issues/4419): Restore `lookupFiles()` in `mocha/lib/utils`, which was broken/missing in Mocha v8.1.0; it now prints a deprecation warning (use `const {lookupFiles} = require('mocha/lib/cli')` instead) ([**@boneskull**](https://github.com/boneskull))
|
||||
|
||||
Thanks to [**@AviVahl**](https://github.com/AviVahl), [**@donghoon-song**](https://github.com/donghoon-song), [**@ValeriaVG**](https://github.com/ValeriaVG), [**@znarf**](https://github.com/znarf), [**@sujin-park**](https://github.com/sujin-park), and [**@majecty**](https://github.com/majecty) for other helpful contributions!
|
||||
|
||||
# 8.1.3 / 2020-08-28
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#4425](https://github.com/mochajs/mocha/issues/4425): Restore `Mocha.utils.lookupFiles()` and Webpack compatibility (both broken since v8.1.0); `Mocha.utils.lookupFiles()` is now **deprecated** and will be removed in the next major revision of Mocha; use `require('mocha/lib/cli').lookupFiles` instead ([**@boneskull**](https://github.com/boneskull))
|
||||
|
||||
# 8.1.2 / 2020-08-25
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#4418](https://github.com/mochajs/mocha/issues/4418): Fix command-line flag incompatibility in forthcoming Node.js v14.9.0 ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#4401](https://github.com/mochajs/mocha/issues/4401): Fix missing global variable in browser ([**@irrationnelle**](https://github.com/irrationnelle))
|
||||
|
||||
## :lock: Security Fixes
|
||||
|
||||
- [#4396](https://github.com/mochajs/mocha/issues/4396): Update many dependencies ([**@GChuf**](https://github.com/GChuf))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- Various fixes by [**@sujin-park**](https://github.com/sujin-park), [**@wwhurin**](https://github.com/wwhurin) & [**@Donghoon759**](https://github.com/Donghoon759)
|
||||
|
||||
# 8.1.1 / 2020-08-04
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#4394](https://github.com/mochajs/mocha/issues/4394): Fix regression wherein certain reporters did not correctly detect terminal width ([**@boneskull**](https://github.com/boneskull))
|
||||
|
||||
# 8.1.0 / 2020-07-30
|
||||
|
||||
In this release, Mocha now builds its browser bundle with Rollup and Babel, which will provide the project's codebase more flexibility and consistency.
|
||||
|
||||
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=).
|
||||
|
||||
This release **does not** drop support for IE11.
|
||||
|
||||
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!
|
||||
|
||||
> 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).
|
||||
|
||||
## :tada: Enhancements
|
||||
|
||||
- [#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))
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#4328](https://github.com/mochajs/mocha/issues/4328): Fix "watch" mode when Mocha run in parallel ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#4382](https://github.com/mochajs/mocha/issues/4382): Fix root hook execution in "watch" mode ([**@indieisaconcept**](https://github.com/indieisaconcept))
|
||||
- [#4383](https://github.com/mochajs/mocha/issues/4383): Consistent auto-generated hook titles ([**@cspotcode**](https://github.com/cspotcode))
|
||||
- [#4359](https://github.com/mochajs/mocha/issues/4359): Better errors when running `mocha init` ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#4341](https://github.com/mochajs/mocha/issues/4341): Fix weirdness when using `delay` option in browser ([**@craigtaub**](https://github.com/craigtaub))
|
||||
|
||||
## :lock: Security Fixes
|
||||
|
||||
- [#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))
|
||||
- [#4354](https://github.com/mochajs/mocha/issues/4354): Update [yargs-unparser](https://npm.im/yargs-unparser) ([**@martinoppitz**](https://github.com/martinoppitz))
|
||||
|
||||
## :book: Documentation & Website
|
||||
|
||||
- [#4173](https://github.com/mochajs/mocha/issues/4173): Document how to use `--enable-source-maps` with Mocha ([**@bcoe**](https://github.com/bcoe))
|
||||
- [#4343](https://github.com/mochajs/mocha/issues/4343): Clean up some API docs ([**@craigtaub**](https://github.com/craigtaub))
|
||||
- [#4318](https://github.com/mochajs/mocha/issues/4318): Sponsor images are now self-hosted ([**@Munter**](https://github.com/Munter))
|
||||
|
||||
## :nut_and_bolt: Other
|
||||
|
||||
- [#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))
|
||||
|
||||
# 8.0.1 / 2020-06-10
|
||||
|
||||
The obligatory patch after a major.
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#4328](https://github.com/mochajs/mocha/issues/4328): Fix `--parallel` when combined with `--watch` ([**@boneskull**](https://github.com/boneskull))
|
||||
|
||||
# 8.0.0 / 2020-06-10
|
||||
|
||||
In this major release, Mocha adds the ability to _run tests in parallel_. Better late than never! Please note the **breaking changes** detailed below.
|
||||
|
||||
Let's welcome [**@giltayar**](https://github.com/giltayar) and [**@nicojs**](https://github.com/nicojs) to the maintenance team!
|
||||
|
||||
## :boom: Breaking Changes
|
||||
|
||||
- [#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))
|
||||
|
||||
- [#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))
|
||||
|
||||
:sparkles: **WORKAROUND:** Replace `mocha.opts` with a [configuration file](https://mochajs.org/#configuring-mocha-nodejs).
|
||||
|
||||
- [#4260](https://github.com/mochajs/mocha/issues/4260): Remove `enableTimeout()` (`this.enableTimeout()`) from the context object ([**@craigtaub**](https://github.com/craigtaub))
|
||||
|
||||
:sparkles: **WORKAROUND:** Replace usage of `this.enableTimeout(false)` in your tests with `this.timeout(0)`.
|
||||
|
||||
- [#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))
|
||||
|
||||
:sparkles: **WORKAROUND**: Use an array instead (e.g., `"spec": "foo.js,bar.js"` becomes `"spec": ["foo.js", "bar.js"]`).
|
||||
|
||||
- [#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))
|
||||
|
||||
- [#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))
|
||||
|
||||
- [#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))
|
||||
|
||||
- [#4178](https://github.com/mochajs/mocha/issues/4178): Remove previously soft-deprecated APIs ([**@wnghdcjfe**](https://github.com/wnghdcjfe)):
|
||||
|
||||
- `Mocha.prototype.ignoreLeaks()`
|
||||
- `Mocha.prototype.useColors()`
|
||||
- `Mocha.prototype.useInlineDiffs()`
|
||||
- `Mocha.prototype.hideDiff()`
|
||||
|
||||
## :tada: Enhancements
|
||||
|
||||
- [#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))
|
||||
|
||||
: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_
|
||||
|
||||
- [#4304](https://github.com/mochajs/mocha/issues/4304): `--require` now works with ES modules ([**@JacobLey**](https://github.com/JacobLey))
|
||||
|
||||
- [#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))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [#4246](https://github.com/mochajs/mocha/issues/4246): Add documentation for parallel mode and Root Hook plugins ([**@boneskull**](https://github.com/boneskull))
|
||||
|
||||
## :nut_and_bolt: Other
|
||||
|
||||
- [#4200](https://github.com/mochajs/mocha/issues/4200): Drop mkdirp and replace it with fs.mkdirSync ([**@HyunSangHan**](https://github.com/HyunSangHan))
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
(All bug fixes in Mocha v8.0.0 are also breaking changes, and are listed above)
|
||||
|
||||
# 7.2.0 / 2020-05-22
|
||||
|
||||
## :tada: Enhancements
|
||||
|
||||
- [#4234](https://github.com/mochajs/mocha/issues/4234): Add ability to run tests in a mocha instance multiple times ([**@nicojs**](https://github.com/nicojs))
|
||||
- [#4219](https://github.com/mochajs/mocha/issues/4219): Exposing filename in JSON, doc, and json-stream reporters ([**@Daniel0113**](https://github.com/Daniel0113))
|
||||
- [#4244](https://github.com/mochajs/mocha/issues/4244): Add Root Hook Plugins ([**@boneskull**](https://github.com/boneskull))
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#4258](https://github.com/mochajs/mocha/issues/4258): Fix missing dot in name of configuration file ([**@sonicdoe**](https://github.com/sonicdoe))
|
||||
- [#4194](https://github.com/mochajs/mocha/issues/4194): Check if module.paths really exists ([**@ematipico**](https://github.com/ematipico))
|
||||
- [#4256](https://github.com/mochajs/mocha/issues/4256): `--forbid-only` does not recognize `it.only` when `before` crashes ([**@arvidOtt**](https://github.com/arvidOtt))
|
||||
- [#4152](https://github.com/mochajs/mocha/issues/4152): Bug with multiple async done() calls ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#4275](https://github.com/mochajs/mocha/issues/4275): Improper warnings for invalid reporters ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#4288](https://github.com/mochajs/mocha/issues/4288): Broken hook.spec.js test for IE11 ([**@boneskull**](https://github.com/boneskull))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [#4081](https://github.com/mochajs/mocha/issues/4081): Insufficient white space for API docs in view on mobile ([**@HyunSangHan**](https://github.com/HyunSangHan))
|
||||
- [#4255](https://github.com/mochajs/mocha/issues/4255): Update mocha-docdash for UI fixes on API docs ([**@craigtaub**](https://github.com/craigtaub))
|
||||
- [#4235](https://github.com/mochajs/mocha/issues/4235): Enable emoji on website; enable normal ul elements ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#4272](https://github.com/mochajs/mocha/issues/4272): Fetch sponsors at build time, show ALL non-skeevy sponsors ([**@boneskull**](https://github.com/boneskull))
|
||||
|
||||
## :nut_and_bolt: Other
|
||||
|
||||
- [#4249](https://github.com/mochajs/mocha/issues/4249): Refactoring improving encapsulation ([**@arvidOtt**](https://github.com/arvidOtt))
|
||||
- [#4242](https://github.com/mochajs/mocha/issues/4242): CI add job names, add Node.js v14 to matrix ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#4237](https://github.com/mochajs/mocha/issues/4237): Refactor validatePlugins to throw coded errors ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#4236](https://github.com/mochajs/mocha/issues/4236): Better debug output ([**@boneskull**](https://github.com/boneskull))
|
||||
|
||||
# 7.1.2 / 2020-04-26
|
||||
|
||||
## :nut_and_bolt: Other
|
||||
|
||||
- [#4251](https://github.com/mochajs/mocha/issues/4251): Prevent karma-mocha from stalling ([**@juergba**](https://github.com/juergba))
|
||||
- [#4222](https://github.com/mochajs/mocha/issues/4222): Update dependency mkdirp to v0.5.5 ([**@outsideris**](https://github.com/outsideris))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [#4208](https://github.com/mochajs/mocha/issues/4208): Add Wallaby logo to site ([**@boneskull**](https://github.com/boneskull))
|
||||
|
||||
# 7.1.1 / 2020-03-18
|
||||
|
||||
## :lock: Security Fixes
|
||||
|
||||
- [#4204](https://github.com/mochajs/mocha/issues/4204): Update dependencies mkdirp, yargs-parser and yargs ([**@juergba**](https://github.com/juergba))
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#3660](https://github.com/mochajs/mocha/issues/3660): Fix `runner` listening to `start` and `end` events ([**@juergba**](https://github.com/juergba))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [#4190](https://github.com/mochajs/mocha/issues/4190): Show Netlify badge on footer ([**@outsideris**](https://github.com/outsideris))
|
||||
|
||||
# 7.1.0 / 2020-02-26
|
||||
|
||||
## :tada: Enhancements
|
||||
|
||||
[#4038](https://github.com/mochajs/mocha/issues/4038): Add Node.js native ESM support ([**@giltayar**](https://github.com/giltayar))
|
||||
|
||||
Mocha supports writing your test files as ES modules:
|
||||
|
||||
- Node.js only v12.11.0 and above
|
||||
- Node.js below v13.2.0, you must set `--experimental-modules` option
|
||||
- current limitations: please check our [documentation](https://mochajs.org/#nodejs-native-esm-support)
|
||||
- for programmatic usage: see [API: loadFilesAsync()](https://mochajs.org/api/mocha#loadFilesAsync)
|
||||
|
||||
**Note:** Node.JS native [ECMAScript Modules](https://nodejs.org/api/esm.html) implementation has status: **Stability: 1 - Experimental**
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#4181](https://github.com/mochajs/mocha/issues/4181): Programmatic API cannot access retried test objects ([**@juergba**](https://github.com/juergba))
|
||||
- [#4174](https://github.com/mochajs/mocha/issues/4174): Browser: fix `allowUncaught` option ([**@juergba**](https://github.com/juergba))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [#4058](https://github.com/mochajs/mocha/issues/4058): Manage author list in AUTHORS instead of `package.json` ([**@outsideris**](https://github.com/outsideris))
|
||||
|
||||
## :nut_and_bolt: Other
|
||||
|
||||
- [#4138](https://github.com/mochajs/mocha/issues/4138): Upgrade ESLint v6.8 ([**@kaicataldo**](https://github.com/kaicataldo))
|
||||
|
||||
# 7.0.1 / 2020-01-25
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#4165](https://github.com/mochajs/mocha/issues/4165): Fix exception when skipping tests programmatically ([**@juergba**](https://github.com/juergba))
|
||||
- [#4153](https://github.com/mochajs/mocha/issues/4153): Restore backwards compatibility for `reporterOptions` ([**@holm**](https://github.com/holm))
|
||||
- [#4150](https://github.com/mochajs/mocha/issues/4150): Fix recovery of an open test upon uncaught exception ([**@juergba**](https://github.com/juergba))
|
||||
- [#4147](https://github.com/mochajs/mocha/issues/4147): Fix regression of leaking uncaught exception handler ([**@juergba**](https://github.com/juergba))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [#4146](https://github.com/mochajs/mocha/issues/4146): Update copyright & trademark notices per OJSF ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#4140](https://github.com/mochajs/mocha/issues/4140): Fix broken links ([**@KyoungWan**](https://github.com/KyoungWan))
|
||||
|
||||
## :nut_and_bolt: Other
|
||||
|
||||
- [#4133](https://github.com/mochajs/mocha/issues/4133): Print more descriptive error message ([**@Zirak**](https://github.com/Zirak))
|
||||
|
||||
# 7.0.0 / 2020-01-05
|
||||
|
||||
## :boom: Breaking Changes
|
||||
|
||||
- [#3885](https://github.com/mochajs/mocha/issues/3885): **Drop Node.js v6.x support** ([**@mojosoeun**](https://github.com/mojosoeun))
|
||||
- [#3890](https://github.com/mochajs/mocha/issues/3890): Remove Node.js debug-related flags `--debug`/`--debug-brk` and deprecate `debug` argument ([**@juergba**](https://github.com/juergba))
|
||||
- [#3962](https://github.com/mochajs/mocha/issues/3962): Changes to command-line options ([**@ParkSB**](https://github.com/ParkSB)):
|
||||
- `--list-interfaces` replaces `--interfaces`
|
||||
- `--list-reporters` replaces `--reporters`
|
||||
- Hook pattern of `this.skip()` ([**@juergba**](https://github.com/juergba)):
|
||||
- [#3859](https://github.com/mochajs/mocha/issues/3859): When conditionally skipping in a `it` test, related `afterEach` hooks are now executed
|
||||
- [#3741](https://github.com/mochajs/mocha/issues/3741): When conditionally skipping in a `beforeEach` hook, subsequent inner `beforeEach` hooks are now skipped and related `afterEach` hooks are executed
|
||||
- [#4136](https://github.com/mochajs/mocha/issues/4136): Disallow `this.skip()` within `after` hooks
|
||||
- [#3967](https://github.com/mochajs/mocha/issues/3967): Remove deprecated `getOptions()` and `lib/cli/options.js` ([**@juergba**](https://github.com/juergba))
|
||||
- [#4083](https://github.com/mochajs/mocha/issues/4083): Uncaught exception in `pending` test: don't swallow, but retrospectively fail the test for correct exit code ([**@juergba**](https://github.com/juergba))
|
||||
- [#4004](https://github.com/mochajs/mocha/issues/4004): Align `Mocha` constructor's option names with command-line options ([**@juergba**](https://github.com/juergba))
|
||||
|
||||
## :tada: Enhancements
|
||||
|
||||
- [#3980](https://github.com/mochajs/mocha/issues/3980): Refactor and improve `--watch` mode with chokidar ([**@geigerzaehler**](https://github.com/geigerzaehler)):
|
||||
- adds command-line options `--watch-files` and `--watch-ignore`
|
||||
- removes `--watch-extensions`
|
||||
- [#3979](https://github.com/mochajs/mocha/issues/3979): Type "rs\\n" to restart tests ([**@broofa**](https://github.com/broofa))
|
||||
|
||||
## :fax: Deprecations
|
||||
|
||||
These are _soft_-deprecated, and will emit a warning upon use. Support will be removed in (likely) the next major version of Mocha:
|
||||
|
||||
- [#3968](https://github.com/mochajs/mocha/issues/3968): Deprecate legacy configuration via `mocha.opts` ([**@juergba**](https://github.com/juergba))
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#4125](https://github.com/mochajs/mocha/issues/4125): Fix timeout handling with `--inspect-brk`/`--inspect` ([**@juergba**](https://github.com/juergba))
|
||||
- [#4070](https://github.com/mochajs/mocha/issues/4070): `Mocha` constructor: improve browser setup ([**@juergba**](https://github.com/juergba))
|
||||
- [#4068](https://github.com/mochajs/mocha/issues/4068): XUnit reporter should handle exceptions during diff generation ([**@rgroothuijsen**](https://github.com/rgroothuijsen))
|
||||
- [#4030](https://github.com/mochajs/mocha/issues/4030): Fix `--allow-uncaught` with `this.skip()` ([**@juergba**](https://github.com/juergba))
|
||||
|
||||
## :mag: Coverage
|
||||
|
||||
- [#4109](https://github.com/mochajs/mocha/issues/4109): Add Node.js v13.x to CI test matrix ([**@juergba**](https://github.com/juergba))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [#4129](https://github.com/mochajs/mocha/issues/4129): Fix broken links ([**@SaeromB**](https://github.com/SaeromB))
|
||||
- [#4127](https://github.com/mochajs/mocha/issues/4127): Add reporter alias names to docs ([**@khg0712**](https://github.com/khg0712))
|
||||
- [#4101](https://github.com/mochajs/mocha/issues/4101): Clarify invalid usage of `done()` ([**@jgehrcke**](https://github.com/jgehrcke))
|
||||
- [#4092](https://github.com/mochajs/mocha/issues/4092): Replace `:coffee:` with emoji ☕️ ([**@pzrq**](https://github.com/pzrq))
|
||||
- [#4088](https://github.com/mochajs/mocha/issues/4088): Initial draft of project charter ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#4066](https://github.com/mochajs/mocha/issues/4066): Change `sh` to `bash` for code block in docs/index.md ([**@HyunSangHan**](https://github.com/HyunSangHan))
|
||||
- [#4045](https://github.com/mochajs/mocha/issues/4045): Update README.md concerning GraphicsMagick installation ([**@HyunSangHan**](https://github.com/HyunSangHan))
|
||||
- [#3988](https://github.com/mochajs/mocha/issues/3988): Fix sponsors background color for readability ([**@outsideris**](https://github.com/outsideris))
|
||||
|
||||
## :nut_and_bolt: Other
|
||||
|
||||
- [#4118](https://github.com/mochajs/mocha/issues/4118): Update node-environment-flags to 1.0.6 ([**@kylef**](https://github.com/kylef))
|
||||
- [#4097](https://github.com/mochajs/mocha/issues/4097): Add GH Funding Metadata ([**@SheetJSDev**](https://github.com/SheetJSDev))
|
||||
- [#4089](https://github.com/mochajs/mocha/issues/4089): Add funding information to `package.json` ([**@Munter**](https://github.com/Munter))
|
||||
- [#4077](https://github.com/mochajs/mocha/issues/4077): Improve integration tests ([**@soobing**](https://github.com/soobing))
|
||||
|
||||
# 6.2.3 / 2020-03-25
|
||||
|
||||
## :lock: Security Fixes
|
||||
|
||||
- [848d6fb8](https://github.com/mochajs/mocha/commit/848d6fb8feef659564b296db457312d38176910d): Update dependencies mkdirp, yargs-parser and yargs ([**@juergba**](https://github.com/juergba))
|
||||
|
||||
# 6.2.2 / 2019-10-18
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#4025](https://github.com/mochajs/mocha/issues/4025): Fix duplicate `EVENT_RUN_END` events upon uncaught exception ([**@juergba**](https://github.com/juergba))
|
||||
- [#4051](https://github.com/mochajs/mocha/issues/4051): Fix "unhide" function in `html` reporter (browser) ([**@pec9399**](https://github.com/pec9399))
|
||||
- [#4063](https://github.com/mochajs/mocha/issues/4063): Fix use of [esm](https://npm.im/esm) in Node.js v8.x ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#4033](https://github.com/mochajs/mocha/issues/4033): Fix output when multiple async exceptions are thrown ([**@juergba**](https://github.com/juergba))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [#4046](https://github.com/mochajs/mocha/issues/4046): Site accessibility fixes ([**@Mia-jeong**](https://github.com/Mia-jeong))
|
||||
- [#4026](https://github.com/mochajs/mocha/issues/4026): Update docs for custom reporters in browser ([**@Lindsay-Needs-Sleep**](https://github.com/Lindsay-Needs-Sleep))
|
||||
- [#3971](https://github.com/mochajs/mocha/issues/3971): Adopt new OpenJS Foundation Code of Conduct ([**@craigtaub**](https://github.com/craigtaub))
|
||||
|
||||
# 6.2.1 / 2019-09-29
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#3955](https://github.com/mochajs/mocha/issues/3955): tty.getWindowSize is not a function inside a "worker_threads" worker ([**@1999**](https://github.com/1999))
|
||||
- [#3970](https://github.com/mochajs/mocha/issues/3970): remove extraGlobals() ([**@juergba**](https://github.com/juergba))
|
||||
- [#3984](https://github.com/mochajs/mocha/issues/3984): Update yargs-unparser to v1.6.0 ([**@juergba**](https://github.com/juergba))
|
||||
- [#3983](https://github.com/mochajs/mocha/issues/3983): Package 'esm': spawn child-process for correct loading ([**@juergba**](https://github.com/juergba))
|
||||
- [#3986](https://github.com/mochajs/mocha/issues/3986): Update yargs to v13.3.0 and yargs-parser to v13.1.1 ([**@juergba**](https://github.com/juergba))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [#3886](https://github.com/mochajs/mocha/issues/3886): fix styles on mochajs.org ([**@outsideris**](https://github.com/outsideris))
|
||||
- [#3966](https://github.com/mochajs/mocha/issues/3966): Remove jsdoc index.html placeholder from eleventy file structure and fix broken link in jsdoc tutorial ([**@Munter**](https://github.com/Munter))
|
||||
- [#3765](https://github.com/mochajs/mocha/issues/3765): Add Matomo to website ([**@MarioDiaz98**](https://github.com/MarioDiaz98))
|
||||
- [#3947](https://github.com/mochajs/mocha/issues/3947): Clarify effect of .skip() ([**@oliversalzburg**](https://github.com/oliversalzburg))
|
||||
|
||||
# 6.2.0 / 2019-07-18
|
||||
|
||||
## :tada: Enhancements
|
||||
|
||||
- [#3827](https://github.com/mochajs/mocha/issues/3827): Do not fork child-process if no Node flags are present ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#3725](https://github.com/mochajs/mocha/issues/3725): Base reporter store ref to console.log, see [mocha/wiki](https://github.com/mochajs/mocha/wiki/HOW-TO:-Correctly-stub-stdout) ([**@craigtaub**](https://github.com/craigtaub))
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#3942](https://github.com/mochajs/mocha/issues/3942): Fix "No test files found" Error when file is passed via `--file` ([**@gabegorelick**](https://github.com/gabegorelick))
|
||||
- [#3914](https://github.com/mochajs/mocha/issues/3914): Modify Mocha constructor to accept options `global` or `globals` ([**@pascalpp**](https://github.com/pascalpp))
|
||||
- [#3894](https://github.com/mochajs/mocha/issues/3894): Fix parsing of config files with `_mocha` binary ([**@juergba**](https://github.com/juergba))
|
||||
- [#3834](https://github.com/mochajs/mocha/issues/3834): Fix CLI parsing with default values ([**@boneskull**](https://github.com/boneskull), [**@juergba**](https://github.com/juergba))
|
||||
- [#3831](https://github.com/mochajs/mocha/issues/3831): Fix `--timeout`/`--slow` string values and duplicate arguments ([**@boneskull**](https://github.com/boneskull), [**@juergba**](https://github.com/juergba))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [#3906](https://github.com/mochajs/mocha/issues/3906): Document option to define custom report name for XUnit reporter ([**@pkuczynski**](https://github.com/pkuczynski))
|
||||
- [#3889](https://github.com/mochajs/mocha/issues/3889): Adds doc links for mocha-examples ([**@craigtaub**](https://github.com/craigtaub))
|
||||
- [#3887](https://github.com/mochajs/mocha/issues/3887): Fix broken links ([**@toyjhlee**](https://github.com/toyjhlee))
|
||||
- [#3841](https://github.com/mochajs/mocha/issues/3841): Fix anchors to configuration section ([**@trescube**](https://github.com/trescube))
|
||||
|
||||
## :mag: Coverage
|
||||
|
||||
- [#3915](https://github.com/mochajs/mocha/issues/3915), [#3929](https://github.com/mochajs/mocha/issues/3929): Increase tests coverage for `--watch` options ([**@geigerzaehler**](https://github.com/geigerzaehler))
|
||||
|
||||
## :nut_and_bolt: Other
|
||||
|
||||
- [#3953](https://github.com/mochajs/mocha/issues/3953): Collect test files later, prepares improvements to the `--watch` mode behavior ([**@geigerzaehler**](https://github.com/geigerzaehler))
|
||||
- [#3939](https://github.com/mochajs/mocha/issues/3939): Upgrade for npm audit ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#3930](https://github.com/mochajs/mocha/issues/3930): Extract `runWatch` into separate module ([**@geigerzaehler**](https://github.com/geigerzaehler))
|
||||
- [#3922](https://github.com/mochajs/mocha/issues/3922): Add `mocha.min.js` file to stacktrace filter ([**@brian-lagerman**](https://github.com/brian-lagerman))
|
||||
- [#3919](https://github.com/mochajs/mocha/issues/3919): Update CI config files to use Node-12.x ([**@plroebuck**](https://github.com/plroebuck))
|
||||
- [#3892](https://github.com/mochajs/mocha/issues/3892): Rework reporter tests ([**@plroebuck**](https://github.com/plroebuck))
|
||||
- [#3872](https://github.com/mochajs/mocha/issues/3872): Rename `--exclude` to `--ignore` and create alias ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#3963](https://github.com/mochajs/mocha/issues/3963): Hide stacktrace when cli args are missing ([**@outsideris**](https://github.com/outsideris))
|
||||
- [#3956](https://github.com/mochajs/mocha/issues/3956): Do not redeclare variable in docs array example ([**@DanielRuf**](https://github.com/DanielRuf))
|
||||
- [#3957](https://github.com/mochajs/mocha/issues/3957): Remove duplicate line-height property in `mocha.css` ([**@DanielRuf**](https://github.com/DanielRuf))
|
||||
- [#3960](https://github.com/mochajs/mocha/issues/3960): Don't re-initialize grep option on watch re-run ([**@geigerzaehler**](https://github.com/geigerzaehler))
|
||||
|
||||
# 6.1.4 / 2019-04-18
|
||||
|
||||
## :lock: Security Fixes
|
||||
|
||||
- [#3877](https://github.com/mochajs/mocha/issues/3877): Upgrade [js-yaml](https://npm.im/js-yaml), addressing [code injection vulnerability](https://www.npmjs.com/advisories/813) ([**@bjornstar**](https://github.com/bjornstar))
|
||||
|
||||
# 6.1.3 / 2019-04-11
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#3863](https://github.com/mochajs/mocha/issues/3863): Fix `yargs`-related global scope pollution ([**@inukshuk**](https://github.com/inukshuk))
|
||||
- [#3869](https://github.com/mochajs/mocha/issues/3869): Fix failure when installed w/ `pnpm` ([**@boneskull**](https://github.com/boneskull))
|
||||
|
||||
# 6.1.2 / 2019-04-08
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#3867](https://github.com/mochajs/mocha/issues/3867): Re-publish v6.1.1 from POSIX OS to avoid dropped executable flags ([**@boneskull**](https://github.com/boneskull))
|
||||
|
||||
# 6.1.1 / 2019-04-07
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#3866](https://github.com/mochajs/mocha/issues/3866): Fix Windows End-of-Line publishing issue ([**@juergba**](https://github.com/juergba) & [**@cspotcode**](https://github.com/cspotcode))
|
||||
|
||||
# 6.1.0 / 2019-04-07
|
||||
|
||||
## :lock: Security Fixes
|
||||
|
||||
- [#3845](https://github.com/mochajs/mocha/issues/3845): Update dependency "js-yaml" to v3.13.0 per npm security advisory ([**@plroebuck**](https://github.com/plroebuck))
|
||||
|
||||
## :tada: Enhancements
|
||||
|
||||
- [#3766](https://github.com/mochajs/mocha/issues/3766): Make reporter constructor support optional `options` parameter ([**@plroebuck**](https://github.com/plroebuck))
|
||||
- [#3760](https://github.com/mochajs/mocha/issues/3760): Add support for config files with `.jsonc` extension ([**@sstephant**](https://github.com/sstephant))
|
||||
|
||||
## :fax: Deprecations
|
||||
|
||||
These are _soft_-deprecated, and will emit a warning upon use. Support will be removed in (likely) the next major version of Mocha:
|
||||
|
||||
- [#3719](https://github.com/mochajs/mocha/issues/3719): Deprecate `this.skip()` for "after all" hooks ([**@juergba**](https://github.com/juergba))
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#3829](https://github.com/mochajs/mocha/issues/3829): Use cwd-relative pathname to load config file ([**@plroebuck**](https://github.com/plroebuck))
|
||||
- [#3745](https://github.com/mochajs/mocha/issues/3745): Fix async calls of `this.skip()` in "before each" hooks ([**@juergba**](https://github.com/juergba))
|
||||
- [#3669](https://github.com/mochajs/mocha/issues/3669): Enable `--allow-uncaught` for uncaught exceptions thrown inside hooks ([**@givanse**](https://github.com/givanse))
|
||||
|
||||
and some regressions:
|
||||
|
||||
- [#3848](https://github.com/mochajs/mocha/issues/3848): Fix `Suite` cloning by copying `root` property ([**@fatso83**](https://github.com/fatso83))
|
||||
- [#3816](https://github.com/mochajs/mocha/issues/3816): Guard against undefined timeout option ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#3814](https://github.com/mochajs/mocha/issues/3814): Update "yargs" in order to avoid deprecation message ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#3788](https://github.com/mochajs/mocha/issues/3788): Fix support for multiple node flags ([**@aginzberg**](https://github.com/aginzberg))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [mochajs/mocha-examples](https://github.com/mochajs/mocha-examples): New repository of working examples of common configurations using mocha ([**@craigtaub**](https://github.com/craigtaub))
|
||||
- [#3850](https://github.com/mochajs/mocha/issues/3850): Remove pound icon showing on header hover on docs ([**@jd2rogers2**](https://github.com/jd2rogers2))
|
||||
- [#3812](https://github.com/mochajs/mocha/issues/3812): Add autoprefixer to documentation page CSS ([**@Munter**](https://github.com/Munter))
|
||||
- [#3811](https://github.com/mochajs/mocha/issues/3811): Update doc examples "tests.html" ([**@DavidLi119**](https://github.com/DavidLi119))
|
||||
- [#3807](https://github.com/mochajs/mocha/issues/3807): Mocha website HTML tweaks ([**@plroebuck**](https://github.com/plroebuck))
|
||||
- [#3793](https://github.com/mochajs/mocha/issues/3793): Update config file example ".mocharc.yml" ([**@cspotcode**](https://github.com/cspotcode))
|
||||
|
||||
## :nut_and_bolt: Other
|
||||
|
||||
- [#3830](https://github.com/mochajs/mocha/issues/3830): Replace dependency "findup-sync" with "find-up" for faster startup ([**@cspotcode**](https://github.com/cspotcode))
|
||||
- [#3799](https://github.com/mochajs/mocha/issues/3799): Update devDependencies to fix many npm vulnerabilities ([**@XhmikosR**](https://github.com/XhmikosR))
|
||||
|
||||
# 6.0.2 / 2019-02-25
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
Two more regressions fixed:
|
||||
|
||||
- [#3768](https://github.com/mochajs/mocha/issues/3768): Test file paths no longer dropped from `mocha.opts` ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#3767](https://github.com/mochajs/mocha/issues/3767): `--require` does not break on module names that look like certain `node` flags ([**@boneskull**](https://github.com/boneskull))
|
||||
|
||||
# 6.0.1 / 2019-02-21
|
||||
|
||||
The obligatory round of post-major-release bugfixes.
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
These issues were regressions.
|
||||
|
||||
- [#3754](https://github.com/mochajs/mocha/issues/3754): Mocha again finds `test.js` when run without arguments ([**@plroebuck**](https://github.com/plroebuck))
|
||||
- [#3756](https://github.com/mochajs/mocha/issues/3756): Mocha again supports third-party interfaces via `--ui` ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#3755](https://github.com/mochajs/mocha/issues/3755): Fix broken `--watch` ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#3759](https://github.com/mochajs/mocha/issues/3759): Fix unwelcome deprecation notice when Mocha run against languages (CoffeeScript) with implicit return statements; _returning a non-`undefined` value from a `describe` callback is no longer considered deprecated_ ([**@boneskull**](https://github.com/boneskull))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [#3738](https://github.com/mochajs/mocha/issues/3738): Upgrade to `@mocha/docdash@2` ([**@tendonstrength**](https://github.com/tendonstrength))
|
||||
- [#3751](https://github.com/mochajs/mocha/issues/3751): Use preferred names for example config files ([**@Szauka**](https://github.com/Szauka))
|
||||
|
||||
# 6.0.0 / 2019-02-18
|
||||
|
||||
## :tada: Enhancements
|
||||
|
||||
- [#3726](https://github.com/mochajs/mocha/issues/3726): Add ability to unload files from `require` cache ([**@plroebuck**](https://github.com/plroebuck))
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#3737](https://github.com/mochajs/mocha/issues/3737): Fix falsy values from options globals ([**@plroebuck**](https://github.com/plroebuck))
|
||||
- [#3707](https://github.com/mochajs/mocha/issues/3707): Fix encapsulation issues for `Suite#_onlyTests` and `Suite#_onlySuites` ([**@vkarpov15**](https://github.com/vkarpov15))
|
||||
- [#3711](https://github.com/mochajs/mocha/issues/3711): Fix diagnostic messages dealing with plurality and markup of output ([**@plroebuck**](https://github.com/plroebuck))
|
||||
- [#3723](https://github.com/mochajs/mocha/issues/3723): Fix "reporter-option" to allow comma-separated options ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#3722](https://github.com/mochajs/mocha/issues/3722): Fix code quality and performance of `lookupFiles` and `files` ([**@plroebuck**](https://github.com/plroebuck))
|
||||
- [#3650](https://github.com/mochajs/mocha/issues/3650), [#3654](https://github.com/mochajs/mocha/issues/3654): Fix noisy error message when no files found ([**@craigtaub**](https://github.com/craigtaub))
|
||||
- [#3632](https://github.com/mochajs/mocha/issues/3632): Tests having an empty title are no longer confused with the "root" suite ([**@juergba**](https://github.com/juergba))
|
||||
- [#3666](https://github.com/mochajs/mocha/issues/3666): Fix missing error codes ([**@vkarpov15**](https://github.com/vkarpov15))
|
||||
- [#3684](https://github.com/mochajs/mocha/issues/3684): Fix exiting problem in Node.js v11.7.0+ ([**@addaleax**](https://github.com/addaleax))
|
||||
- [#3691](https://github.com/mochajs/mocha/issues/3691): Fix `--delay` (and other boolean options) not working in all cases ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#3692](https://github.com/mochajs/mocha/issues/3692): Fix invalid command-line argument usage not causing actual errors ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#3698](https://github.com/mochajs/mocha/issues/3698), [#3699](https://github.com/mochajs/mocha/issues/3699): Fix debug-related Node.js options not working in all cases ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#3700](https://github.com/mochajs/mocha/issues/3700): Growl notifications now show the correct number of tests run ([**@outsideris**](https://github.com/outsideris))
|
||||
- [#3686](https://github.com/mochajs/mocha/issues/3686): Avoid potential ReDoS when diffing large objects ([**@cyjake**](https://github.com/cyjake))
|
||||
- [#3715](https://github.com/mochajs/mocha/issues/3715): Fix incorrect order of emitted events when used programmatically ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#3706](https://github.com/mochajs/mocha/issues/3706): Fix regression wherein `--reporter-option`/`--reporter-options` did not support comma-separated key/value pairs ([**@boneskull**](https://github.com/boneskull))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [#3652](https://github.com/mochajs/mocha/issues/3652): Switch from Jekyll to Eleventy ([**@Munter**](https://github.com/Munter))
|
||||
|
||||
## :nut_and_bolt: Other
|
||||
|
||||
- [#3677](https://github.com/mochajs/mocha/issues/3677): Add error objects for createUnsupportedError and createInvalidExceptionError ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#3733](https://github.com/mochajs/mocha/issues/3733): Removed unnecessary processing in post-processing hook ([**@wanseob**](https://github.com/wanseob))
|
||||
- [#3730](https://github.com/mochajs/mocha/issues/3730): Update nyc to latest version ([**@coreyfarrell**](https://github.com/coreyfarrell))
|
||||
- [#3648](https://github.com/mochajs/mocha/issues/3648), [#3680](https://github.com/mochajs/mocha/issues/3680): Fixes to support latest versions of [unexpected](https://npm.im/unexpected) and [unexpected-sinon](https://npm.im/unexpected-sinon) ([**@sunesimonsen**](https://github.com/sunesimonsen))
|
||||
- [#3638](https://github.com/mochajs/mocha/issues/3638): Add meta tag to site ([**@MartijnCuppens**](https://github.com/MartijnCuppens))
|
||||
- [#3653](https://github.com/mochajs/mocha/issues/3653): Fix parts of test suite failing to run on Windows ([**@boneskull**](https://github.com/boneskull))
|
||||
|
||||
# 6.0.0-1 / 2019-01-02
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- Fix missing `mocharc.json` in published package ([**@boneskull**](https://github.com/boneskull))
|
||||
|
||||
# 6.0.0-0 / 2019-01-01
|
||||
|
||||
**Documentation for this release can be found at [next.mochajs.org](https://next.mochajs.org)**!
|
||||
|
||||
Welcome [**@plroebuck**](https://github.com/plroebuck), [**@craigtaub**](https://github.com/craigtaub), & [**@markowsiak**](https://github.com/markowsiak) to the team!
|
||||
|
||||
## :boom: Breaking Changes
|
||||
|
||||
- [#3149](https://github.com/mochajs/mocha/issues/3149): **Drop Node.js v4.x support** ([**@outsideris**](https://github.com/outsideris))
|
||||
- [#3556](https://github.com/mochajs/mocha/issues/3556): Changes to command-line options ([**@boneskull**](https://github.com/boneskull)):
|
||||
- `--grep` and `--fgrep` are now mutually exclusive; attempting to use both will cause Mocha to fail instead of simply ignoring `--grep`
|
||||
- `--compilers` is no longer supported; attempting to use will cause Mocha to fail with a link to more information
|
||||
- `-d` is no longer an alias for `--debug`; `-d` is currently ignored
|
||||
- [#3275](https://github.com/mochajs/mocha/issues/3275): `--watch-extensions` no longer implies `js`; it must be explicitly added ([**@TheDancingCode**](https://github.com/TheDancingCode))
|
||||
- [#2908](https://github.com/mochajs/mocha/issues/2908): `tap` reporter emits error messages ([**@chrmod**](https://github.com/chrmod))
|
||||
- [#2819](https://github.com/mochajs/mocha/issues/2819): When conditionally skipping in a `before` hook, subsequent `before` hooks _and_ tests in nested suites are now skipped ([**@bannmoore**](https://github.com/bannmoore))
|
||||
- [#627](https://github.com/mochajs/mocha/issues/627): Emit filepath in "timeout exceeded" exceptions where applicable ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#3556](https://github.com/mochajs/mocha/issues/3556): `lib/template.html` has moved to `lib/browser/template.html` ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#2576](https://github.com/mochajs/mocha/issues/2576): An exception is now thrown if Mocha fails to parse or find a `mocha.opts` at a user-specified path ([**@plroebuck**](https://github.com/plroebuck))
|
||||
- [#3458](https://github.com/mochajs/mocha/issues/3458): Instantiating a `Base`-extending reporter without a `Runner` parameter will throw an exception ([**@craigtaub**](https://github.com/craigtaub))
|
||||
- [#3125](https://github.com/mochajs/mocha/issues/3125): For consumers of Mocha's programmatic API, all exceptions thrown from Mocha now have a `code` property (and some will have additional metadata). Some `Error` messages have changed. **Please use the `code` property to check `Error` types instead of the `message` property**; these descriptions will be localized in the future. ([**@craigtaub**](https://github.com/craigtaub))
|
||||
|
||||
## :fax: Deprecations
|
||||
|
||||
These are _soft_-deprecated, and will emit a warning upon use. Support will be removed in (likely) the next major version of Mocha:
|
||||
|
||||
- `-gc` users should use `--gc-global` instead
|
||||
- Consumers of the function exported by `bin/options` should now use the `loadMochaOpts` or `loadOptions` (preferred) functions exported by the `lib/cli/options` module
|
||||
|
||||
Regarding the `Mocha` class constructor (from `lib/mocha`):
|
||||
|
||||
- Use property `color: false` instead of `useColors: false`
|
||||
- Use property `timeout: false` instead of `enableTimeouts: false`
|
||||
|
||||
All of the above deprecations were introduced by [#3556](https://github.com/mochajs/mocha/issues/3556).
|
||||
|
||||
`mocha.opts` is now considered "legacy"; please prefer RC file or `package.json` over `mocha.opts`.
|
||||
|
||||
## :tada: Enhancements
|
||||
|
||||
Enhancements introduced in [#3556](https://github.com/mochajs/mocha/issues/3556):
|
||||
|
||||
- Mocha now supports "RC" files in JS, JSON, YAML, or `package.json`-based (using `mocha` property) format
|
||||
|
||||
- `.mocharc.js`, `.mocharc.json`, `.mocharc.yaml` or `.mocharc.yml` are valid "rc" file names and will be automatically loaded
|
||||
- Use `--config /path/to/rc/file` to specify an explicit path
|
||||
- Use `--package /path/to/package.json` to specify an explicit `package.json` to read the `mocha` prop from
|
||||
- Use `--no-config` or `--no-package` to completely disable loading of configuration via RC file and `package.json`, respectively
|
||||
- Configurations are merged as applicable using the priority list:
|
||||
1. Command-line arguments
|
||||
1. RC file
|
||||
1. `package.json`
|
||||
1. `mocha.opts`
|
||||
1. Mocha's own defaults
|
||||
- Check out these [example config files](https://github.com/mochajs/mocha/tree/master/example/config)
|
||||
|
||||
- Node/V8 flag support in `mocha` executable:
|
||||
|
||||
- Support all allowed `node` flags as supported by the running version of `node` (also thanks to [**@demurgos**](https://github.com/demurgos))
|
||||
- Support any V8 flag by prepending `--v8-` to the flag name
|
||||
- All flags are also supported via config files, `package.json` properties, or `mocha.opts`
|
||||
- Debug-related flags (e.g., `--inspect`) now _imply_ `--no-timeouts`
|
||||
- Use of e.g., `--debug` will automatically invoke `--inspect` if supported by running version of `node`
|
||||
|
||||
- Support negation of any Mocha-specific command-line flag by prepending `--no-` to the flag name
|
||||
|
||||
- Interfaces now have descriptions when listed using `--interfaces` flag
|
||||
|
||||
- `Mocha` constructor supports all options
|
||||
|
||||
- `--extension` is now an alias for `--watch-extensions` and affects _non-watch-mode_ test runs as well. For example, to run _only_ `test/*.coffee` (not `test/*.js`), you can do `mocha --require coffee-script/register --extensions coffee`.
|
||||
|
||||
- [#3552](https://github.com/mochajs/mocha/issues/3552): `tap` reporter is now TAP13-capable ([**@plroebuck**](https://github.com/plroebuck) & [**@mollstam**](https://github.com/mollstam))
|
||||
|
||||
- [#3535](https://github.com/mochajs/mocha/issues/3535): Mocha's version can now be queried programmatically via public property `Mocha.prototype.version` ([**@plroebuck**](https://github.com/plroebuck))
|
||||
|
||||
- [#3428](https://github.com/mochajs/mocha/issues/3428): `xunit` reporter shows diffs ([**@mlucool**](https://github.com/mlucool))
|
||||
|
||||
- [#2529](https://github.com/mochajs/mocha/issues/2529): `Runner` now emits a `retry` event when tests are retried (reporters can listen for this) ([**@catdad**](https://github.com/catdad))
|
||||
|
||||
- [#2962](https://github.com/mochajs/mocha/issues/2962), [#3111](https://github.com/mochajs/mocha/issues/3111): In-browser notification support; warn about missing prereqs when `--growl` supplied ([**@plroebuck**](https://github.com/plroebuck))
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#3356](https://github.com/mochajs/mocha/issues/3356): `--no-timeouts` and `--timeout 0` now does what you'd expect ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#3475](https://github.com/mochajs/mocha/issues/3475): Restore `--no-exit` option ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#3570](https://github.com/mochajs/mocha/issues/3570): Long-running tests now respect `SIGINT` ([**@boneskull**](https://github.com/boneskull))
|
||||
- [#2944](https://github.com/mochajs/mocha/issues/2944): `--forbid-only` and `--forbid-pending` now "fail fast" when encountered on a suite ([**@outsideris**](https://github.com/outsideris))
|
||||
- [#1652](https://github.com/mochajs/mocha/issues/1652), [#2951](https://github.com/mochajs/mocha/issues/2951): Fix broken clamping of timeout values ([**@plroebuck**](https://github.com/plroebuck))
|
||||
- [#2095](https://github.com/mochajs/mocha/issues/2095), [#3521](https://github.com/mochajs/mocha/issues/3521): Do not log `stdout:` prefix in browser console ([**@Bamieh**](https://github.com/Bamieh))
|
||||
- [#3595](https://github.com/mochajs/mocha/issues/3595): Fix mochajs.org deployment problems ([**@papandreou**](https://github.com/papandreou))
|
||||
- [#3518](https://github.com/mochajs/mocha/issues/3518): Improve `utils.isPromise()` ([**@fabiosantoscode**](https://github.com/fabiosantoscode))
|
||||
- [#3320](https://github.com/mochajs/mocha/issues/3320): Fail gracefully when non-extensible objects are thrown in async tests ([**@fargies**](https://github.com/fargies))
|
||||
- [#2475](https://github.com/mochajs/mocha/issues/2475): XUnit does not duplicate test result numbers in "errors" and "failures"; "failures" will **always** be zero ([**@mlucool**](https://github.com/mlucool))
|
||||
- [#3398](https://github.com/mochajs/mocha/issues/3398), [#3598](https://github.com/mochajs/mocha/issues/3598), [#3457](https://github.com/mochajs/mocha/issues/3457), [#3617](https://github.com/mochajs/mocha/issues/3617): Fix regression wherein `--bail` would not execute "after" nor "after each" hooks ([**@juergba**](https://github.com/juergba))
|
||||
- [#3580](https://github.com/mochajs/mocha/issues/3580): Fix potential exception when using XUnit reporter programmatically ([**@Lana-Light**](https://github.com/Lana-Light))
|
||||
- [#1304](https://github.com/mochajs/mocha/issues/1304): Do not output color to `TERM=dumb` ([**@plroebuck**](https://github.com/plroebuck))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [#3525](https://github.com/mochajs/mocha/issues/3525): Improvements to `.github/CONTRIBUTING.md` ([**@markowsiak**](https://github.com/markowsiak))
|
||||
- [#3466](https://github.com/mochajs/mocha/issues/3466): Update description of `slow` option ([**@finfin**](https://github.com/finfin))
|
||||
- [#3405](https://github.com/mochajs/mocha/issues/3405): Remove references to bower installations ([**@goteamtim**](https://github.com/goteamtim))
|
||||
- [#3361](https://github.com/mochajs/mocha/issues/3361): Improvements to `--watch` docs ([**@benglass**](https://github.com/benglass))
|
||||
- [#3136](https://github.com/mochajs/mocha/issues/3136): Improve docs around globbing and shell expansion ([**@akrawchyk**](https://github.com/akrawchyk))
|
||||
- [#2819](https://github.com/mochajs/mocha/issues/2819): Update docs around skips and hooks ([**@bannmoore**](https://github.com/bannmoore))
|
||||
- Many improvements by [**@outsideris**](https://github.com/outsideris)
|
||||
|
||||
## :nut_and_bolt: Other
|
||||
|
||||
- [#3557](https://github.com/mochajs/mocha/issues/3557): Use `ms` userland module instead of hand-rolled solution ([**@gizemkeser**](https://github.com/gizemkeser))
|
||||
- Many CI fixes and other refactors by [**@plroebuck**](https://github.com/plroebuck)
|
||||
- Test refactors by [**@outsideris**](https://github.com/outsideris)
|
||||
|
||||
# 5.2.0 / 2018-05-18
|
||||
|
||||
## :tada: Enhancements
|
||||
|
||||
- [#3375](https://github.com/mochajs/mocha/pull/3375): Add support for comments in `mocha.opts` ([@plroebuck](https://github.com/plroebuck))
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#3346](https://github.com/mochajs/mocha/pull/3346): Exit correctly from `before` hooks when using `--bail` ([@outsideris](https://github.com/outsideris))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [#3328](https://github.com/mochajs/mocha/pull/3328): Mocha-flavored [API docs](https://mochajs.org/api/)! ([@Munter](https://github.com/munter))
|
||||
|
||||
## :nut_and_bolt: Other
|
||||
|
||||
- [#3330](https://github.com/mochajs/mocha/pull/3330): Use `Buffer.from()` ([@harrysarson](https://github.com/harrysarson))
|
||||
- [#3295](https://github.com/mochajs/mocha/pull/3295): Remove redundant folder ([@DavNej](https://github.com/DajNev))
|
||||
- [#3356](https://github.com/mochajs/mocha/pull/3356): Refactoring ([@plroebuck](https://github.com/plroebuck))
|
||||
|
||||
# 5.1.1 / 2018-04-18
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#3325](https://github.com/mochajs/mocha/issues/3325): Revert change which broke `--watch` ([@boneskull](https://github.com/boneskull))
|
||||
|
||||
# 5.1.0 / 2018-04-12
|
||||
|
||||
## :tada: Enhancements
|
||||
|
||||
- [#3210](https://github.com/mochajs/mocha/pull/3210): Add `--exclude` option ([@metalex9](https://github.com/metalex9))
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#3318](https://github.com/mochajs/mocha/pull/3318): Fix failures in circular objects in JSON reporter ([@jeversmann](https://github.com/jeversmann), [@boneskull](https://github.com/boneskull))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [#3323](https://github.com/mochajs/mocha/pull/3323): Publish actual [API documentation](https://mochajs.org/api/)! ([@dfberry](https://github.com/dfberry), [@Munter](https://github.com/munter))
|
||||
- [#3299](https://github.com/mochajs/mocha/pull/3299): Improve docs around exclusive tests ([@nicgirault](https://github.com/nicgirault))
|
||||
|
||||
## :nut_and_bolt: Other
|
||||
|
||||
- [#3302](https://github.com/mochajs/mocha/pull/3302), [#3308](https://github.com/mochajs/mocha/pull/3308), [#3310](https://github.com/mochajs/mocha/pull/3310), [#3315](https://github.com/mochajs/mocha/pull/3315), [#3316](https://github.com/mochajs/mocha/pull/3316): Build matrix improvements ([more info](https://boneskull.com/mocha-and-travis-ci-build-stages/)) ([@outsideris](https://github.com/outsideris), [@boneskull](https://github.com/boneskull))
|
||||
- [#3272](https://github.com/mochajs/mocha/pull/3272): Refactor reporter tests ([@jMuzsik](https://github.com/jMuzsik))
|
||||
|
||||
# 5.0.5 / 2018-03-22
|
||||
|
||||
Welcome [@outsideris](https://github.com/outsideris) to the team!
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#3096](https://github.com/mochajs/mocha/issues/3096): Fix `--bail` failing to bail within hooks ([@outsideris](https://github.com/outsideris))
|
||||
- [#3184](https://github.com/mochajs/mocha/issues/3184): Don't skip too many suites (using `describe.skip()`) ([@outsideris](https://github.com/outsideris))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [#3133](https://github.com/mochajs/mocha/issues/3133): Improve docs regarding "pending" behavior ([@ematicipo](https://github.com/ematicipo))
|
||||
- [#3276](https://github.com/mochajs/mocha/pull/3276), [#3274](https://github.com/mochajs/mocha/pull/3274): Fix broken stuff in `CHANGELOG.md` ([@tagoro9](https://github.com/tagoro9), [@honzajavorek](https://github.com/honzajavorek))
|
||||
|
||||
## :nut_and_bolt: Other
|
||||
|
||||
- [#3208](https://github.com/mochajs/mocha/issues/3208): Improve test coverage for AMD users ([@outsideris](https://github.com/outsideris))
|
||||
- [#3267](https://github.com/mochajs/mocha/pull/3267): Remove vestiges of PhantomJS from CI ([@anishkny](https://github.com/anishkny))
|
||||
- [#2952](https://github.com/mochajs/mocha/issues/2952): Fix a debug message ([@boneskull](https://github.com/boneskull))
|
||||
|
||||
# 5.0.4 / 2018-03-07
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#3265](https://github.com/mochajs/mocha/issues/3265): Fixes regression in "watch" functionality introduced in v5.0.2 ([@outsideris](https://github.com/outsideris))
|
||||
|
||||
# 5.0.3 / 2018-03-06
|
||||
|
||||
This patch features a fix to address a potential "low severity" [ReDoS vulnerability](https://snyk.io/vuln/npm:diff:20180305) in the [diff](https://npm.im/diff) package (a dependency of Mocha).
|
||||
|
||||
## :lock: Security Fixes
|
||||
|
||||
- [#3266](https://github.com/mochajs/mocha/pull/3266): Bump `diff` to v3.5.0 ([@anishkny](https://github.com/anishkny))
|
||||
|
||||
## :nut_and_bolt: Other
|
||||
|
||||
- [#3011](https://github.com/mochajs/mocha/issues/3011): Expose `generateDiff()` in `Base` reporter ([@harrysarson](https://github.com/harrysarson))
|
||||
|
||||
# 5.0.2 / 2018-03-05
|
||||
|
||||
This release fixes a class of tests which report as _false positives_. **Certain tests will now break**, though they would have previously been reported as passing. Details below. Sorry for the inconvenience!
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#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:
|
||||
|
||||
\`\`\`js
|
||||
it('should actually fail, sorry!', function (done) {
|
||||
// passing assertion
|
||||
assert(true === true);
|
||||
|
||||
// test complete & is marked as passing
|
||||
done();
|
||||
|
||||
// ...but something evil lurks within
|
||||
setTimeout(() => {
|
||||
throw new Error('chaos!');
|
||||
}, 100);
|
||||
});
|
||||
\`\`\`
|
||||
|
||||
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.
|
||||
|
||||
**Maintainers of external reporters**: _If_ a test of this class is encountered, the `Runner` instance will emit the `end` event _twice_; you _may_ need to change your reporter to use `runner.once('end')` intead of `runner.on('end')`.
|
||||
|
||||
- [#3093](https://github.com/mochajs/mocha/issues/3093): Fix stack trace reformatting problem ([@outsideris](https://github.com/outsideris))
|
||||
|
||||
## :nut_and_bolt: Other
|
||||
|
||||
- [#3248](https://github.com/mochajs/mocha/issues/3248): Update `browser-stdout` to v1.3.1 ([@honzajavorek](https://github.com/honzajavorek))
|
||||
|
||||
# 5.0.1 / 2018-02-07
|
||||
|
||||
...your garden-variety patch release.
|
||||
|
||||
Special thanks to [Wallaby.js](https://wallabyjs.com) for their continued support! :heart:
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#1838](https://github.com/mochajs/mocha/issues/1838): `--delay` now works with `.only()` ([@silviom](https://github.com/silviom))
|
||||
- [#3119](https://github.com/mochajs/mocha/issues/3119): Plug memory leak present in v8 ([@boneskull](https://github.com/boneskull))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [#3132](https://github.com/mochajs/mocha/issues/3132), [#3098](https://github.com/mochajs/mocha/issues/3098): Update `--glob` docs ([@outsideris](https://github.com/outsideris))
|
||||
- [#3212](https://github.com/mochajs/mocha/pull/3212): Update [Wallaby.js](https://wallabyjs.com)-related docs ([@ArtemGovorov](https://github.com/ArtemGovorov))
|
||||
- [#3205](https://github.com/mochajs/mocha/pull/3205): Remove outdated cruft ([@boneskull](https://github.com/boneskull))
|
||||
|
||||
## :nut_and_bolt: Other
|
||||
|
||||
- [#3224](https://github.com/mochajs/mocha/pull/3224): Add proper Wallaby.js config ([@ArtemGovorov](https://github.com/ArtemGovorov))
|
||||
- [#3230](https://github.com/mochajs/mocha/pull/3230): Update copyright year ([@josephlin55555](https://github.com/josephlin55555))
|
||||
|
||||
# 5.0.0 / 2018-01-17
|
||||
|
||||
Mocha starts off 2018 right by again dropping support for _unmaintained rubbish_.
|
||||
|
||||
Welcome [@vkarpov15](https://github.com/vkarpov15) to the team!
|
||||
|
||||
## :boom: Breaking Changes
|
||||
|
||||
- **[#3148](https://github.com/mochajs/mocha/issues/3148): Drop support for IE9 and IE10** ([@Bamieh](https://github.com/Bamieh))
|
||||
Practically speaking, only code which consumes (through bundling or otherwise) the userland [buffer](https://npm.im/buffer) module should be affected. However, Mocha will no longer test against these browsers, nor apply fixes for them.
|
||||
|
||||
## :tada: Enhancements
|
||||
|
||||
- [#3181](https://github.com/mochajs/mocha/issues/3181): Add useful new `--file` command line argument ([documentation](https://mochajs.org/#--file-file)) ([@hswolff](https://github.com/hswolff))
|
||||
|
||||
## :bug: Fixes
|
||||
|
||||
- [#3187](https://github.com/mochajs/mocha/issues/3187): Fix inaccurate test duration reporting ([@FND](https://github.com/FND))
|
||||
- [#3202](https://github.com/mochajs/mocha/pull/3202): Fix bad markup in HTML reporter ([@DanielRuf](https://github.com/DanielRuf))
|
||||
|
||||
## :sunglasses: Developer Experience
|
||||
|
||||
- [#2352](https://github.com/mochajs/mocha/issues/2352): Ditch GNU Make for [nps](https://npm.im/nps) to manage scripts ([@TedYav](https://github.com/TedYav))
|
||||
|
||||
## :book: Documentation
|
||||
|
||||
- [#3137](https://github.com/mochajs/mocha/issues/3137): Add missing `--no-timeouts` docs ([@dfberry](https://github.com/dfberry))
|
||||
- [#3134](https://github.com/mochajs/mocha/issues/3134): Improve `done()` callback docs ([@maraisr](https://github.com/maraisr))
|
||||
- [#3135](https://github.com/mochajs/mocha/issues/3135): Fix cross-references ([@vkarpov15](https://github.com/vkarpov15))
|
||||
- [#3163](https://github.com/mochajs/mocha/pull/3163): Fix tpyos ([@tbroadley](https://github.com/tbroadley))
|
||||
- [#3177](https://github.com/mochajs/mocha/pull/3177): Tweak `README.md` organization ([@xxczaki](https://github.com/xxczaki))
|
||||
- Misc updates ([@boneskull](https://github.com/boneskull))
|
||||
|
||||
## :nut_and_bolt: Other
|
||||
|
||||
- [#3118](https://github.com/mochajs/mocha/issues/3118): Move TextMate Integration to [its own repo](https://github.com/mochajs/mocha.tmbundle) ([@Bamieh](https://github.com/Bamieh))
|
||||
- [#3185](https://github.com/mochajs/mocha/issues/3185): Add Node.js v9 to build matrix; remove v7 ([@xxczaki](https://github.com/xxczaki))
|
||||
- [#3172](https://github.com/mochajs/mocha/issues/3172): Markdown linting ([@boneskull](https://github.com/boneskull))
|
||||
- Test & Netlify updates ([@Munter](https://github.com/munter), [@boneskull](https://github.com/boneskull))
|
||||
22
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/LICENSE
generated
vendored
Normal file
22
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/LICENSE
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2011-2021 OpenJS Foundation and contributors, https://openjsf.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
70
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/README.md
generated
vendored
Normal file
70
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/README.md
generated
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
<p align="center">
|
||||
<img src="https://cldup.com/xFVFxOioAU.svg" alt="Mocha test framework"/>
|
||||
</p>
|
||||
|
||||
<p align="center">☕️ Simple, flexible, fun JavaScript test framework for Node.js & The Browser ☕️</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/mochajs/mocha/actions?query=workflow%3ATests+branch%3Amaster"><img src="https://github.com/mochajs/mocha/workflows/Tests/badge.svg?branch=master" alt="GitHub Actions Build Status"></a>
|
||||
<a href="https://coveralls.io/github/mochajs/mocha"><img src="https://coveralls.io/repos/github/mochajs/mocha/badge.svg" alt="Coverage Status"></a>
|
||||
<a href="https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmochajs%2Fmocha?ref=badge_shield"><img src="https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmochajs%2Fmocha.svg?type=shield" alt="FOSSA Status"></a>
|
||||
<a href="https://gitter.im/mochajs/mocha?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"><img src="https://badges.gitter.im/Join%20Chat.svg" alt="Gitter"></a>
|
||||
<a href="https://github.com/mochajs/mocha#sponsors"><img src="https://opencollective.com/mochajs/tiers/sponsors/badge.svg" alt="OpenCollective"></a>
|
||||
<a href="https://github.com/mochajs/mocha#backers"><img src="https://opencollective.com/mochajs/tiers/backers/badge.svg" alt="OpenCollective"></a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://www.npmjs.com/package/mocha"><img src="https://img.shields.io/npm/v/mocha.svg" alt="NPM Version"></a>
|
||||
<a href="https://github.com/mochajs/mocha"><img src="https://img.shields.io/node/v/mocha.svg" alt="Node Version"></a>
|
||||
</p>
|
||||
|
||||
<p align="center"><br><img alt="Mocha Browser Support h/t SauceLabs" src="https://saucelabs.com/browser-matrix/mochajs.svg" width="354"></p>
|
||||
|
||||
## Links
|
||||
|
||||
- **[Documentation](https://mochajs.org/)**
|
||||
- **[Release Notes / History / Changes](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)**
|
||||
- [Code of Conduct](https://github.com/mochajs/mocha/blob/master/.github/CODE_OF_CONDUCT.md)
|
||||
- [Contributing](https://github.com/mochajs/mocha/blob/master/.github/CONTRIBUTING.md)
|
||||
- [Gitter Chatroom](https://gitter.im/mochajs/mocha) (ask questions here!)
|
||||
- [Issue Tracker](https://github.com/mochajs/mocha/issues)
|
||||
|
||||
## Backers
|
||||
|
||||
[Become a backer](https://opencollective.com/mochajs) and show your support to our open source project on [our site](https://mochajs.org/#backers).
|
||||
|
||||
<a href="https://opencollective.com/mochajs"><img src="https://opencollective.com/mochajs/tiers/backers.svg?limit=30&button=false&avatarHeight=46&width=750"></a>
|
||||
|
||||
## Sponsors
|
||||
|
||||
Does your company use Mocha? Ask your manager or marketing team if your company would be interested in supporting our project. Support will allow the maintainers to dedicate more time for maintenance and new features for everyone. Also, your company's logo will show [on GitHub](https://github.com/mochajs/mocha#readme) and on [our site](https://mochajs.org#sponsors) - who doesn't want a little extra exposure? [Here's the info](https://opencollective.com/mochajs).
|
||||
|
||||
[](https://opencollective.com/mochajs/tiers/sponsors/0/website)
|
||||
[](https://opencollective.com/mochajs/tiers/sponsors/1/website)
|
||||
[](https://opencollective.com/mochajs/tiers/sponsors/2/website)
|
||||
[](https://opencollective.com/mochajs/tiers/sponsors/3/website)
|
||||
|
||||
## Development
|
||||
|
||||
You might want to know that:
|
||||
|
||||
- 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
|
||||
- Mocha is an _independent_ open-source project, maintained exclusively by volunteers.
|
||||
|
||||
You might want to help:
|
||||
|
||||
- New to contributing to Mocha? Check out this list of [good first issues](https://github.com/mochajs/mocha/issues?q=is%3Aissue+is%3Aopen+label%3Agood-first-issue)
|
||||
- Mocha could use a hand with [these issues](https://github.com/mochajs/mocha/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22)
|
||||
- The [maintainer's handbook](https://github.com/mochajs/mocha/blob/master/MAINTAINERS.md) explains how things get done
|
||||
|
||||
Finally, come [chat with the maintainers](https://gitter.im/mochajs/contributors) on Gitter if you want to help with:
|
||||
|
||||
- Triaging issues, answering questions
|
||||
- Review, merging, and closing pull requests
|
||||
- Other project-maintenance-y things
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2011-2021 OpenJS Foundation and contributors. Licensed [MIT](https://github.com/mochajs/mocha/blob/master/LICENSE).
|
||||
|
||||
[](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmochajs%2Fmocha?ref=badge_large)
|
||||
BIN
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/assets/growl/error.png
generated
vendored
Normal file
BIN
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/assets/growl/error.png
generated
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 412 B |
BIN
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/assets/growl/ok.png
generated
vendored
Normal file
BIN
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/assets/growl/ok.png
generated
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 388 B |
10
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/bin/_mocha
generated
vendored
Normal file
10
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/bin/_mocha
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* This file remains for backwards compatibility only.
|
||||
* Don't put stuff in this file.
|
||||
* @see module:lib/cli
|
||||
*/
|
||||
|
||||
require('../lib/cli').main();
|
||||
151
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/bin/mocha
generated
vendored
Normal file
151
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/bin/mocha
generated
vendored
Normal file
@ -0,0 +1,151 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* This wrapper executable checks for known node flags and appends them when found,
|
||||
* before invoking the "real" executable (`lib/cli/cli.js`)
|
||||
*
|
||||
* @module bin/mocha
|
||||
* @private
|
||||
*/
|
||||
|
||||
const {deprecate} = require('../lib/utils');
|
||||
const {loadOptions} = require('../lib/cli/options');
|
||||
const {
|
||||
unparseNodeFlags,
|
||||
isNodeFlag,
|
||||
impliesNoTimeouts
|
||||
} = require('../lib/cli/node-flags');
|
||||
const unparse = require('yargs-unparser');
|
||||
const debug = require('debug')('mocha:cli:mocha');
|
||||
const {aliases} = require('../lib/cli/run-option-metadata');
|
||||
|
||||
const mochaArgs = {};
|
||||
const nodeArgs = {};
|
||||
|
||||
const opts = loadOptions(process.argv.slice(2));
|
||||
debug('loaded opts', opts);
|
||||
|
||||
/**
|
||||
* Given option/command `value`, disable timeouts if applicable
|
||||
* @param {string} [value] - Value to check
|
||||
* @ignore
|
||||
*/
|
||||
const disableTimeouts = value => {
|
||||
if (impliesNoTimeouts(value)) {
|
||||
debug('option %s disabled timeouts', value);
|
||||
mochaArgs.timeout = 0;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* If `value` begins with `v8-` and is not explicitly `v8-options`, remove prefix
|
||||
* @param {string} [value] - Value to check
|
||||
* @returns {string} `value` with prefix (maybe) removed
|
||||
* @ignore
|
||||
*/
|
||||
const trimV8Option = value =>
|
||||
value !== 'v8-options' && /^v8-/.test(value) ? value.slice(3) : value;
|
||||
|
||||
// sort options into "node" and "mocha" buckets
|
||||
Object.keys(opts).forEach(opt => {
|
||||
if (isNodeFlag(opt)) {
|
||||
nodeArgs[trimV8Option(opt)] = opts[opt];
|
||||
} else {
|
||||
mochaArgs[opt] = opts[opt];
|
||||
}
|
||||
});
|
||||
|
||||
// disable 'timeout' for debugFlags
|
||||
Object.keys(nodeArgs).forEach(opt => disableTimeouts(opt));
|
||||
|
||||
// Native debugger handling
|
||||
// see https://nodejs.org/api/debugger.html#debugger_debugger
|
||||
// look for 'inspect' or 'debug' that would launch this debugger,
|
||||
// remove it from Mocha's opts and prepend it to Node's opts.
|
||||
// A deprecation warning will be printed by node, if applicable.
|
||||
// (mochaArgs._ are "positional" arguments, not prefixed with - or --)
|
||||
if (mochaArgs._) {
|
||||
const i = mochaArgs._.findIndex(val => val === 'inspect' || val === 'debug');
|
||||
if (i > -1) {
|
||||
const [command] = mochaArgs._.splice(i, 1);
|
||||
disableTimeouts('inspect');
|
||||
nodeArgs._ = [command];
|
||||
}
|
||||
}
|
||||
|
||||
// historical
|
||||
if (nodeArgs.gc) {
|
||||
deprecate(
|
||||
'"-gc" is deprecated and will be removed from a future version of Mocha. Use "--gc-global" instead.'
|
||||
);
|
||||
nodeArgs['gc-global'] = nodeArgs.gc;
|
||||
delete nodeArgs.gc;
|
||||
}
|
||||
|
||||
// --require/-r is treated as Mocha flag except when 'esm' is preloaded
|
||||
if (mochaArgs.require && mochaArgs.require.includes('esm')) {
|
||||
nodeArgs.require = ['esm'];
|
||||
mochaArgs.require = mochaArgs.require.filter(mod => mod !== 'esm');
|
||||
if (!mochaArgs.require.length) {
|
||||
delete mochaArgs.require;
|
||||
}
|
||||
}
|
||||
|
||||
if (Object.keys(nodeArgs).length) {
|
||||
const {spawn} = require('child_process');
|
||||
const mochaPath = require.resolve('../lib/cli/cli.js');
|
||||
|
||||
debug('final node args', nodeArgs);
|
||||
|
||||
const args = [].concat(
|
||||
unparseNodeFlags(nodeArgs),
|
||||
mochaPath,
|
||||
unparse(mochaArgs, {alias: aliases})
|
||||
);
|
||||
|
||||
debug(
|
||||
'forking child process via command: %s %s',
|
||||
process.execPath,
|
||||
args.join(' ')
|
||||
);
|
||||
|
||||
const proc = spawn(process.execPath, args, {
|
||||
stdio: 'inherit'
|
||||
});
|
||||
|
||||
proc.on('exit', (code, signal) => {
|
||||
process.on('exit', () => {
|
||||
if (signal) {
|
||||
process.kill(process.pid, signal);
|
||||
} else {
|
||||
process.exit(code);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// terminate children.
|
||||
process.on('SIGINT', () => {
|
||||
// XXX: a previous comment said this would abort the runner, but I can't see that it does
|
||||
// anything with the default runner.
|
||||
debug('main process caught SIGINT');
|
||||
proc.kill('SIGINT');
|
||||
// if running in parallel mode, we will have a proper SIGINT handler, so the below won't
|
||||
// be needed.
|
||||
if (!args.parallel || args.jobs < 2) {
|
||||
// win32 does not support SIGTERM, so use next best thing.
|
||||
if (require('os').platform() === 'win32') {
|
||||
proc.kill('SIGKILL');
|
||||
} else {
|
||||
// using SIGKILL won't cleanly close the output streams, which can result
|
||||
// in cut-off text or a befouled terminal.
|
||||
debug('sending SIGTERM to child process');
|
||||
proc.kill('SIGTERM');
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
debug('running Mocha in-process');
|
||||
require('../lib/cli/cli').main(unparse(mochaArgs, {alias: aliases}));
|
||||
}
|
||||
219
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/browser-entry.js
generated
vendored
Normal file
219
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/browser-entry.js
generated
vendored
Normal file
@ -0,0 +1,219 @@
|
||||
'use strict';
|
||||
|
||||
/* eslint no-unused-vars: off */
|
||||
/* eslint-env commonjs */
|
||||
|
||||
/**
|
||||
* Shim process.stdout.
|
||||
*/
|
||||
|
||||
process.stdout = require('browser-stdout')({label: false});
|
||||
|
||||
var parseQuery = require('./lib/browser/parse-query');
|
||||
var highlightTags = require('./lib/browser/highlight-tags');
|
||||
var Mocha = require('./lib/mocha');
|
||||
|
||||
/**
|
||||
* Create a Mocha instance.
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
|
||||
var mocha = new Mocha({reporter: 'html'});
|
||||
|
||||
/**
|
||||
* Save timer references to avoid Sinon interfering (see GH-237).
|
||||
*/
|
||||
|
||||
var Date = global.Date;
|
||||
var setTimeout = global.setTimeout;
|
||||
var setInterval = global.setInterval;
|
||||
var clearTimeout = global.clearTimeout;
|
||||
var clearInterval = global.clearInterval;
|
||||
|
||||
var uncaughtExceptionHandlers = [];
|
||||
|
||||
var originalOnerrorHandler = global.onerror;
|
||||
|
||||
/**
|
||||
* Remove uncaughtException listener.
|
||||
* Revert to original onerror handler if previously defined.
|
||||
*/
|
||||
|
||||
process.removeListener = function(e, fn) {
|
||||
if (e === 'uncaughtException') {
|
||||
if (originalOnerrorHandler) {
|
||||
global.onerror = originalOnerrorHandler;
|
||||
} else {
|
||||
global.onerror = function() {};
|
||||
}
|
||||
var i = uncaughtExceptionHandlers.indexOf(fn);
|
||||
if (i !== -1) {
|
||||
uncaughtExceptionHandlers.splice(i, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Implements listenerCount for 'uncaughtException'.
|
||||
*/
|
||||
|
||||
process.listenerCount = function(name) {
|
||||
if (name === 'uncaughtException') {
|
||||
return uncaughtExceptionHandlers.length;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Implements uncaughtException listener.
|
||||
*/
|
||||
|
||||
process.on = function(e, fn) {
|
||||
if (e === 'uncaughtException') {
|
||||
global.onerror = function(err, url, line) {
|
||||
fn(new Error(err + ' (' + url + ':' + line + ')'));
|
||||
return !mocha.options.allowUncaught;
|
||||
};
|
||||
uncaughtExceptionHandlers.push(fn);
|
||||
}
|
||||
};
|
||||
|
||||
process.listeners = function(e) {
|
||||
if (e === 'uncaughtException') {
|
||||
return uncaughtExceptionHandlers;
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
// The BDD UI is registered by default, but no UI will be functional in the
|
||||
// browser without an explicit call to the overridden `mocha.ui` (see below).
|
||||
// Ensure that this default UI does not expose its methods to the global scope.
|
||||
mocha.suite.removeAllListeners('pre-require');
|
||||
|
||||
var immediateQueue = [];
|
||||
var immediateTimeout;
|
||||
|
||||
function timeslice() {
|
||||
var immediateStart = new Date().getTime();
|
||||
while (immediateQueue.length && new Date().getTime() - immediateStart < 100) {
|
||||
immediateQueue.shift()();
|
||||
}
|
||||
if (immediateQueue.length) {
|
||||
immediateTimeout = setTimeout(timeslice, 0);
|
||||
} else {
|
||||
immediateTimeout = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* High-performance override of Runner.immediately.
|
||||
*/
|
||||
|
||||
Mocha.Runner.immediately = function(callback) {
|
||||
immediateQueue.push(callback);
|
||||
if (!immediateTimeout) {
|
||||
immediateTimeout = setTimeout(timeslice, 0);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to allow assertion libraries to throw errors directly into mocha.
|
||||
* This is useful when running tests in a browser because window.onerror will
|
||||
* only receive the 'message' attribute of the Error.
|
||||
*/
|
||||
mocha.throwError = function(err) {
|
||||
uncaughtExceptionHandlers.forEach(function(fn) {
|
||||
fn(err);
|
||||
});
|
||||
throw err;
|
||||
};
|
||||
|
||||
/**
|
||||
* Override ui to ensure that the ui functions are initialized.
|
||||
* Normally this would happen in Mocha.prototype.loadFiles.
|
||||
*/
|
||||
|
||||
mocha.ui = function(ui) {
|
||||
Mocha.prototype.ui.call(this, ui);
|
||||
this.suite.emit('pre-require', global, null, this);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Setup mocha with the given setting options.
|
||||
*/
|
||||
|
||||
mocha.setup = function(opts) {
|
||||
if (typeof opts === 'string') {
|
||||
opts = {ui: opts};
|
||||
}
|
||||
if (opts.delay === true) {
|
||||
this.delay();
|
||||
}
|
||||
var self = this;
|
||||
Object.keys(opts)
|
||||
.filter(function(opt) {
|
||||
return opt !== 'delay';
|
||||
})
|
||||
.forEach(function(opt) {
|
||||
if (Object.prototype.hasOwnProperty.call(opts, opt)) {
|
||||
self[opt](opts[opt]);
|
||||
}
|
||||
});
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Run mocha, returning the Runner.
|
||||
*/
|
||||
|
||||
mocha.run = function(fn) {
|
||||
var options = mocha.options;
|
||||
mocha.globals('location');
|
||||
|
||||
var query = parseQuery(global.location.search || '');
|
||||
if (query.grep) {
|
||||
mocha.grep(query.grep);
|
||||
}
|
||||
if (query.fgrep) {
|
||||
mocha.fgrep(query.fgrep);
|
||||
}
|
||||
if (query.invert) {
|
||||
mocha.invert();
|
||||
}
|
||||
|
||||
return Mocha.prototype.run.call(mocha, function(err) {
|
||||
// The DOM Document is not available in Web Workers.
|
||||
var document = global.document;
|
||||
if (
|
||||
document &&
|
||||
document.getElementById('mocha') &&
|
||||
options.noHighlighting !== true
|
||||
) {
|
||||
highlightTags('code');
|
||||
}
|
||||
if (fn) {
|
||||
fn(err);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose the process shim.
|
||||
* https://github.com/mochajs/mocha/pull/916
|
||||
*/
|
||||
|
||||
Mocha.process = process;
|
||||
|
||||
/**
|
||||
* Expose mocha.
|
||||
*/
|
||||
|
||||
global.Mocha = Mocha;
|
||||
global.mocha = mocha;
|
||||
|
||||
// this allows test/acceptance/required-tokens.js to pass; thus,
|
||||
// you can now do `const describe = require('mocha').describe` in a
|
||||
// browser context (assuming browserification). should fix #880
|
||||
module.exports = Object.assign(mocha, global);
|
||||
3
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/index.js
generated
vendored
Normal file
3
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/index.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./lib/mocha');
|
||||
169
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/browser/growl.js
generated
vendored
Normal file
169
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/browser/growl.js
generated
vendored
Normal file
@ -0,0 +1,169 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Web Notifications module.
|
||||
* @module Growl
|
||||
*/
|
||||
|
||||
/**
|
||||
* Save timer references to avoid Sinon interfering (see GH-237).
|
||||
*/
|
||||
var Date = global.Date;
|
||||
var setTimeout = global.setTimeout;
|
||||
var EVENT_RUN_END = require('../runner').constants.EVENT_RUN_END;
|
||||
var isBrowser = require('../utils').isBrowser;
|
||||
|
||||
/**
|
||||
* Checks if browser notification support exists.
|
||||
*
|
||||
* @public
|
||||
* @see {@link https://caniuse.com/#feat=notifications|Browser support (notifications)}
|
||||
* @see {@link https://caniuse.com/#feat=promises|Browser support (promises)}
|
||||
* @see {@link Mocha#growl}
|
||||
* @see {@link Mocha#isGrowlCapable}
|
||||
* @return {boolean} whether browser notification support exists
|
||||
*/
|
||||
exports.isCapable = function() {
|
||||
var hasNotificationSupport = 'Notification' in window;
|
||||
var hasPromiseSupport = typeof Promise === 'function';
|
||||
return isBrowser() && hasNotificationSupport && hasPromiseSupport;
|
||||
};
|
||||
|
||||
/**
|
||||
* Implements browser notifications as a pseudo-reporter.
|
||||
*
|
||||
* @public
|
||||
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/notification|Notification API}
|
||||
* @see {@link https://developers.google.com/web/fundamentals/push-notifications/display-a-notification|Displaying a Notification}
|
||||
* @see {@link Growl#isPermitted}
|
||||
* @see {@link Mocha#_growl}
|
||||
* @param {Runner} runner - Runner instance.
|
||||
*/
|
||||
exports.notify = function(runner) {
|
||||
var promise = isPermitted();
|
||||
|
||||
/**
|
||||
* Attempt notification.
|
||||
*/
|
||||
var sendNotification = function() {
|
||||
// If user hasn't responded yet... "No notification for you!" (Seinfeld)
|
||||
Promise.race([promise, Promise.resolve(undefined)])
|
||||
.then(canNotify)
|
||||
.then(function() {
|
||||
display(runner);
|
||||
})
|
||||
.catch(notPermitted);
|
||||
};
|
||||
|
||||
runner.once(EVENT_RUN_END, sendNotification);
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if browser notification is permitted by user.
|
||||
*
|
||||
* @private
|
||||
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Notification/permission|Notification.permission}
|
||||
* @see {@link Mocha#growl}
|
||||
* @see {@link Mocha#isGrowlPermitted}
|
||||
* @returns {Promise<boolean>} promise determining if browser notification
|
||||
* permissible when fulfilled.
|
||||
*/
|
||||
function isPermitted() {
|
||||
var permitted = {
|
||||
granted: function allow() {
|
||||
return Promise.resolve(true);
|
||||
},
|
||||
denied: function deny() {
|
||||
return Promise.resolve(false);
|
||||
},
|
||||
default: function ask() {
|
||||
return Notification.requestPermission().then(function(permission) {
|
||||
return permission === 'granted';
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return permitted[Notification.permission]();
|
||||
}
|
||||
|
||||
/**
|
||||
* @summary
|
||||
* Determines if notification should proceed.
|
||||
*
|
||||
* @description
|
||||
* Notification shall <strong>not</strong> proceed unless `value` is true.
|
||||
*
|
||||
* `value` will equal one of:
|
||||
* <ul>
|
||||
* <li><code>true</code> (from `isPermitted`)</li>
|
||||
* <li><code>false</code> (from `isPermitted`)</li>
|
||||
* <li><code>undefined</code> (from `Promise.race`)</li>
|
||||
* </ul>
|
||||
*
|
||||
* @private
|
||||
* @param {boolean|undefined} value - Determines if notification permissible.
|
||||
* @returns {Promise<undefined>} Notification can proceed
|
||||
*/
|
||||
function canNotify(value) {
|
||||
if (!value) {
|
||||
var why = value === false ? 'blocked' : 'unacknowledged';
|
||||
var reason = 'not permitted by user (' + why + ')';
|
||||
return Promise.reject(new Error(reason));
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the notification.
|
||||
*
|
||||
* @private
|
||||
* @param {Runner} runner - Runner instance.
|
||||
*/
|
||||
function display(runner) {
|
||||
var stats = runner.stats;
|
||||
var symbol = {
|
||||
cross: '\u274C',
|
||||
tick: '\u2705'
|
||||
};
|
||||
var logo = require('../../package.json').notifyLogo;
|
||||
var _message;
|
||||
var message;
|
||||
var title;
|
||||
|
||||
if (stats.failures) {
|
||||
_message = stats.failures + ' of ' + stats.tests + ' tests failed';
|
||||
message = symbol.cross + ' ' + _message;
|
||||
title = 'Failed';
|
||||
} else {
|
||||
_message = stats.passes + ' tests passed in ' + stats.duration + 'ms';
|
||||
message = symbol.tick + ' ' + _message;
|
||||
title = 'Passed';
|
||||
}
|
||||
|
||||
// Send notification
|
||||
var options = {
|
||||
badge: logo,
|
||||
body: message,
|
||||
dir: 'ltr',
|
||||
icon: logo,
|
||||
lang: 'en-US',
|
||||
name: 'mocha',
|
||||
requireInteraction: false,
|
||||
timestamp: Date.now()
|
||||
};
|
||||
var notification = new Notification(title, options);
|
||||
|
||||
// Autoclose after brief delay (makes various browsers act same)
|
||||
var FORCE_DURATION = 4000;
|
||||
setTimeout(notification.close.bind(notification), FORCE_DURATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* As notifications are tangential to our purpose, just log the error.
|
||||
*
|
||||
* @private
|
||||
* @param {Error} err - Why notification didn't happen.
|
||||
*/
|
||||
function notPermitted(err) {
|
||||
console.error('notification error:', err.message);
|
||||
}
|
||||
39
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/browser/highlight-tags.js
generated
vendored
Normal file
39
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/browser/highlight-tags.js
generated
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Highlight the given string of `js`.
|
||||
*
|
||||
* @private
|
||||
* @param {string} js
|
||||
* @return {string}
|
||||
*/
|
||||
function highlight(js) {
|
||||
return js
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>')
|
||||
.replace(/('.*?')/gm, '<span class="string">$1</span>')
|
||||
.replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
|
||||
.replace(/(\d+)/gm, '<span class="number">$1</span>')
|
||||
.replace(
|
||||
/\bnew[ \t]+(\w+)/gm,
|
||||
'<span class="keyword">new</span> <span class="init">$1</span>'
|
||||
)
|
||||
.replace(
|
||||
/\b(function|new|throw|return|var|if|else)\b/gm,
|
||||
'<span class="keyword">$1</span>'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlight the contents of tag `name`.
|
||||
*
|
||||
* @private
|
||||
* @param {string} name
|
||||
*/
|
||||
module.exports = function highlightTags(name) {
|
||||
var code = document.getElementById('mocha').getElementsByTagName(name);
|
||||
for (var i = 0, len = code.length; i < len; ++i) {
|
||||
code[i].innerHTML = highlight(code[i].innerHTML);
|
||||
}
|
||||
};
|
||||
24
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/browser/parse-query.js
generated
vendored
Normal file
24
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/browser/parse-query.js
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Parse the given `qs`.
|
||||
*
|
||||
* @private
|
||||
* @param {string} qs
|
||||
* @return {Object<string, string>}
|
||||
*/
|
||||
module.exports = function parseQuery(qs) {
|
||||
return qs
|
||||
.replace('?', '')
|
||||
.split('&')
|
||||
.reduce(function(obj, pair) {
|
||||
var i = pair.indexOf('=');
|
||||
var key = pair.slice(0, i);
|
||||
var val = pair.slice(++i);
|
||||
|
||||
// Due to how the URLSearchParams API treats spaces
|
||||
obj[key] = decodeURIComponent(val.replace(/\+/g, '%20'));
|
||||
|
||||
return obj;
|
||||
}, {});
|
||||
};
|
||||
123
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/browser/progress.js
generated
vendored
Normal file
123
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/browser/progress.js
generated
vendored
Normal file
@ -0,0 +1,123 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
@module browser/Progress
|
||||
*/
|
||||
|
||||
/**
|
||||
* Expose `Progress`.
|
||||
*/
|
||||
|
||||
module.exports = Progress;
|
||||
|
||||
/**
|
||||
* Initialize a new `Progress` indicator.
|
||||
*/
|
||||
function Progress() {
|
||||
this.percent = 0;
|
||||
this.size(0);
|
||||
this.fontSize(11);
|
||||
this.font('helvetica, arial, sans-serif');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set progress size to `size`.
|
||||
*
|
||||
* @public
|
||||
* @param {number} size
|
||||
* @return {Progress} Progress instance.
|
||||
*/
|
||||
Progress.prototype.size = function(size) {
|
||||
this._size = size;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set text to `text`.
|
||||
*
|
||||
* @public
|
||||
* @param {string} text
|
||||
* @return {Progress} Progress instance.
|
||||
*/
|
||||
Progress.prototype.text = function(text) {
|
||||
this._text = text;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set font size to `size`.
|
||||
*
|
||||
* @public
|
||||
* @param {number} size
|
||||
* @return {Progress} Progress instance.
|
||||
*/
|
||||
Progress.prototype.fontSize = function(size) {
|
||||
this._fontSize = size;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set font to `family`.
|
||||
*
|
||||
* @param {string} family
|
||||
* @return {Progress} Progress instance.
|
||||
*/
|
||||
Progress.prototype.font = function(family) {
|
||||
this._font = family;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Update percentage to `n`.
|
||||
*
|
||||
* @param {number} n
|
||||
* @return {Progress} Progress instance.
|
||||
*/
|
||||
Progress.prototype.update = function(n) {
|
||||
this.percent = n;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Draw on `ctx`.
|
||||
*
|
||||
* @param {CanvasRenderingContext2d} ctx
|
||||
* @return {Progress} Progress instance.
|
||||
*/
|
||||
Progress.prototype.draw = function(ctx) {
|
||||
try {
|
||||
var percent = Math.min(this.percent, 100);
|
||||
var size = this._size;
|
||||
var half = size / 2;
|
||||
var x = half;
|
||||
var y = half;
|
||||
var rad = half - 1;
|
||||
var fontSize = this._fontSize;
|
||||
|
||||
ctx.font = fontSize + 'px ' + this._font;
|
||||
|
||||
var angle = Math.PI * 2 * (percent / 100);
|
||||
ctx.clearRect(0, 0, size, size);
|
||||
|
||||
// outer circle
|
||||
ctx.strokeStyle = '#9f9f9f';
|
||||
ctx.beginPath();
|
||||
ctx.arc(x, y, rad, 0, angle, false);
|
||||
ctx.stroke();
|
||||
|
||||
// inner circle
|
||||
ctx.strokeStyle = '#eee';
|
||||
ctx.beginPath();
|
||||
ctx.arc(x, y, rad - 1, 0, angle, true);
|
||||
ctx.stroke();
|
||||
|
||||
// text
|
||||
var text = this._text || (percent | 0) + '%';
|
||||
var w = ctx.measureText(text).width;
|
||||
|
||||
ctx.fillText(text, x - w / 2 + 1, y + fontSize / 2 - 1);
|
||||
} catch (ignore) {
|
||||
// don't fail if we can't render progress
|
||||
}
|
||||
return this;
|
||||
};
|
||||
20
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/browser/template.html
generated
vendored
Normal file
20
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/browser/template.html
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Mocha</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="stylesheet" href="mocha.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
<script src="mocha.js"></script>
|
||||
<script>
|
||||
mocha.setup('bdd');
|
||||
</script>
|
||||
<script src="tests.spec.js"></script>
|
||||
<script>
|
||||
mocha.run();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
88
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/cli.js
generated
vendored
Normal file
88
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/cli.js
generated
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Contains CLI entry point and public API for programmatic usage in Node.js.
|
||||
* - Option parsing is handled by {@link https://npm.im/yargs yargs}.
|
||||
* - If executed via `node`, this module will run {@linkcode module:lib/cli.main main()}.
|
||||
* @public
|
||||
* @module lib/cli
|
||||
*/
|
||||
|
||||
const debug = require('debug')('mocha:cli:cli');
|
||||
const symbols = require('log-symbols');
|
||||
const yargs = require('yargs/yargs');
|
||||
const path = require('path');
|
||||
const {
|
||||
loadRc,
|
||||
loadPkgRc,
|
||||
loadOptions,
|
||||
YARGS_PARSER_CONFIG
|
||||
} = require('./options');
|
||||
const lookupFiles = require('./lookup-files');
|
||||
const commands = require('./commands');
|
||||
const ansi = require('ansi-colors');
|
||||
const {repository, homepage, version, gitter} = require('../../package.json');
|
||||
const {cwd} = require('../utils');
|
||||
|
||||
/**
|
||||
* - Accepts an `Array` of arguments
|
||||
* - Modifies {@link https://nodejs.org/api/modules.html#modules_module_paths Node.js' search path} for easy loading of consumer modules
|
||||
* - Sets {@linkcode https://nodejs.org/api/errors.html#errors_error_stacktracelimit Error.stackTraceLimit} to `Infinity`
|
||||
* @public
|
||||
* @summary Mocha's main command-line entry-point.
|
||||
* @param {string[]} argv - Array of arguments to parse, or by default the lovely `process.argv.slice(2)`
|
||||
*/
|
||||
exports.main = (argv = process.argv.slice(2)) => {
|
||||
debug('entered main with raw args', argv);
|
||||
// ensure we can require() from current working directory
|
||||
if (typeof module.paths !== 'undefined') {
|
||||
module.paths.push(cwd(), path.resolve('node_modules'));
|
||||
}
|
||||
|
||||
Error.stackTraceLimit = Infinity; // configurable via --stack-trace-limit?
|
||||
|
||||
var args = loadOptions(argv);
|
||||
|
||||
yargs()
|
||||
.scriptName('mocha')
|
||||
.command(commands.run)
|
||||
.command(commands.init)
|
||||
.updateStrings({
|
||||
'Positionals:': 'Positional Arguments',
|
||||
'Options:': 'Other Options',
|
||||
'Commands:': 'Commands'
|
||||
})
|
||||
.fail((msg, err, yargs) => {
|
||||
debug('caught error sometime before command handler: %O', err);
|
||||
yargs.showHelp();
|
||||
console.error(`\n${symbols.error} ${ansi.red('ERROR:')} ${msg}`);
|
||||
process.exitCode = 1;
|
||||
})
|
||||
.help('help', 'Show usage information & exit')
|
||||
.alias('help', 'h')
|
||||
.version('version', 'Show version number & exit', version)
|
||||
.alias('version', 'V')
|
||||
.wrap(process.stdout.columns ? Math.min(process.stdout.columns, 80) : 80)
|
||||
.epilog(
|
||||
`Mocha Resources
|
||||
Chat: ${ansi.magenta(gitter)}
|
||||
GitHub: ${ansi.blue(repository.url)}
|
||||
Docs: ${ansi.yellow(homepage)}
|
||||
`
|
||||
)
|
||||
.parserConfiguration(YARGS_PARSER_CONFIG)
|
||||
.config(args)
|
||||
.parse(args._);
|
||||
};
|
||||
|
||||
exports.lookupFiles = lookupFiles;
|
||||
exports.loadOptions = loadOptions;
|
||||
exports.loadPkgRc = loadPkgRc;
|
||||
exports.loadRc = loadRc;
|
||||
|
||||
// allow direct execution
|
||||
if (require.main === module) {
|
||||
exports.main();
|
||||
}
|
||||
92
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/collect-files.js
generated
vendored
Normal file
92
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/collect-files.js
generated
vendored
Normal file
@ -0,0 +1,92 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const ansi = require('ansi-colors');
|
||||
const debug = require('debug')('mocha:cli:run:helpers');
|
||||
const minimatch = require('minimatch');
|
||||
const {NO_FILES_MATCH_PATTERN} = require('../errors').constants;
|
||||
const lookupFiles = require('./lookup-files');
|
||||
const {castArray} = require('../utils');
|
||||
|
||||
/**
|
||||
* Exports a function that collects test files from CLI parameters.
|
||||
* @see module:lib/cli/run-helpers
|
||||
* @see module:lib/cli/watch-run
|
||||
* @module
|
||||
* @private
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smash together an array of test files in the correct order
|
||||
* @param {FileCollectionOptions} [opts] - Options
|
||||
* @returns {string[]} List of files to test
|
||||
* @private
|
||||
*/
|
||||
module.exports = ({
|
||||
ignore,
|
||||
extension,
|
||||
file: fileArgs,
|
||||
recursive,
|
||||
sort,
|
||||
spec
|
||||
} = {}) => {
|
||||
const unmatched = [];
|
||||
const specFiles = spec.reduce((specFiles, arg) => {
|
||||
try {
|
||||
const moreSpecFiles = castArray(lookupFiles(arg, extension, recursive))
|
||||
.filter(filename =>
|
||||
ignore.every(pattern => !minimatch(filename, pattern))
|
||||
)
|
||||
.map(filename => path.resolve(filename));
|
||||
return [...specFiles, ...moreSpecFiles];
|
||||
} catch (err) {
|
||||
if (err.code === NO_FILES_MATCH_PATTERN) {
|
||||
unmatched.push({message: err.message, pattern: err.pattern});
|
||||
return specFiles;
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
}, []);
|
||||
|
||||
// ensure we don't sort the stuff from fileArgs; order is important!
|
||||
if (sort) {
|
||||
specFiles.sort();
|
||||
}
|
||||
|
||||
// add files given through --file to be ran first
|
||||
const files = [
|
||||
...fileArgs.map(filepath => path.resolve(filepath)),
|
||||
...specFiles
|
||||
];
|
||||
debug('test files (in order): ', files);
|
||||
|
||||
if (!files.length) {
|
||||
// give full message details when only 1 file is missing
|
||||
const noneFoundMsg =
|
||||
unmatched.length === 1
|
||||
? `Error: No test files found: ${JSON.stringify(unmatched[0].pattern)}` // stringify to print escaped characters raw
|
||||
: 'Error: No test files found';
|
||||
console.error(ansi.red(noneFoundMsg));
|
||||
process.exit(1);
|
||||
} else {
|
||||
// print messages as a warning
|
||||
unmatched.forEach(warning => {
|
||||
console.warn(ansi.yellow(`Warning: ${warning.message}`));
|
||||
});
|
||||
}
|
||||
|
||||
return files;
|
||||
};
|
||||
|
||||
/**
|
||||
* An object to configure how Mocha gathers test files
|
||||
* @private
|
||||
* @typedef {Object} FileCollectionOptions
|
||||
* @property {string[]} extension - File extensions to use
|
||||
* @property {string[]} spec - Files, dirs, globs to run
|
||||
* @property {string[]} ignore - Files, dirs, globs to ignore
|
||||
* @property {string[]} file - List of additional files to include
|
||||
* @property {boolean} recursive - Find files recursively
|
||||
* @property {boolean} sort - Sort test files
|
||||
*/
|
||||
13
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/commands.js
generated
vendored
Normal file
13
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/commands.js
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Exports Yargs commands
|
||||
* @see https://git.io/fpJ0G
|
||||
* @private
|
||||
* @module
|
||||
*/
|
||||
|
||||
exports.init = require('./init');
|
||||
|
||||
// default command
|
||||
exports.run = require('./run');
|
||||
105
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/config.js
generated
vendored
Normal file
105
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/config.js
generated
vendored
Normal file
@ -0,0 +1,105 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Responsible for loading / finding Mocha's "rc" files.
|
||||
*
|
||||
* @private
|
||||
* @module
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const debug = require('debug')('mocha:cli:config');
|
||||
const findUp = require('find-up');
|
||||
const {createUnparsableFileError} = require('../errors');
|
||||
const utils = require('../utils');
|
||||
|
||||
/**
|
||||
* These are the valid config files, in order of precedence;
|
||||
* e.g., if `.mocharc.js` is present, then `.mocharc.yaml` and the rest
|
||||
* will be ignored.
|
||||
* The user should still be able to explicitly specify a file.
|
||||
* @private
|
||||
*/
|
||||
exports.CONFIG_FILES = [
|
||||
'.mocharc.cjs',
|
||||
'.mocharc.js',
|
||||
'.mocharc.yaml',
|
||||
'.mocharc.yml',
|
||||
'.mocharc.jsonc',
|
||||
'.mocharc.json'
|
||||
];
|
||||
|
||||
const isModuleNotFoundError = err =>
|
||||
err.code !== 'MODULE_NOT_FOUND' ||
|
||||
err.message.indexOf('Cannot find module') !== -1;
|
||||
|
||||
/**
|
||||
* Parsers for various config filetypes. Each accepts a filepath and
|
||||
* returns an object (but could throw)
|
||||
*/
|
||||
const parsers = (exports.parsers = {
|
||||
yaml: filepath => require('js-yaml').load(fs.readFileSync(filepath, 'utf8')),
|
||||
js: filepath => {
|
||||
const cwdFilepath = path.resolve(filepath);
|
||||
try {
|
||||
debug('parsers: load using cwd-relative path: "%s"', cwdFilepath);
|
||||
return require(cwdFilepath);
|
||||
} catch (err) {
|
||||
if (isModuleNotFoundError(err)) {
|
||||
debug('parsers: retry load as module-relative path: "%s"', filepath);
|
||||
return require(filepath);
|
||||
} else {
|
||||
throw err; // rethrow
|
||||
}
|
||||
}
|
||||
},
|
||||
json: filepath =>
|
||||
JSON.parse(
|
||||
require('strip-json-comments')(fs.readFileSync(filepath, 'utf8'))
|
||||
)
|
||||
});
|
||||
|
||||
/**
|
||||
* Loads and parses, based on file extension, a config file.
|
||||
* "JSON" files may have comments.
|
||||
*
|
||||
* @private
|
||||
* @param {string} filepath - Config file path to load
|
||||
* @returns {Object} Parsed config object
|
||||
*/
|
||||
exports.loadConfig = filepath => {
|
||||
let config = {};
|
||||
debug('loadConfig: trying to parse config at %s', filepath);
|
||||
|
||||
const ext = path.extname(filepath);
|
||||
try {
|
||||
if (ext === '.yml' || ext === '.yaml') {
|
||||
config = parsers.yaml(filepath);
|
||||
} else if (ext === '.js' || ext === '.cjs') {
|
||||
config = parsers.js(filepath);
|
||||
} else {
|
||||
config = parsers.json(filepath);
|
||||
}
|
||||
} catch (err) {
|
||||
throw createUnparsableFileError(
|
||||
`Unable to read/parse ${filepath}: ${err}`,
|
||||
filepath
|
||||
);
|
||||
}
|
||||
return config;
|
||||
};
|
||||
|
||||
/**
|
||||
* Find ("find up") config file starting at `cwd`
|
||||
*
|
||||
* @param {string} [cwd] - Current working directory
|
||||
* @returns {string|null} Filepath to config, if found
|
||||
*/
|
||||
exports.findConfig = (cwd = utils.cwd()) => {
|
||||
const filepath = findUp.sync(exports.CONFIG_FILES, {cwd});
|
||||
if (filepath) {
|
||||
debug('findConfig: found config file %s', filepath);
|
||||
}
|
||||
return filepath;
|
||||
};
|
||||
3
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/index.js
generated
vendored
Normal file
3
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/index.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./cli');
|
||||
36
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/init.js
generated
vendored
Normal file
36
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/init.js
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Command module for "init" command
|
||||
*
|
||||
* @private
|
||||
* @module
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
exports.command = 'init <path>';
|
||||
|
||||
exports.description = 'create a client-side Mocha setup at <path>';
|
||||
|
||||
exports.builder = yargs =>
|
||||
yargs.positional('path', {
|
||||
type: 'string',
|
||||
normalize: true
|
||||
});
|
||||
|
||||
exports.handler = argv => {
|
||||
const destdir = argv.path;
|
||||
const srcdir = path.join(__dirname, '..', '..');
|
||||
fs.mkdirSync(destdir, {recursive: true});
|
||||
const css = fs.readFileSync(path.join(srcdir, 'mocha.css'));
|
||||
const js = fs.readFileSync(path.join(srcdir, 'mocha.js'));
|
||||
const tmpl = fs.readFileSync(
|
||||
path.join(srcdir, 'lib', 'browser', 'template.html')
|
||||
);
|
||||
fs.writeFileSync(path.join(destdir, 'mocha.css'), css);
|
||||
fs.writeFileSync(path.join(destdir, 'mocha.js'), js);
|
||||
fs.writeFileSync(path.join(destdir, 'tests.spec.js'), '');
|
||||
fs.writeFileSync(path.join(destdir, 'index.html'), tmpl);
|
||||
};
|
||||
145
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/lookup-files.js
generated
vendored
Normal file
145
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/lookup-files.js
generated
vendored
Normal file
@ -0,0 +1,145 @@
|
||||
'use strict';
|
||||
/**
|
||||
* Contains `lookupFiles`, which takes some globs/dirs/options and returns a list of files.
|
||||
* @module
|
||||
* @private
|
||||
*/
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var glob = require('glob');
|
||||
var errors = require('../errors');
|
||||
var createNoFilesMatchPatternError = errors.createNoFilesMatchPatternError;
|
||||
var createMissingArgumentError = errors.createMissingArgumentError;
|
||||
const debug = require('debug')('mocha:cli:lookup-files');
|
||||
|
||||
/**
|
||||
* Determines if pathname would be a "hidden" file (or directory) on UN*X.
|
||||
*
|
||||
* @description
|
||||
* On UN*X, pathnames beginning with a full stop (aka dot) are hidden during
|
||||
* typical usage. Dotfiles, plain-text configuration files, are prime examples.
|
||||
*
|
||||
* @see {@link http://xahlee.info/UnixResource_dir/writ/unix_origin_of_dot_filename.html|Origin of Dot File Names}
|
||||
*
|
||||
* @private
|
||||
* @param {string} pathname - Pathname to check for match.
|
||||
* @return {boolean} whether pathname would be considered a hidden file.
|
||||
* @example
|
||||
* isHiddenOnUnix('.profile'); // => true
|
||||
*/
|
||||
const isHiddenOnUnix = pathname => path.basename(pathname).startsWith('.');
|
||||
|
||||
/**
|
||||
* Determines if pathname has a matching file extension.
|
||||
*
|
||||
* Supports multi-part extensions.
|
||||
*
|
||||
* @private
|
||||
* @param {string} pathname - Pathname to check for match.
|
||||
* @param {string[]} exts - List of file extensions, w/-or-w/o leading period
|
||||
* @return {boolean} `true` if file extension matches.
|
||||
* @example
|
||||
* hasMatchingExtname('foo.html', ['js', 'css']); // false
|
||||
* hasMatchingExtname('foo.js', ['.js']); // true
|
||||
* hasMatchingExtname('foo.js', ['js']); // ture
|
||||
*/
|
||||
const hasMatchingExtname = (pathname, exts = []) =>
|
||||
exts
|
||||
.map(ext => (ext.startsWith('.') ? ext : `.${ext}`))
|
||||
.some(ext => pathname.endsWith(ext));
|
||||
|
||||
/**
|
||||
* Lookup file names at the given `path`.
|
||||
*
|
||||
* @description
|
||||
* Filenames are returned in _traversal_ order by the OS/filesystem.
|
||||
* **Make no assumption that the names will be sorted in any fashion.**
|
||||
*
|
||||
* @public
|
||||
* @alias module:lib/cli.lookupFiles
|
||||
* @param {string} filepath - Base path to start searching from.
|
||||
* @param {string[]} [extensions=[]] - File extensions to look for.
|
||||
* @param {boolean} [recursive=false] - Whether to recurse into subdirectories.
|
||||
* @return {string[]} An array of paths.
|
||||
* @throws {Error} if no files match pattern.
|
||||
* @throws {TypeError} if `filepath` is directory and `extensions` not provided.
|
||||
*/
|
||||
module.exports = function lookupFiles(
|
||||
filepath,
|
||||
extensions = [],
|
||||
recursive = false
|
||||
) {
|
||||
const files = [];
|
||||
let stat;
|
||||
|
||||
if (!fs.existsSync(filepath)) {
|
||||
let pattern;
|
||||
if (glob.hasMagic(filepath)) {
|
||||
// Handle glob as is without extensions
|
||||
pattern = filepath;
|
||||
} else {
|
||||
// glob pattern e.g. 'filepath+(.js|.ts)'
|
||||
const strExtensions = extensions
|
||||
.map(ext => (ext.startsWith('.') ? ext : `.${ext}`))
|
||||
.join('|');
|
||||
pattern = `${filepath}+(${strExtensions})`;
|
||||
debug('looking for files using glob pattern: %s', pattern);
|
||||
}
|
||||
files.push(...glob.sync(pattern, {nodir: true}));
|
||||
if (!files.length) {
|
||||
throw createNoFilesMatchPatternError(
|
||||
`Cannot find any files matching pattern "${filepath}"`,
|
||||
filepath
|
||||
);
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
// Handle file
|
||||
try {
|
||||
stat = fs.statSync(filepath);
|
||||
if (stat.isFile()) {
|
||||
return filepath;
|
||||
}
|
||||
} catch (err) {
|
||||
// ignore error
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle directory
|
||||
fs.readdirSync(filepath).forEach(dirent => {
|
||||
const pathname = path.join(filepath, dirent);
|
||||
let stat;
|
||||
|
||||
try {
|
||||
stat = fs.statSync(pathname);
|
||||
if (stat.isDirectory()) {
|
||||
if (recursive) {
|
||||
files.push(...lookupFiles(pathname, extensions, recursive));
|
||||
}
|
||||
return;
|
||||
}
|
||||
} catch (ignored) {
|
||||
return;
|
||||
}
|
||||
if (!extensions.length) {
|
||||
throw createMissingArgumentError(
|
||||
`Argument '${extensions}' required when argument '${filepath}' is a directory`,
|
||||
'extensions',
|
||||
'array'
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
!stat.isFile() ||
|
||||
!hasMatchingExtname(pathname, extensions) ||
|
||||
isHiddenOnUnix(pathname)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
files.push(pathname);
|
||||
});
|
||||
|
||||
return files;
|
||||
};
|
||||
88
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/node-flags.js
generated
vendored
Normal file
88
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/node-flags.js
generated
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Some settings and code related to Mocha's handling of Node.js/V8 flags.
|
||||
* @private
|
||||
* @module
|
||||
*/
|
||||
|
||||
const nodeFlags = process.allowedNodeEnvironmentFlags;
|
||||
const {isMochaFlag} = require('./run-option-metadata');
|
||||
const unparse = require('yargs-unparser');
|
||||
|
||||
/**
|
||||
* These flags are considered "debug" flags.
|
||||
* @see {@link impliesNoTimeouts}
|
||||
* @private
|
||||
*/
|
||||
const debugFlags = new Set(['inspect', 'inspect-brk']);
|
||||
|
||||
/**
|
||||
* Mocha has historical support for various `node` and V8 flags which might not
|
||||
* appear in `process.allowedNodeEnvironmentFlags`.
|
||||
* These include:
|
||||
* - `--preserve-symlinks`
|
||||
* - `--harmony-*`
|
||||
* - `--gc-global`
|
||||
* - `--trace-*`
|
||||
* - `--es-staging`
|
||||
* - `--use-strict`
|
||||
* - `--v8-*` (but *not* `--v8-options`)
|
||||
* @summary Whether or not to pass a flag along to the `node` executable.
|
||||
* @param {string} flag - Flag to test
|
||||
* @param {boolean} [bareword=true] - If `false`, we expect `flag` to have one or two leading dashes.
|
||||
* @returns {boolean} If the flag is considered a "Node" flag.
|
||||
* @private
|
||||
*/
|
||||
exports.isNodeFlag = (flag, bareword = true) => {
|
||||
if (!bareword) {
|
||||
// check if the flag begins with dashes; if not, not a node flag.
|
||||
if (!/^--?/.test(flag)) {
|
||||
return false;
|
||||
}
|
||||
// strip the leading dashes to match against subsequent checks
|
||||
flag = flag.replace(/^--?/, '');
|
||||
}
|
||||
return (
|
||||
// check actual node flags from `process.allowedNodeEnvironmentFlags`,
|
||||
// then historical support for various V8 and non-`NODE_OPTIONS` flags
|
||||
// and also any V8 flags with `--v8-` prefix
|
||||
(!isMochaFlag(flag) && nodeFlags && nodeFlags.has(flag)) ||
|
||||
debugFlags.has(flag) ||
|
||||
/(?:preserve-symlinks(?:-main)?|harmony(?:[_-]|$)|(?:trace[_-].+$)|gc(?:[_-]global)?$|es[_-]staging$|use[_-]strict$|v8[_-](?!options).+?$)/.test(
|
||||
flag
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns `true` if the flag is a "debug-like" flag. These require timeouts
|
||||
* to be suppressed, or pausing the debugger on breakpoints will cause test failures.
|
||||
* @param {string} flag - Flag to test
|
||||
* @returns {boolean}
|
||||
* @private
|
||||
*/
|
||||
exports.impliesNoTimeouts = flag => debugFlags.has(flag);
|
||||
|
||||
/**
|
||||
* All non-strictly-boolean arguments to node--those with values--must specify those values using `=`, e.g., `--inspect=0.0.0.0`.
|
||||
* Unparse these arguments using `yargs-unparser` (which would result in `--inspect 0.0.0.0`), then supply `=` where we have values.
|
||||
* Apparently --require in Node.js v8 does NOT want `=`.
|
||||
* There's probably an easier or more robust way to do this; fixes welcome
|
||||
* @param {Object} opts - Arguments object
|
||||
* @returns {string[]} Unparsed arguments using `=` to specify values
|
||||
* @private
|
||||
*/
|
||||
exports.unparseNodeFlags = opts => {
|
||||
var args = unparse(opts);
|
||||
return args.length
|
||||
? args
|
||||
.join(' ')
|
||||
.split(/\b/)
|
||||
.map((arg, index, args) =>
|
||||
arg === ' ' && args[index - 1] !== 'require' ? '=' : arg
|
||||
)
|
||||
.join('')
|
||||
.split(' ')
|
||||
: [];
|
||||
};
|
||||
70
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/one-and-dones.js
generated
vendored
Normal file
70
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/one-and-dones.js
generated
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Contains "command" code for "one-and-dones"--options passed
|
||||
* to Mocha which cause it to just dump some info and exit.
|
||||
* See {@link module:lib/cli/one-and-dones.ONE_AND_DONE_ARGS ONE_AND_DONE_ARGS} for more info.
|
||||
* @module
|
||||
* @private
|
||||
*/
|
||||
|
||||
const align = require('wide-align');
|
||||
const Mocha = require('../mocha');
|
||||
|
||||
/**
|
||||
* Dumps a sorted list of the enumerable, lower-case keys of some object
|
||||
* to `STDOUT`.
|
||||
* @param {Object} obj - Object, ostensibly having some enumerable keys
|
||||
* @ignore
|
||||
* @private
|
||||
*/
|
||||
const showKeys = obj => {
|
||||
console.log();
|
||||
const keys = Object.keys(obj);
|
||||
const maxKeyLength = keys.reduce((max, key) => Math.max(max, key.length), 0);
|
||||
keys
|
||||
.filter(
|
||||
key => /^[a-z]/.test(key) && !obj[key].browserOnly && !obj[key].abstract
|
||||
)
|
||||
.sort()
|
||||
.forEach(key => {
|
||||
const description = obj[key].description;
|
||||
console.log(
|
||||
` ${align.left(key, maxKeyLength + 1)}${
|
||||
description ? `- ${description}` : ''
|
||||
}`
|
||||
);
|
||||
});
|
||||
console.log();
|
||||
};
|
||||
|
||||
/**
|
||||
* Handlers for one-and-done options
|
||||
* @namespace
|
||||
* @private
|
||||
*/
|
||||
exports.ONE_AND_DONES = {
|
||||
/**
|
||||
* Dump list of built-in interfaces
|
||||
* @private
|
||||
*/
|
||||
'list-interfaces': () => {
|
||||
showKeys(Mocha.interfaces);
|
||||
},
|
||||
/**
|
||||
* Dump list of built-in reporters
|
||||
* @private
|
||||
*/
|
||||
'list-reporters': () => {
|
||||
showKeys(Mocha.reporters);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* A Set of all one-and-done options
|
||||
* @type Set<string>
|
||||
* @private
|
||||
*/
|
||||
exports.ONE_AND_DONE_ARGS = new Set(
|
||||
['help', 'h', 'version', 'V'].concat(Object.keys(exports.ONE_AND_DONES))
|
||||
);
|
||||
261
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/options.js
generated
vendored
Normal file
261
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/options.js
generated
vendored
Normal file
@ -0,0 +1,261 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Main entry point for handling filesystem-based configuration,
|
||||
* whether that's a config file or `package.json` or whatever.
|
||||
* @module lib/cli/options
|
||||
* @private
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const ansi = require('ansi-colors');
|
||||
const yargsParser = require('yargs-parser');
|
||||
const {types, aliases} = require('./run-option-metadata');
|
||||
const {ONE_AND_DONE_ARGS} = require('./one-and-dones');
|
||||
const mocharc = require('../mocharc.json');
|
||||
const {list} = require('./run-helpers');
|
||||
const {loadConfig, findConfig} = require('./config');
|
||||
const findUp = require('find-up');
|
||||
const debug = require('debug')('mocha:cli:options');
|
||||
const {isNodeFlag} = require('./node-flags');
|
||||
const {createUnparsableFileError} = require('../errors');
|
||||
|
||||
/**
|
||||
* The `yargs-parser` namespace
|
||||
* @external yargsParser
|
||||
* @see {@link https://npm.im/yargs-parser}
|
||||
*/
|
||||
|
||||
/**
|
||||
* An object returned by a configured `yargs-parser` representing arguments
|
||||
* @memberof external:yargsParser
|
||||
* @interface Arguments
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base yargs parser configuration
|
||||
* @private
|
||||
*/
|
||||
const YARGS_PARSER_CONFIG = {
|
||||
'combine-arrays': true,
|
||||
'short-option-groups': false,
|
||||
'dot-notation': false,
|
||||
'strip-aliased': true
|
||||
};
|
||||
|
||||
/**
|
||||
* This is the config pulled from the `yargs` property of Mocha's
|
||||
* `package.json`, but it also disables camel case expansion as to
|
||||
* avoid outputting non-canonical keynames, as we need to do some
|
||||
* lookups.
|
||||
* @private
|
||||
* @ignore
|
||||
*/
|
||||
const configuration = Object.assign({}, YARGS_PARSER_CONFIG, {
|
||||
'camel-case-expansion': false
|
||||
});
|
||||
|
||||
/**
|
||||
* This is a really fancy way to:
|
||||
* - `array`-type options: ensure unique values and evtl. split comma-delimited lists
|
||||
* - `boolean`/`number`/`string`- options: use last element when given multiple times
|
||||
* This is passed as the `coerce` option to `yargs-parser`
|
||||
* @private
|
||||
* @ignore
|
||||
*/
|
||||
const globOptions = ['spec', 'ignore'];
|
||||
const coerceOpts = Object.assign(
|
||||
types.array.reduce(
|
||||
(acc, arg) =>
|
||||
Object.assign(acc, {
|
||||
[arg]: v => Array.from(new Set(globOptions.includes(arg) ? v : list(v)))
|
||||
}),
|
||||
{}
|
||||
),
|
||||
types.boolean
|
||||
.concat(types.string, types.number)
|
||||
.reduce(
|
||||
(acc, arg) =>
|
||||
Object.assign(acc, {[arg]: v => (Array.isArray(v) ? v.pop() : v)}),
|
||||
{}
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* We do not have a case when multiple arguments are ever allowed after a flag
|
||||
* (e.g., `--foo bar baz quux`), so we fix the number of arguments to 1 across
|
||||
* the board of non-boolean options.
|
||||
* This is passed as the `narg` option to `yargs-parser`
|
||||
* @private
|
||||
* @ignore
|
||||
*/
|
||||
const nargOpts = types.array
|
||||
.concat(types.string, types.number)
|
||||
.reduce((acc, arg) => Object.assign(acc, {[arg]: 1}), {});
|
||||
|
||||
/**
|
||||
* Wrapper around `yargs-parser` which applies our settings
|
||||
* @param {string|string[]} args - Arguments to parse
|
||||
* @param {Object} defaultValues - Default values of mocharc.json
|
||||
* @param {...Object} configObjects - `configObjects` for yargs-parser
|
||||
* @private
|
||||
* @ignore
|
||||
*/
|
||||
const parse = (args = [], defaultValues = {}, ...configObjects) => {
|
||||
// save node-specific args for special handling.
|
||||
// 1. when these args have a "=" they should be considered to have values
|
||||
// 2. if they don't, they just boolean flags
|
||||
// 3. to avoid explicitly defining the set of them, we tell yargs-parser they
|
||||
// are ALL boolean flags.
|
||||
// 4. we can then reapply the values after yargs-parser is done.
|
||||
const nodeArgs = (Array.isArray(args) ? args : args.split(' ')).reduce(
|
||||
(acc, arg) => {
|
||||
const pair = arg.split('=');
|
||||
let flag = pair[0];
|
||||
if (isNodeFlag(flag, false)) {
|
||||
flag = flag.replace(/^--?/, '');
|
||||
return arg.includes('=')
|
||||
? acc.concat([[flag, pair[1]]])
|
||||
: acc.concat([[flag, true]]);
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
const result = yargsParser.detailed(args, {
|
||||
configuration,
|
||||
configObjects,
|
||||
default: defaultValues,
|
||||
coerce: coerceOpts,
|
||||
narg: nargOpts,
|
||||
alias: aliases,
|
||||
string: types.string,
|
||||
array: types.array,
|
||||
number: types.number,
|
||||
boolean: types.boolean.concat(nodeArgs.map(pair => pair[0]))
|
||||
});
|
||||
if (result.error) {
|
||||
console.error(ansi.red(`Error: ${result.error.message}`));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// reapply "=" arg values from above
|
||||
nodeArgs.forEach(([key, value]) => {
|
||||
result.argv[key] = value;
|
||||
});
|
||||
|
||||
return result.argv;
|
||||
};
|
||||
|
||||
/**
|
||||
* Given path to config file in `args.config`, attempt to load & parse config file.
|
||||
* @param {Object} [args] - Arguments object
|
||||
* @param {string|boolean} [args.config] - Path to config file or `false` to skip
|
||||
* @public
|
||||
* @alias module:lib/cli.loadRc
|
||||
* @returns {external:yargsParser.Arguments|void} Parsed config, or nothing if `args.config` is `false`
|
||||
*/
|
||||
const loadRc = (args = {}) => {
|
||||
if (args.config !== false) {
|
||||
const config = args.config || findConfig();
|
||||
return config ? loadConfig(config) : {};
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.loadRc = loadRc;
|
||||
|
||||
/**
|
||||
* Given path to `package.json` in `args.package`, attempt to load config from `mocha` prop.
|
||||
* @param {Object} [args] - Arguments object
|
||||
* @param {string|boolean} [args.config] - Path to `package.json` or `false` to skip
|
||||
* @public
|
||||
* @alias module:lib/cli.loadPkgRc
|
||||
* @returns {external:yargsParser.Arguments|void} Parsed config, or nothing if `args.package` is `false`
|
||||
*/
|
||||
const loadPkgRc = (args = {}) => {
|
||||
let result;
|
||||
if (args.package === false) {
|
||||
return result;
|
||||
}
|
||||
result = {};
|
||||
const filepath = args.package || findUp.sync(mocharc.package);
|
||||
if (filepath) {
|
||||
try {
|
||||
const pkg = JSON.parse(fs.readFileSync(filepath, 'utf8'));
|
||||
if (pkg.mocha) {
|
||||
debug('`mocha` prop of package.json parsed: %O', pkg.mocha);
|
||||
result = pkg.mocha;
|
||||
} else {
|
||||
debug('no config found in %s', filepath);
|
||||
}
|
||||
} catch (err) {
|
||||
if (args.package) {
|
||||
throw createUnparsableFileError(
|
||||
`Unable to read/parse ${filepath}: ${err}`,
|
||||
filepath
|
||||
);
|
||||
}
|
||||
debug('failed to read default package.json at %s; ignoring', filepath);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports.loadPkgRc = loadPkgRc;
|
||||
|
||||
/**
|
||||
* Priority list:
|
||||
*
|
||||
* 1. Command-line args
|
||||
* 2. RC file (`.mocharc.c?js`, `.mocharc.ya?ml`, `mocharc.json`)
|
||||
* 3. `mocha` prop of `package.json`
|
||||
* 4. default configuration (`lib/mocharc.json`)
|
||||
*
|
||||
* If a {@link module:lib/cli/one-and-dones.ONE_AND_DONE_ARGS "one-and-done" option} is present in the `argv` array, no external config files will be read.
|
||||
* @summary Parses options read from `.mocharc.*` and `package.json`.
|
||||
* @param {string|string[]} [argv] - Arguments to parse
|
||||
* @public
|
||||
* @alias module:lib/cli.loadOptions
|
||||
* @returns {external:yargsParser.Arguments} Parsed args from everything
|
||||
*/
|
||||
const loadOptions = (argv = []) => {
|
||||
let args = parse(argv);
|
||||
// short-circuit: look for a flag that would abort loading of options
|
||||
if (
|
||||
Array.from(ONE_AND_DONE_ARGS).reduce(
|
||||
(acc, arg) => acc || arg in args,
|
||||
false
|
||||
)
|
||||
) {
|
||||
return args;
|
||||
}
|
||||
|
||||
const rcConfig = loadRc(args);
|
||||
const pkgConfig = loadPkgRc(args);
|
||||
|
||||
if (rcConfig) {
|
||||
args.config = false;
|
||||
args._ = args._.concat(rcConfig._ || []);
|
||||
}
|
||||
if (pkgConfig) {
|
||||
args.package = false;
|
||||
args._ = args._.concat(pkgConfig._ || []);
|
||||
}
|
||||
|
||||
args = parse(args._, mocharc, args, rcConfig || {}, pkgConfig || {});
|
||||
|
||||
// recombine positional arguments and "spec"
|
||||
if (args.spec) {
|
||||
args._ = args._.concat(args.spec);
|
||||
delete args.spec;
|
||||
}
|
||||
|
||||
// make unique
|
||||
args._ = Array.from(new Set(args._));
|
||||
|
||||
return args;
|
||||
};
|
||||
|
||||
module.exports.loadOptions = loadOptions;
|
||||
module.exports.YARGS_PARSER_CONFIG = YARGS_PARSER_CONFIG;
|
||||
243
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/run-helpers.js
generated
vendored
Normal file
243
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/run-helpers.js
generated
vendored
Normal file
@ -0,0 +1,243 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Helper scripts for the `run` command
|
||||
* @see module:lib/cli/run
|
||||
* @module
|
||||
* @private
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const debug = require('debug')('mocha:cli:run:helpers');
|
||||
const {watchRun, watchParallelRun} = require('./watch-run');
|
||||
const collectFiles = require('./collect-files');
|
||||
const {format} = require('util');
|
||||
const {createInvalidLegacyPluginError} = require('../errors');
|
||||
const {requireOrImport} = require('../esm-utils');
|
||||
const PluginLoader = require('../plugin-loader');
|
||||
|
||||
/**
|
||||
* Exits Mocha when tests + code under test has finished execution (default)
|
||||
* @param {number} code - Exit code; typically # of failures
|
||||
* @ignore
|
||||
* @private
|
||||
*/
|
||||
const exitMochaLater = code => {
|
||||
process.on('exit', () => {
|
||||
process.exitCode = Math.min(code, 255);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Exits Mocha when Mocha itself has finished execution, regardless of
|
||||
* what the tests or code under test is doing.
|
||||
* @param {number} code - Exit code; typically # of failures
|
||||
* @ignore
|
||||
* @private
|
||||
*/
|
||||
const exitMocha = code => {
|
||||
const clampedCode = Math.min(code, 255);
|
||||
let draining = 0;
|
||||
|
||||
// Eagerly set the process's exit code in case stream.write doesn't
|
||||
// execute its callback before the process terminates.
|
||||
process.exitCode = clampedCode;
|
||||
|
||||
// flush output for Node.js Windows pipe bug
|
||||
// https://github.com/joyent/node/issues/6247 is just one bug example
|
||||
// https://github.com/visionmedia/mocha/issues/333 has a good discussion
|
||||
const done = () => {
|
||||
if (!draining--) {
|
||||
process.exit(clampedCode);
|
||||
}
|
||||
};
|
||||
|
||||
const streams = [process.stdout, process.stderr];
|
||||
|
||||
streams.forEach(stream => {
|
||||
// submit empty write request and wait for completion
|
||||
draining += 1;
|
||||
stream.write('', done);
|
||||
});
|
||||
|
||||
done();
|
||||
};
|
||||
|
||||
/**
|
||||
* Coerce a comma-delimited string (or array thereof) into a flattened array of
|
||||
* strings
|
||||
* @param {string|string[]} str - Value to coerce
|
||||
* @returns {string[]} Array of strings
|
||||
* @private
|
||||
*/
|
||||
exports.list = str =>
|
||||
Array.isArray(str) ? exports.list(str.join(',')) : str.split(/ *, */);
|
||||
|
||||
/**
|
||||
* `require()` the modules as required by `--require <require>`.
|
||||
*
|
||||
* Returns array of `mochaHooks` exports, if any.
|
||||
* @param {string[]} requires - Modules to require
|
||||
* @returns {Promise<object>} Plugin implementations
|
||||
* @private
|
||||
*/
|
||||
exports.handleRequires = async (requires = [], {ignoredPlugins = []} = {}) => {
|
||||
const pluginLoader = PluginLoader.create({ignore: ignoredPlugins});
|
||||
for await (const mod of requires) {
|
||||
let modpath = mod;
|
||||
// this is relative to cwd
|
||||
if (fs.existsSync(mod) || fs.existsSync(`${mod}.js`)) {
|
||||
modpath = path.resolve(mod);
|
||||
debug('resolved required file %s to %s', mod, modpath);
|
||||
}
|
||||
const requiredModule = await requireOrImport(modpath);
|
||||
if (requiredModule && typeof requiredModule === 'object') {
|
||||
if (pluginLoader.load(requiredModule)) {
|
||||
debug('found one or more plugin implementations in %s', modpath);
|
||||
}
|
||||
}
|
||||
debug('loaded required module "%s"', mod);
|
||||
}
|
||||
const plugins = await pluginLoader.finalize();
|
||||
if (Object.keys(plugins).length) {
|
||||
debug('finalized plugin implementations: %O', plugins);
|
||||
}
|
||||
return plugins;
|
||||
};
|
||||
|
||||
/**
|
||||
* Collect and load test files, then run mocha instance.
|
||||
* @param {Mocha} mocha - Mocha instance
|
||||
* @param {Options} [opts] - Command line options
|
||||
* @param {boolean} [opts.exit] - Whether or not to force-exit after tests are complete
|
||||
* @param {Object} fileCollectParams - Parameters that control test
|
||||
* file collection. See `lib/cli/collect-files.js`.
|
||||
* @returns {Promise<Runner>}
|
||||
* @private
|
||||
*/
|
||||
const singleRun = async (mocha, {exit}, fileCollectParams) => {
|
||||
const files = collectFiles(fileCollectParams);
|
||||
debug('single run with %d file(s)', files.length);
|
||||
mocha.files = files;
|
||||
|
||||
// handles ESM modules
|
||||
await mocha.loadFilesAsync();
|
||||
return mocha.run(exit ? exitMocha : exitMochaLater);
|
||||
};
|
||||
|
||||
/**
|
||||
* Collect files and run tests (using `BufferedRunner`).
|
||||
*
|
||||
* This is `async` for consistency.
|
||||
*
|
||||
* @param {Mocha} mocha - Mocha instance
|
||||
* @param {Options} options - Command line options
|
||||
* @param {Object} fileCollectParams - Parameters that control test
|
||||
* file collection. See `lib/cli/collect-files.js`.
|
||||
* @returns {Promise<BufferedRunner>}
|
||||
* @ignore
|
||||
* @private
|
||||
*/
|
||||
const parallelRun = async (mocha, options, fileCollectParams) => {
|
||||
const files = collectFiles(fileCollectParams);
|
||||
debug('executing %d test file(s) in parallel mode', files.length);
|
||||
mocha.files = files;
|
||||
|
||||
// note that we DO NOT load any files here; this is handled by the worker
|
||||
return mocha.run(options.exit ? exitMocha : exitMochaLater);
|
||||
};
|
||||
|
||||
/**
|
||||
* Actually run tests. Delegates to one of four different functions:
|
||||
* - `singleRun`: run tests in serial & exit
|
||||
* - `watchRun`: run tests in serial, rerunning as files change
|
||||
* - `parallelRun`: run tests in parallel & exit
|
||||
* - `watchParallelRun`: run tests in parallel, rerunning as files change
|
||||
* @param {Mocha} mocha - Mocha instance
|
||||
* @param {Options} opts - Command line options
|
||||
* @private
|
||||
* @returns {Promise<Runner>}
|
||||
*/
|
||||
exports.runMocha = async (mocha, options) => {
|
||||
const {
|
||||
watch = false,
|
||||
extension = [],
|
||||
ignore = [],
|
||||
file = [],
|
||||
parallel = false,
|
||||
recursive = false,
|
||||
sort = false,
|
||||
spec = []
|
||||
} = options;
|
||||
|
||||
const fileCollectParams = {
|
||||
ignore,
|
||||
extension,
|
||||
file,
|
||||
recursive,
|
||||
sort,
|
||||
spec
|
||||
};
|
||||
|
||||
let run;
|
||||
if (watch) {
|
||||
run = parallel ? watchParallelRun : watchRun;
|
||||
} else {
|
||||
run = parallel ? parallelRun : singleRun;
|
||||
}
|
||||
|
||||
return run(mocha, options, fileCollectParams);
|
||||
};
|
||||
|
||||
/**
|
||||
* Used for `--reporter` and `--ui`. Ensures there's only one, and asserts that
|
||||
* it actually exists. This must be run _after_ requires are processed (see
|
||||
* {@link handleRequires}), as it'll prevent interfaces from loading otherwise.
|
||||
* @param {Object} opts - Options object
|
||||
* @param {"reporter"|"interface"} pluginType - Type of plugin.
|
||||
* @param {Object} [map] - An object perhaps having key `key`. Used as a cache
|
||||
* of sorts; `Mocha.reporters` is one, where each key corresponds to a reporter
|
||||
* name
|
||||
* @private
|
||||
*/
|
||||
exports.validateLegacyPlugin = (opts, pluginType, map = {}) => {
|
||||
/**
|
||||
* This should be a unique identifier; either a string (present in `map`),
|
||||
* or a resolvable (via `require.resolve`) module ID/path.
|
||||
* @type {string}
|
||||
*/
|
||||
const pluginId = opts[pluginType];
|
||||
|
||||
if (Array.isArray(pluginId)) {
|
||||
throw createInvalidLegacyPluginError(
|
||||
`"--${pluginType}" can only be specified once`,
|
||||
pluginType
|
||||
);
|
||||
}
|
||||
|
||||
const createUnknownError = err =>
|
||||
createInvalidLegacyPluginError(
|
||||
format('Could not load %s "%s":\n\n %O', pluginType, pluginId, err),
|
||||
pluginType,
|
||||
pluginId
|
||||
);
|
||||
|
||||
// if this exists, then it's already loaded, so nothing more to do.
|
||||
if (!map[pluginId]) {
|
||||
try {
|
||||
opts[pluginType] = require(pluginId);
|
||||
} catch (err) {
|
||||
if (err.code === 'MODULE_NOT_FOUND') {
|
||||
// Try to load reporters from a path (absolute or relative)
|
||||
try {
|
||||
opts[pluginType] = require(path.resolve(pluginId));
|
||||
} catch (err) {
|
||||
throw createUnknownError(err);
|
||||
}
|
||||
} else {
|
||||
throw createUnknownError(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
114
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/run-option-metadata.js
generated
vendored
Normal file
114
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/run-option-metadata.js
generated
vendored
Normal file
@ -0,0 +1,114 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Metadata about various options of the `run` command
|
||||
* @see module:lib/cli/run
|
||||
* @module
|
||||
* @private
|
||||
*/
|
||||
|
||||
/**
|
||||
* Dictionary of yargs option types to list of options having said type
|
||||
* @type {{string:string[]}}
|
||||
* @private
|
||||
*/
|
||||
const TYPES = (exports.types = {
|
||||
array: [
|
||||
'extension',
|
||||
'file',
|
||||
'global',
|
||||
'ignore',
|
||||
'reporter-option',
|
||||
'require',
|
||||
'spec',
|
||||
'watch-files',
|
||||
'watch-ignore'
|
||||
],
|
||||
boolean: [
|
||||
'allow-uncaught',
|
||||
'async-only',
|
||||
'bail',
|
||||
'check-leaks',
|
||||
'color',
|
||||
'delay',
|
||||
'diff',
|
||||
'dry-run',
|
||||
'exit',
|
||||
'forbid-only',
|
||||
'forbid-pending',
|
||||
'full-trace',
|
||||
'growl',
|
||||
'inline-diffs',
|
||||
'invert',
|
||||
'list-interfaces',
|
||||
'list-reporters',
|
||||
'no-colors',
|
||||
'parallel',
|
||||
'recursive',
|
||||
'sort',
|
||||
'watch'
|
||||
],
|
||||
number: ['retries', 'jobs'],
|
||||
string: [
|
||||
'config',
|
||||
'fgrep',
|
||||
'grep',
|
||||
'package',
|
||||
'reporter',
|
||||
'ui',
|
||||
'slow',
|
||||
'timeout'
|
||||
]
|
||||
});
|
||||
|
||||
/**
|
||||
* Option aliases keyed by canonical option name.
|
||||
* Arrays used to reduce
|
||||
* @type {{string:string[]}}
|
||||
* @private
|
||||
*/
|
||||
exports.aliases = {
|
||||
'async-only': ['A'],
|
||||
bail: ['b'],
|
||||
color: ['c', 'colors'],
|
||||
fgrep: ['f'],
|
||||
global: ['globals'],
|
||||
grep: ['g'],
|
||||
growl: ['G'],
|
||||
ignore: ['exclude'],
|
||||
invert: ['i'],
|
||||
jobs: ['j'],
|
||||
'no-colors': ['C'],
|
||||
parallel: ['p'],
|
||||
reporter: ['R'],
|
||||
'reporter-option': ['reporter-options', 'O'],
|
||||
require: ['r'],
|
||||
slow: ['s'],
|
||||
sort: ['S'],
|
||||
timeout: ['t', 'timeouts'],
|
||||
ui: ['u'],
|
||||
watch: ['w']
|
||||
};
|
||||
|
||||
const ALL_MOCHA_FLAGS = Object.keys(TYPES).reduce((acc, key) => {
|
||||
// gets all flags from each of the fields in `types`, adds those,
|
||||
// then adds aliases of each flag (if any)
|
||||
TYPES[key].forEach(flag => {
|
||||
acc.add(flag);
|
||||
const aliases = exports.aliases[flag] || [];
|
||||
aliases.forEach(alias => {
|
||||
acc.add(alias);
|
||||
});
|
||||
});
|
||||
return acc;
|
||||
}, new Set());
|
||||
|
||||
/**
|
||||
* Returns `true` if the provided `flag` is known to Mocha.
|
||||
* @param {string} flag - Flag to check
|
||||
* @returns {boolean} If `true`, this is a Mocha flag
|
||||
* @private
|
||||
*/
|
||||
exports.isMochaFlag = flag => {
|
||||
return ALL_MOCHA_FLAGS.has(flag.replace(/^--?/, ''));
|
||||
};
|
||||
371
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/run.js
generated
vendored
Normal file
371
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/run.js
generated
vendored
Normal file
@ -0,0 +1,371 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Definition for Mocha's default ("run tests") command
|
||||
*
|
||||
* @module
|
||||
* @private
|
||||
*/
|
||||
|
||||
const symbols = require('log-symbols');
|
||||
const ansi = require('ansi-colors');
|
||||
const Mocha = require('../mocha');
|
||||
const {
|
||||
createUnsupportedError,
|
||||
createInvalidArgumentValueError,
|
||||
createMissingArgumentError
|
||||
} = require('../errors');
|
||||
|
||||
const {
|
||||
list,
|
||||
handleRequires,
|
||||
validateLegacyPlugin,
|
||||
runMocha
|
||||
} = require('./run-helpers');
|
||||
const {ONE_AND_DONES, ONE_AND_DONE_ARGS} = require('./one-and-dones');
|
||||
const debug = require('debug')('mocha:cli:run');
|
||||
const defaults = require('../mocharc');
|
||||
const {types, aliases} = require('./run-option-metadata');
|
||||
|
||||
/**
|
||||
* Logical option groups
|
||||
* @constant
|
||||
*/
|
||||
const GROUPS = {
|
||||
FILES: 'File Handling',
|
||||
FILTERS: 'Test Filters',
|
||||
NODEJS: 'Node.js & V8',
|
||||
OUTPUT: 'Reporting & Output',
|
||||
RULES: 'Rules & Behavior',
|
||||
CONFIG: 'Configuration'
|
||||
};
|
||||
|
||||
exports.command = ['$0 [spec..]', 'inspect'];
|
||||
|
||||
exports.describe = 'Run tests with Mocha';
|
||||
|
||||
exports.builder = yargs =>
|
||||
yargs
|
||||
.options({
|
||||
'allow-uncaught': {
|
||||
description: 'Allow uncaught errors to propagate',
|
||||
group: GROUPS.RULES
|
||||
},
|
||||
'async-only': {
|
||||
description:
|
||||
'Require all tests to use a callback (async) or return a Promise',
|
||||
group: GROUPS.RULES
|
||||
},
|
||||
bail: {
|
||||
description: 'Abort ("bail") after first test failure',
|
||||
group: GROUPS.RULES
|
||||
},
|
||||
'check-leaks': {
|
||||
description: 'Check for global variable leaks',
|
||||
group: GROUPS.RULES
|
||||
},
|
||||
color: {
|
||||
description: 'Force-enable color output',
|
||||
group: GROUPS.OUTPUT
|
||||
},
|
||||
config: {
|
||||
config: true,
|
||||
defaultDescription: '(nearest rc file)',
|
||||
description: 'Path to config file',
|
||||
group: GROUPS.CONFIG
|
||||
},
|
||||
delay: {
|
||||
description: 'Delay initial execution of root suite',
|
||||
group: GROUPS.RULES
|
||||
},
|
||||
diff: {
|
||||
default: true,
|
||||
description: 'Show diff on failure',
|
||||
group: GROUPS.OUTPUT
|
||||
},
|
||||
'dry-run': {
|
||||
description: 'Report tests without executing them',
|
||||
group: GROUPS.RULES
|
||||
},
|
||||
exit: {
|
||||
description: 'Force Mocha to quit after tests complete',
|
||||
group: GROUPS.RULES
|
||||
},
|
||||
extension: {
|
||||
default: defaults.extension,
|
||||
description: 'File extension(s) to load',
|
||||
group: GROUPS.FILES,
|
||||
requiresArg: true,
|
||||
coerce: list
|
||||
},
|
||||
fgrep: {
|
||||
conflicts: 'grep',
|
||||
description: 'Only run tests containing this string',
|
||||
group: GROUPS.FILTERS,
|
||||
requiresArg: true
|
||||
},
|
||||
file: {
|
||||
defaultDescription: '(none)',
|
||||
description:
|
||||
'Specify file(s) to be loaded prior to root suite execution',
|
||||
group: GROUPS.FILES,
|
||||
normalize: true,
|
||||
requiresArg: true
|
||||
},
|
||||
'forbid-only': {
|
||||
description: 'Fail if exclusive test(s) encountered',
|
||||
group: GROUPS.RULES
|
||||
},
|
||||
'forbid-pending': {
|
||||
description: 'Fail if pending test(s) encountered',
|
||||
group: GROUPS.RULES
|
||||
},
|
||||
'full-trace': {
|
||||
description: 'Display full stack traces',
|
||||
group: GROUPS.OUTPUT
|
||||
},
|
||||
global: {
|
||||
coerce: list,
|
||||
description: 'List of allowed global variables',
|
||||
group: GROUPS.RULES,
|
||||
requiresArg: true
|
||||
},
|
||||
grep: {
|
||||
coerce: value => (!value ? null : value),
|
||||
conflicts: 'fgrep',
|
||||
description: 'Only run tests matching this string or regexp',
|
||||
group: GROUPS.FILTERS,
|
||||
requiresArg: true
|
||||
},
|
||||
growl: {
|
||||
description: 'Enable Growl notifications',
|
||||
group: GROUPS.OUTPUT
|
||||
},
|
||||
ignore: {
|
||||
defaultDescription: '(none)',
|
||||
description: 'Ignore file(s) or glob pattern(s)',
|
||||
group: GROUPS.FILES,
|
||||
requiresArg: true
|
||||
},
|
||||
'inline-diffs': {
|
||||
description:
|
||||
'Display actual/expected differences inline within each string',
|
||||
group: GROUPS.OUTPUT
|
||||
},
|
||||
invert: {
|
||||
description: 'Inverts --grep and --fgrep matches',
|
||||
group: GROUPS.FILTERS
|
||||
},
|
||||
jobs: {
|
||||
description:
|
||||
'Number of concurrent jobs for --parallel; use 1 to run in serial',
|
||||
defaultDescription: '(number of CPU cores - 1)',
|
||||
requiresArg: true,
|
||||
group: GROUPS.RULES
|
||||
},
|
||||
'list-interfaces': {
|
||||
conflicts: Array.from(ONE_AND_DONE_ARGS),
|
||||
description: 'List built-in user interfaces & exit'
|
||||
},
|
||||
'list-reporters': {
|
||||
conflicts: Array.from(ONE_AND_DONE_ARGS),
|
||||
description: 'List built-in reporters & exit'
|
||||
},
|
||||
'no-colors': {
|
||||
description: 'Force-disable color output',
|
||||
group: GROUPS.OUTPUT,
|
||||
hidden: true
|
||||
},
|
||||
package: {
|
||||
description: 'Path to package.json for config',
|
||||
group: GROUPS.CONFIG,
|
||||
normalize: true,
|
||||
requiresArg: true
|
||||
},
|
||||
parallel: {
|
||||
description: 'Run tests in parallel',
|
||||
group: GROUPS.RULES
|
||||
},
|
||||
recursive: {
|
||||
description: 'Look for tests in subdirectories',
|
||||
group: GROUPS.FILES
|
||||
},
|
||||
reporter: {
|
||||
default: defaults.reporter,
|
||||
description: 'Specify reporter to use',
|
||||
group: GROUPS.OUTPUT,
|
||||
requiresArg: true
|
||||
},
|
||||
'reporter-option': {
|
||||
coerce: opts =>
|
||||
list(opts).reduce((acc, opt) => {
|
||||
const pair = opt.split('=');
|
||||
|
||||
if (pair.length > 2 || !pair.length) {
|
||||
throw createInvalidArgumentValueError(
|
||||
`invalid reporter option '${opt}'`,
|
||||
'--reporter-option',
|
||||
opt,
|
||||
'expected "key=value" format'
|
||||
);
|
||||
}
|
||||
|
||||
acc[pair[0]] = pair.length === 2 ? pair[1] : true;
|
||||
return acc;
|
||||
}, {}),
|
||||
description: 'Reporter-specific options (<k=v,[k1=v1,..]>)',
|
||||
group: GROUPS.OUTPUT,
|
||||
requiresArg: true
|
||||
},
|
||||
require: {
|
||||
defaultDescription: '(none)',
|
||||
description: 'Require module',
|
||||
group: GROUPS.FILES,
|
||||
requiresArg: true
|
||||
},
|
||||
retries: {
|
||||
description: 'Retry failed tests this many times',
|
||||
group: GROUPS.RULES
|
||||
},
|
||||
slow: {
|
||||
default: defaults.slow,
|
||||
description: 'Specify "slow" test threshold (in milliseconds)',
|
||||
group: GROUPS.RULES
|
||||
},
|
||||
sort: {
|
||||
description: 'Sort test files',
|
||||
group: GROUPS.FILES
|
||||
},
|
||||
timeout: {
|
||||
default: defaults.timeout,
|
||||
description: 'Specify test timeout threshold (in milliseconds)',
|
||||
group: GROUPS.RULES
|
||||
},
|
||||
ui: {
|
||||
default: defaults.ui,
|
||||
description: 'Specify user interface',
|
||||
group: GROUPS.RULES,
|
||||
requiresArg: true
|
||||
},
|
||||
watch: {
|
||||
description: 'Watch files in the current working directory for changes',
|
||||
group: GROUPS.FILES
|
||||
},
|
||||
'watch-files': {
|
||||
description: 'List of paths or globs to watch',
|
||||
group: GROUPS.FILES,
|
||||
requiresArg: true,
|
||||
coerce: list
|
||||
},
|
||||
'watch-ignore': {
|
||||
description: 'List of paths or globs to exclude from watching',
|
||||
group: GROUPS.FILES,
|
||||
requiresArg: true,
|
||||
coerce: list,
|
||||
default: defaults['watch-ignore']
|
||||
}
|
||||
})
|
||||
.positional('spec', {
|
||||
default: ['test'],
|
||||
description: 'One or more files, directories, or globs to test',
|
||||
type: 'array'
|
||||
})
|
||||
.check(argv => {
|
||||
// "one-and-dones"; let yargs handle help and version
|
||||
Object.keys(ONE_AND_DONES).forEach(opt => {
|
||||
if (argv[opt]) {
|
||||
ONE_AND_DONES[opt].call(null, yargs);
|
||||
process.exit();
|
||||
}
|
||||
});
|
||||
|
||||
// yargs.implies() isn't flexible enough to handle this
|
||||
if (argv.invert && !('fgrep' in argv || 'grep' in argv)) {
|
||||
throw createMissingArgumentError(
|
||||
'"--invert" requires one of "--fgrep <str>" or "--grep <regexp>"',
|
||||
'--fgrep|--grep',
|
||||
'string|regexp'
|
||||
);
|
||||
}
|
||||
|
||||
if (argv.parallel) {
|
||||
// yargs.conflicts() can't deal with `--file foo.js --no-parallel`, either
|
||||
if (argv.file) {
|
||||
throw createUnsupportedError(
|
||||
'--parallel runs test files in a non-deterministic order, and is mutually exclusive with --file'
|
||||
);
|
||||
}
|
||||
|
||||
// or this
|
||||
if (argv.sort) {
|
||||
throw createUnsupportedError(
|
||||
'--parallel runs test files in a non-deterministic order, and is mutually exclusive with --sort'
|
||||
);
|
||||
}
|
||||
|
||||
if (argv.reporter === 'progress') {
|
||||
throw createUnsupportedError(
|
||||
'--reporter=progress is mutually exclusive with --parallel'
|
||||
);
|
||||
}
|
||||
|
||||
if (argv.reporter === 'markdown') {
|
||||
throw createUnsupportedError(
|
||||
'--reporter=markdown is mutually exclusive with --parallel'
|
||||
);
|
||||
}
|
||||
|
||||
if (argv.reporter === 'json-stream') {
|
||||
throw createUnsupportedError(
|
||||
'--reporter=json-stream is mutually exclusive with --parallel'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (argv.compilers) {
|
||||
throw createUnsupportedError(
|
||||
`--compilers is DEPRECATED and no longer supported.
|
||||
See https://git.io/vdcSr for migration information.`
|
||||
);
|
||||
}
|
||||
|
||||
if (argv.opts) {
|
||||
throw createUnsupportedError(
|
||||
`--opts: configuring Mocha via 'mocha.opts' is DEPRECATED and no longer supported.
|
||||
Please use a configuration file instead.`
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
})
|
||||
.middleware(async (argv, yargs) => {
|
||||
// currently a failing middleware does not work nicely with yargs' `fail()`.
|
||||
try {
|
||||
// load requires first, because it can impact "plugin" validation
|
||||
const plugins = await handleRequires(argv.require);
|
||||
validateLegacyPlugin(argv, 'reporter', Mocha.reporters);
|
||||
validateLegacyPlugin(argv, 'ui', Mocha.interfaces);
|
||||
Object.assign(argv, plugins);
|
||||
} catch (err) {
|
||||
// this could be a bad --require, bad reporter, ui, etc.
|
||||
console.error(`\n${symbols.error} ${ansi.red('ERROR:')}`, err);
|
||||
yargs.exit(1);
|
||||
}
|
||||
})
|
||||
.array(types.array)
|
||||
.boolean(types.boolean)
|
||||
.string(types.string)
|
||||
.number(types.number)
|
||||
.alias(aliases);
|
||||
|
||||
exports.handler = async function(argv) {
|
||||
debug('post-yargs config', argv);
|
||||
const mocha = new Mocha(argv);
|
||||
|
||||
try {
|
||||
await runMocha(mocha, argv);
|
||||
} catch (err) {
|
||||
console.error('\n' + (err.stack || `Error: ${err.message || err}`));
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
380
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/watch-run.js
generated
vendored
Normal file
380
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/cli/watch-run.js
generated
vendored
Normal file
@ -0,0 +1,380 @@
|
||||
'use strict';
|
||||
|
||||
const logSymbols = require('log-symbols');
|
||||
const debug = require('debug')('mocha:cli:watch');
|
||||
const path = require('path');
|
||||
const chokidar = require('chokidar');
|
||||
const Context = require('../context');
|
||||
const collectFiles = require('./collect-files');
|
||||
|
||||
/**
|
||||
* Exports the `watchRun` function that runs mocha in "watch" mode.
|
||||
* @see module:lib/cli/run-helpers
|
||||
* @module
|
||||
* @private
|
||||
*/
|
||||
|
||||
/**
|
||||
* Run Mocha in parallel "watch" mode
|
||||
* @param {Mocha} mocha - Mocha instance
|
||||
* @param {Object} opts - Options
|
||||
* @param {string[]} [opts.watchFiles] - List of paths and patterns to
|
||||
* watch. If not provided all files with an extension included in
|
||||
* `fileCollectionParams.extension` are watched. See first argument of
|
||||
* `chokidar.watch`.
|
||||
* @param {string[]} opts.watchIgnore - List of paths and patterns to
|
||||
* exclude from watching. See `ignored` option of `chokidar`.
|
||||
* @param {FileCollectionOptions} fileCollectParams - Parameters that control test
|
||||
* @private
|
||||
*/
|
||||
exports.watchParallelRun = (
|
||||
mocha,
|
||||
{watchFiles, watchIgnore},
|
||||
fileCollectParams
|
||||
) => {
|
||||
debug('creating parallel watcher');
|
||||
|
||||
return createWatcher(mocha, {
|
||||
watchFiles,
|
||||
watchIgnore,
|
||||
beforeRun({mocha}) {
|
||||
// I don't know why we're cloning the root suite.
|
||||
const rootSuite = mocha.suite.clone();
|
||||
|
||||
// ensure we aren't leaking event listeners
|
||||
mocha.dispose();
|
||||
|
||||
// this `require` is needed because the require cache has been cleared. the dynamic
|
||||
// exports set via the below call to `mocha.ui()` won't work properly if a
|
||||
// test depends on this module (see `required-tokens.spec.js`).
|
||||
const Mocha = require('../mocha');
|
||||
|
||||
// ... and now that we've gotten a new module, we need to use it again due
|
||||
// to `mocha.ui()` call
|
||||
const newMocha = new Mocha(mocha.options);
|
||||
// don't know why this is needed
|
||||
newMocha.suite = rootSuite;
|
||||
// nor this
|
||||
newMocha.suite.ctx = new Context();
|
||||
|
||||
// reset the list of files
|
||||
newMocha.files = collectFiles(fileCollectParams);
|
||||
|
||||
// because we've swapped out the root suite (see the `run` inner function
|
||||
// in `createRerunner`), we need to call `mocha.ui()` again to set up the context/globals.
|
||||
newMocha.ui(newMocha.options.ui);
|
||||
|
||||
// we need to call `newMocha.rootHooks` to set up rootHooks for the new
|
||||
// suite
|
||||
newMocha.rootHooks(newMocha.options.rootHooks);
|
||||
|
||||
// in parallel mode, the main Mocha process doesn't actually load the
|
||||
// files. this flag prevents `mocha.run()` from autoloading.
|
||||
newMocha.lazyLoadFiles(true);
|
||||
return newMocha;
|
||||
},
|
||||
fileCollectParams
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Run Mocha in "watch" mode
|
||||
* @param {Mocha} mocha - Mocha instance
|
||||
* @param {Object} opts - Options
|
||||
* @param {string[]} [opts.watchFiles] - List of paths and patterns to
|
||||
* watch. If not provided all files with an extension included in
|
||||
* `fileCollectionParams.extension` are watched. See first argument of
|
||||
* `chokidar.watch`.
|
||||
* @param {string[]} opts.watchIgnore - List of paths and patterns to
|
||||
* exclude from watching. See `ignored` option of `chokidar`.
|
||||
* @param {FileCollectionOptions} fileCollectParams - Parameters that control test
|
||||
* file collection. See `lib/cli/collect-files.js`.
|
||||
* @private
|
||||
*/
|
||||
exports.watchRun = (mocha, {watchFiles, watchIgnore}, fileCollectParams) => {
|
||||
debug('creating serial watcher');
|
||||
|
||||
return createWatcher(mocha, {
|
||||
watchFiles,
|
||||
watchIgnore,
|
||||
beforeRun({mocha}) {
|
||||
mocha.unloadFiles();
|
||||
|
||||
// I don't know why we're cloning the root suite.
|
||||
const rootSuite = mocha.suite.clone();
|
||||
|
||||
// ensure we aren't leaking event listeners
|
||||
mocha.dispose();
|
||||
|
||||
// this `require` is needed because the require cache has been cleared. the dynamic
|
||||
// exports set via the below call to `mocha.ui()` won't work properly if a
|
||||
// test depends on this module (see `required-tokens.spec.js`).
|
||||
const Mocha = require('../mocha');
|
||||
|
||||
// ... and now that we've gotten a new module, we need to use it again due
|
||||
// to `mocha.ui()` call
|
||||
const newMocha = new Mocha(mocha.options);
|
||||
// don't know why this is needed
|
||||
newMocha.suite = rootSuite;
|
||||
// nor this
|
||||
newMocha.suite.ctx = new Context();
|
||||
|
||||
// reset the list of files
|
||||
newMocha.files = collectFiles(fileCollectParams);
|
||||
|
||||
// because we've swapped out the root suite (see the `run` inner function
|
||||
// in `createRerunner`), we need to call `mocha.ui()` again to set up the context/globals.
|
||||
newMocha.ui(newMocha.options.ui);
|
||||
|
||||
// we need to call `newMocha.rootHooks` to set up rootHooks for the new
|
||||
// suite
|
||||
newMocha.rootHooks(newMocha.options.rootHooks);
|
||||
|
||||
return newMocha;
|
||||
},
|
||||
fileCollectParams
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Bootstraps a chokidar watcher. Handles keyboard input & signals
|
||||
* @param {Mocha} mocha - Mocha instance
|
||||
* @param {Object} opts
|
||||
* @param {BeforeWatchRun} [opts.beforeRun] - Function to call before
|
||||
* `mocha.run()`
|
||||
* @param {string[]} [opts.watchFiles] - List of paths and patterns to watch. If
|
||||
* not provided all files with an extension included in
|
||||
* `fileCollectionParams.extension` are watched. See first argument of
|
||||
* `chokidar.watch`.
|
||||
* @param {string[]} [opts.watchIgnore] - List of paths and patterns to exclude
|
||||
* from watching. See `ignored` option of `chokidar`.
|
||||
* @param {FileCollectionOptions} opts.fileCollectParams - List of extensions to watch if `opts.watchFiles` is not given.
|
||||
* @returns {FSWatcher}
|
||||
* @ignore
|
||||
* @private
|
||||
*/
|
||||
const createWatcher = (
|
||||
mocha,
|
||||
{watchFiles, watchIgnore, beforeRun, fileCollectParams}
|
||||
) => {
|
||||
if (!watchFiles) {
|
||||
watchFiles = fileCollectParams.extension.map(ext => `**/*.${ext}`);
|
||||
}
|
||||
|
||||
debug('ignoring files matching: %s', watchIgnore);
|
||||
let globalFixtureContext;
|
||||
|
||||
// we handle global fixtures manually
|
||||
mocha.enableGlobalSetup(false).enableGlobalTeardown(false);
|
||||
|
||||
const watcher = chokidar.watch(watchFiles, {
|
||||
ignored: watchIgnore,
|
||||
ignoreInitial: true
|
||||
});
|
||||
|
||||
const rerunner = createRerunner(mocha, watcher, {
|
||||
beforeRun
|
||||
});
|
||||
|
||||
watcher.on('ready', async () => {
|
||||
if (!globalFixtureContext) {
|
||||
debug('triggering global setup');
|
||||
globalFixtureContext = await mocha.runGlobalSetup();
|
||||
}
|
||||
rerunner.run();
|
||||
});
|
||||
|
||||
watcher.on('all', () => {
|
||||
rerunner.scheduleRun();
|
||||
});
|
||||
|
||||
hideCursor();
|
||||
process.on('exit', () => {
|
||||
showCursor();
|
||||
});
|
||||
|
||||
// this is for testing.
|
||||
// win32 cannot gracefully shutdown via a signal from a parent
|
||||
// process; a `SIGINT` from a parent will cause the process
|
||||
// to immediately exit. during normal course of operation, a user
|
||||
// will type Ctrl-C and the listener will be invoked, but this
|
||||
// is not possible in automated testing.
|
||||
// there may be another way to solve this, but it too will be a hack.
|
||||
// for our watch tests on win32 we must _fork_ mocha with an IPC channel
|
||||
if (process.connected) {
|
||||
process.on('message', msg => {
|
||||
if (msg === 'SIGINT') {
|
||||
process.emit('SIGINT');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let exiting = false;
|
||||
process.on('SIGINT', async () => {
|
||||
showCursor();
|
||||
console.error(`${logSymbols.warning} [mocha] cleaning up, please wait...`);
|
||||
if (!exiting) {
|
||||
exiting = true;
|
||||
if (mocha.hasGlobalTeardownFixtures()) {
|
||||
debug('running global teardown');
|
||||
try {
|
||||
await mocha.runGlobalTeardown(globalFixtureContext);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
process.exit(130);
|
||||
}
|
||||
});
|
||||
|
||||
// Keyboard shortcut for restarting when "rs\n" is typed (ala Nodemon)
|
||||
process.stdin.resume();
|
||||
process.stdin.setEncoding('utf8');
|
||||
process.stdin.on('data', data => {
|
||||
const str = data
|
||||
.toString()
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
if (str === 'rs') rerunner.scheduleRun();
|
||||
});
|
||||
|
||||
return watcher;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create an object that allows you to rerun tests on the mocha instance.
|
||||
*
|
||||
* @param {Mocha} mocha - Mocha instance
|
||||
* @param {FSWatcher} watcher - chokidar `FSWatcher` instance
|
||||
* @param {Object} [opts] - Options!
|
||||
* @param {BeforeWatchRun} [opts.beforeRun] - Function to call before `mocha.run()`
|
||||
* @returns {Rerunner}
|
||||
* @ignore
|
||||
* @private
|
||||
*/
|
||||
const createRerunner = (mocha, watcher, {beforeRun} = {}) => {
|
||||
// Set to a `Runner` when mocha is running. Set to `null` when mocha is not
|
||||
// running.
|
||||
let runner = null;
|
||||
|
||||
// true if a file has changed during a test run
|
||||
let rerunScheduled = false;
|
||||
|
||||
const run = () => {
|
||||
try {
|
||||
mocha = beforeRun ? beforeRun({mocha, watcher}) || mocha : mocha;
|
||||
runner = mocha.run(() => {
|
||||
debug('finished watch run');
|
||||
runner = null;
|
||||
blastCache(watcher);
|
||||
if (rerunScheduled) {
|
||||
rerun();
|
||||
} else {
|
||||
console.error(`${logSymbols.info} [mocha] waiting for changes...`);
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(e.stack);
|
||||
}
|
||||
};
|
||||
|
||||
const scheduleRun = () => {
|
||||
if (rerunScheduled) {
|
||||
return;
|
||||
}
|
||||
|
||||
rerunScheduled = true;
|
||||
if (runner) {
|
||||
runner.abort();
|
||||
} else {
|
||||
rerun();
|
||||
}
|
||||
};
|
||||
|
||||
const rerun = () => {
|
||||
rerunScheduled = false;
|
||||
eraseLine();
|
||||
run();
|
||||
};
|
||||
|
||||
return {
|
||||
scheduleRun,
|
||||
run
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the list of absolute paths watched by a chokidar watcher.
|
||||
*
|
||||
* @param watcher - Instance of a chokidar watcher
|
||||
* @return {string[]} - List of absolute paths
|
||||
* @ignore
|
||||
* @private
|
||||
*/
|
||||
const getWatchedFiles = watcher => {
|
||||
const watchedDirs = watcher.getWatched();
|
||||
return Object.keys(watchedDirs).reduce(
|
||||
(acc, dir) => [
|
||||
...acc,
|
||||
...watchedDirs[dir].map(file => path.join(dir, file))
|
||||
],
|
||||
[]
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Hide the cursor.
|
||||
* @ignore
|
||||
* @private
|
||||
*/
|
||||
const hideCursor = () => {
|
||||
process.stdout.write('\u001b[?25l');
|
||||
};
|
||||
|
||||
/**
|
||||
* Show the cursor.
|
||||
* @ignore
|
||||
* @private
|
||||
*/
|
||||
const showCursor = () => {
|
||||
process.stdout.write('\u001b[?25h');
|
||||
};
|
||||
|
||||
/**
|
||||
* Erases the line on stdout
|
||||
* @private
|
||||
*/
|
||||
const eraseLine = () => {
|
||||
process.stdout.write('\u001b[2K');
|
||||
};
|
||||
|
||||
/**
|
||||
* Blast all of the watched files out of `require.cache`
|
||||
* @param {FSWatcher} watcher - chokidar FSWatcher
|
||||
* @ignore
|
||||
* @private
|
||||
*/
|
||||
const blastCache = watcher => {
|
||||
const files = getWatchedFiles(watcher);
|
||||
files.forEach(file => {
|
||||
delete require.cache[file];
|
||||
});
|
||||
debug('deleted %d file(s) from the require cache', files.length);
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback to be run before `mocha.run()` is called.
|
||||
* Optionally, it can return a new `Mocha` instance.
|
||||
* @callback BeforeWatchRun
|
||||
* @private
|
||||
* @param {{mocha: Mocha, watcher: FSWatcher}} options
|
||||
* @returns {Mocha}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Object containing run control methods
|
||||
* @typedef {Object} Rerunner
|
||||
* @private
|
||||
* @property {Function} run - Calls `mocha.run()`
|
||||
* @property {Function} scheduleRun - Schedules another call to `run`
|
||||
*/
|
||||
86
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/context.js
generated
vendored
Normal file
86
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/context.js
generated
vendored
Normal file
@ -0,0 +1,86 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module Context
|
||||
*/
|
||||
/**
|
||||
* Expose `Context`.
|
||||
*/
|
||||
|
||||
module.exports = Context;
|
||||
|
||||
/**
|
||||
* Initialize a new `Context`.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
function Context() {}
|
||||
|
||||
/**
|
||||
* Set or get the context `Runnable` to `runnable`.
|
||||
*
|
||||
* @private
|
||||
* @param {Runnable} runnable
|
||||
* @return {Context} context
|
||||
*/
|
||||
Context.prototype.runnable = function(runnable) {
|
||||
if (!arguments.length) {
|
||||
return this._runnable;
|
||||
}
|
||||
this.test = this._runnable = runnable;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set or get test timeout `ms`.
|
||||
*
|
||||
* @private
|
||||
* @param {number} ms
|
||||
* @return {Context} self
|
||||
*/
|
||||
Context.prototype.timeout = function(ms) {
|
||||
if (!arguments.length) {
|
||||
return this.runnable().timeout();
|
||||
}
|
||||
this.runnable().timeout(ms);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set or get test slowness threshold `ms`.
|
||||
*
|
||||
* @private
|
||||
* @param {number} ms
|
||||
* @return {Context} self
|
||||
*/
|
||||
Context.prototype.slow = function(ms) {
|
||||
if (!arguments.length) {
|
||||
return this.runnable().slow();
|
||||
}
|
||||
this.runnable().slow(ms);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Mark a test as skipped.
|
||||
*
|
||||
* @private
|
||||
* @throws Pending
|
||||
*/
|
||||
Context.prototype.skip = function() {
|
||||
this.runnable().skip();
|
||||
};
|
||||
|
||||
/**
|
||||
* Set or get a number of allowed retries on failed tests
|
||||
*
|
||||
* @private
|
||||
* @param {number} n
|
||||
* @return {Context} self
|
||||
*/
|
||||
Context.prototype.retries = function(n) {
|
||||
if (!arguments.length) {
|
||||
return this.runnable().retries();
|
||||
}
|
||||
this.runnable().retries(n);
|
||||
return this;
|
||||
};
|
||||
563
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/errors.js
generated
vendored
Normal file
563
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/errors.js
generated
vendored
Normal file
@ -0,0 +1,563 @@
|
||||
'use strict';
|
||||
|
||||
const {format} = require('util');
|
||||
|
||||
/**
|
||||
* Contains error codes, factory functions to create throwable error objects,
|
||||
* and warning/deprecation functions.
|
||||
* @module
|
||||
*/
|
||||
|
||||
/**
|
||||
* process.emitWarning or a polyfill
|
||||
* @see https://nodejs.org/api/process.html#process_process_emitwarning_warning_options
|
||||
* @ignore
|
||||
*/
|
||||
const emitWarning = (msg, type) => {
|
||||
if (process.emitWarning) {
|
||||
process.emitWarning(msg, type);
|
||||
} else {
|
||||
/* istanbul ignore next */
|
||||
process.nextTick(function() {
|
||||
console.warn(type + ': ' + msg);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Show a deprecation warning. Each distinct message is only displayed once.
|
||||
* Ignores empty messages.
|
||||
*
|
||||
* @param {string} [msg] - Warning to print
|
||||
* @private
|
||||
*/
|
||||
const deprecate = msg => {
|
||||
msg = String(msg);
|
||||
if (msg && !deprecate.cache[msg]) {
|
||||
deprecate.cache[msg] = true;
|
||||
emitWarning(msg, 'DeprecationWarning');
|
||||
}
|
||||
};
|
||||
deprecate.cache = {};
|
||||
|
||||
/**
|
||||
* Show a generic warning.
|
||||
* Ignores empty messages.
|
||||
*
|
||||
* @param {string} [msg] - Warning to print
|
||||
* @private
|
||||
*/
|
||||
const warn = msg => {
|
||||
if (msg) {
|
||||
emitWarning(msg);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* When Mocha throws exceptions (or rejects `Promise`s), it attempts to assign a `code` property to the `Error` object, for easier handling. These are the potential values of `code`.
|
||||
* @public
|
||||
* @namespace
|
||||
* @memberof module:lib/errors
|
||||
*/
|
||||
var constants = {
|
||||
/**
|
||||
* An unrecoverable error.
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
FATAL: 'ERR_MOCHA_FATAL',
|
||||
|
||||
/**
|
||||
* The type of an argument to a function call is invalid
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
INVALID_ARG_TYPE: 'ERR_MOCHA_INVALID_ARG_TYPE',
|
||||
|
||||
/**
|
||||
* The value of an argument to a function call is invalid
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
INVALID_ARG_VALUE: 'ERR_MOCHA_INVALID_ARG_VALUE',
|
||||
|
||||
/**
|
||||
* Something was thrown, but it wasn't an `Error`
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
INVALID_EXCEPTION: 'ERR_MOCHA_INVALID_EXCEPTION',
|
||||
|
||||
/**
|
||||
* An interface (e.g., `Mocha.interfaces`) is unknown or invalid
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
INVALID_INTERFACE: 'ERR_MOCHA_INVALID_INTERFACE',
|
||||
|
||||
/**
|
||||
* A reporter (.e.g, `Mocha.reporters`) is unknown or invalid
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
INVALID_REPORTER: 'ERR_MOCHA_INVALID_REPORTER',
|
||||
|
||||
/**
|
||||
* `done()` was called twice in a `Test` or `Hook` callback
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
MULTIPLE_DONE: 'ERR_MOCHA_MULTIPLE_DONE',
|
||||
|
||||
/**
|
||||
* No files matched the pattern provided by the user
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
NO_FILES_MATCH_PATTERN: 'ERR_MOCHA_NO_FILES_MATCH_PATTERN',
|
||||
|
||||
/**
|
||||
* Known, but unsupported behavior of some kind
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
UNSUPPORTED: 'ERR_MOCHA_UNSUPPORTED',
|
||||
|
||||
/**
|
||||
* Invalid state transition occurring in `Mocha` instance
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
INSTANCE_ALREADY_RUNNING: 'ERR_MOCHA_INSTANCE_ALREADY_RUNNING',
|
||||
|
||||
/**
|
||||
* Invalid state transition occurring in `Mocha` instance
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
INSTANCE_ALREADY_DISPOSED: 'ERR_MOCHA_INSTANCE_ALREADY_DISPOSED',
|
||||
|
||||
/**
|
||||
* Use of `only()` w/ `--forbid-only` results in this error.
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
FORBIDDEN_EXCLUSIVITY: 'ERR_MOCHA_FORBIDDEN_EXCLUSIVITY',
|
||||
|
||||
/**
|
||||
* To be thrown when a user-defined plugin implementation (e.g., `mochaHooks`) is invalid
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
INVALID_PLUGIN_IMPLEMENTATION: 'ERR_MOCHA_INVALID_PLUGIN_IMPLEMENTATION',
|
||||
|
||||
/**
|
||||
* To be thrown when a builtin or third-party plugin definition (the _definition_ of `mochaHooks`) is invalid
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
INVALID_PLUGIN_DEFINITION: 'ERR_MOCHA_INVALID_PLUGIN_DEFINITION',
|
||||
|
||||
/**
|
||||
* When a runnable exceeds its allowed run time.
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
TIMEOUT: 'ERR_MOCHA_TIMEOUT',
|
||||
|
||||
/**
|
||||
* Input file is not able to be parsed
|
||||
* @constant
|
||||
* @default
|
||||
*/
|
||||
UNPARSABLE_FILE: 'ERR_MOCHA_UNPARSABLE_FILE'
|
||||
};
|
||||
|
||||
/**
|
||||
* A set containing all string values of all Mocha error constants, for use by {@link isMochaError}.
|
||||
* @private
|
||||
*/
|
||||
const MOCHA_ERRORS = new Set(Object.values(constants));
|
||||
|
||||
/**
|
||||
* Creates an error object to be thrown when no files to be tested could be found using specified pattern.
|
||||
*
|
||||
* @public
|
||||
* @static
|
||||
* @param {string} message - Error message to be displayed.
|
||||
* @param {string} pattern - User-specified argument value.
|
||||
* @returns {Error} instance detailing the error condition
|
||||
*/
|
||||
function createNoFilesMatchPatternError(message, pattern) {
|
||||
var err = new Error(message);
|
||||
err.code = constants.NO_FILES_MATCH_PATTERN;
|
||||
err.pattern = pattern;
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error object to be thrown when the reporter specified in the options was not found.
|
||||
*
|
||||
* @public
|
||||
* @param {string} message - Error message to be displayed.
|
||||
* @param {string} reporter - User-specified reporter value.
|
||||
* @returns {Error} instance detailing the error condition
|
||||
*/
|
||||
function createInvalidReporterError(message, reporter) {
|
||||
var err = new TypeError(message);
|
||||
err.code = constants.INVALID_REPORTER;
|
||||
err.reporter = reporter;
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error object to be thrown when the interface specified in the options was not found.
|
||||
*
|
||||
* @public
|
||||
* @static
|
||||
* @param {string} message - Error message to be displayed.
|
||||
* @param {string} ui - User-specified interface value.
|
||||
* @returns {Error} instance detailing the error condition
|
||||
*/
|
||||
function createInvalidInterfaceError(message, ui) {
|
||||
var err = new Error(message);
|
||||
err.code = constants.INVALID_INTERFACE;
|
||||
err.interface = ui;
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error object to be thrown when a behavior, option, or parameter is unsupported.
|
||||
*
|
||||
* @public
|
||||
* @static
|
||||
* @param {string} message - Error message to be displayed.
|
||||
* @returns {Error} instance detailing the error condition
|
||||
*/
|
||||
function createUnsupportedError(message) {
|
||||
var err = new Error(message);
|
||||
err.code = constants.UNSUPPORTED;
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error object to be thrown when an argument is missing.
|
||||
*
|
||||
* @public
|
||||
* @static
|
||||
* @param {string} message - Error message to be displayed.
|
||||
* @param {string} argument - Argument name.
|
||||
* @param {string} expected - Expected argument datatype.
|
||||
* @returns {Error} instance detailing the error condition
|
||||
*/
|
||||
function createMissingArgumentError(message, argument, expected) {
|
||||
return createInvalidArgumentTypeError(message, argument, expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error object to be thrown when an argument did not use the supported type
|
||||
*
|
||||
* @public
|
||||
* @static
|
||||
* @param {string} message - Error message to be displayed.
|
||||
* @param {string} argument - Argument name.
|
||||
* @param {string} expected - Expected argument datatype.
|
||||
* @returns {Error} instance detailing the error condition
|
||||
*/
|
||||
function createInvalidArgumentTypeError(message, argument, expected) {
|
||||
var err = new TypeError(message);
|
||||
err.code = constants.INVALID_ARG_TYPE;
|
||||
err.argument = argument;
|
||||
err.expected = expected;
|
||||
err.actual = typeof argument;
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error object to be thrown when an argument did not use the supported value
|
||||
*
|
||||
* @public
|
||||
* @static
|
||||
* @param {string} message - Error message to be displayed.
|
||||
* @param {string} argument - Argument name.
|
||||
* @param {string} value - Argument value.
|
||||
* @param {string} [reason] - Why value is invalid.
|
||||
* @returns {Error} instance detailing the error condition
|
||||
*/
|
||||
function createInvalidArgumentValueError(message, argument, value, reason) {
|
||||
var err = new TypeError(message);
|
||||
err.code = constants.INVALID_ARG_VALUE;
|
||||
err.argument = argument;
|
||||
err.value = value;
|
||||
err.reason = typeof reason !== 'undefined' ? reason : 'is invalid';
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error object to be thrown when an exception was caught, but the `Error` is falsy or undefined.
|
||||
*
|
||||
* @public
|
||||
* @static
|
||||
* @param {string} message - Error message to be displayed.
|
||||
* @returns {Error} instance detailing the error condition
|
||||
*/
|
||||
function createInvalidExceptionError(message, value) {
|
||||
var err = new Error(message);
|
||||
err.code = constants.INVALID_EXCEPTION;
|
||||
err.valueType = typeof value;
|
||||
err.value = value;
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error object to be thrown when an unrecoverable error occurs.
|
||||
*
|
||||
* @public
|
||||
* @static
|
||||
* @param {string} message - Error message to be displayed.
|
||||
* @returns {Error} instance detailing the error condition
|
||||
*/
|
||||
function createFatalError(message, value) {
|
||||
var err = new Error(message);
|
||||
err.code = constants.FATAL;
|
||||
err.valueType = typeof value;
|
||||
err.value = value;
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically creates a plugin-type-specific error based on plugin type
|
||||
* @param {string} message - Error message
|
||||
* @param {"reporter"|"interface"} pluginType - Plugin type. Future: expand as needed
|
||||
* @param {string} [pluginId] - Name/path of plugin, if any
|
||||
* @throws When `pluginType` is not known
|
||||
* @public
|
||||
* @static
|
||||
* @returns {Error}
|
||||
*/
|
||||
function createInvalidLegacyPluginError(message, pluginType, pluginId) {
|
||||
switch (pluginType) {
|
||||
case 'reporter':
|
||||
return createInvalidReporterError(message, pluginId);
|
||||
case 'interface':
|
||||
return createInvalidInterfaceError(message, pluginId);
|
||||
default:
|
||||
throw new Error('unknown pluginType "' + pluginType + '"');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* **DEPRECATED**. Use {@link createInvalidLegacyPluginError} instead Dynamically creates a plugin-type-specific error based on plugin type
|
||||
* @deprecated
|
||||
* @param {string} message - Error message
|
||||
* @param {"reporter"|"interface"} pluginType - Plugin type. Future: expand as needed
|
||||
* @param {string} [pluginId] - Name/path of plugin, if any
|
||||
* @throws When `pluginType` is not known
|
||||
* @public
|
||||
* @static
|
||||
* @returns {Error}
|
||||
*/
|
||||
function createInvalidPluginError(...args) {
|
||||
deprecate('Use createInvalidLegacyPluginError() instead');
|
||||
return createInvalidLegacyPluginError(...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error object to be thrown when a mocha object's `run` method is executed while it is already disposed.
|
||||
* @param {string} message The error message to be displayed.
|
||||
* @param {boolean} cleanReferencesAfterRun the value of `cleanReferencesAfterRun`
|
||||
* @param {Mocha} instance the mocha instance that throw this error
|
||||
* @static
|
||||
*/
|
||||
function createMochaInstanceAlreadyDisposedError(
|
||||
message,
|
||||
cleanReferencesAfterRun,
|
||||
instance
|
||||
) {
|
||||
var err = new Error(message);
|
||||
err.code = constants.INSTANCE_ALREADY_DISPOSED;
|
||||
err.cleanReferencesAfterRun = cleanReferencesAfterRun;
|
||||
err.instance = instance;
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error object to be thrown when a mocha object's `run` method is called while a test run is in progress.
|
||||
* @param {string} message The error message to be displayed.
|
||||
* @static
|
||||
* @public
|
||||
*/
|
||||
function createMochaInstanceAlreadyRunningError(message, instance) {
|
||||
var err = new Error(message);
|
||||
err.code = constants.INSTANCE_ALREADY_RUNNING;
|
||||
err.instance = instance;
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error object to be thrown when done() is called multiple times in a test
|
||||
*
|
||||
* @public
|
||||
* @param {Runnable} runnable - Original runnable
|
||||
* @param {Error} [originalErr] - Original error, if any
|
||||
* @returns {Error} instance detailing the error condition
|
||||
* @static
|
||||
*/
|
||||
function createMultipleDoneError(runnable, originalErr) {
|
||||
var title;
|
||||
try {
|
||||
title = format('<%s>', runnable.fullTitle());
|
||||
if (runnable.parent.root) {
|
||||
title += ' (of root suite)';
|
||||
}
|
||||
} catch (ignored) {
|
||||
title = format('<%s> (of unknown suite)', runnable.title);
|
||||
}
|
||||
var message = format(
|
||||
'done() called multiple times in %s %s',
|
||||
runnable.type ? runnable.type : 'unknown runnable',
|
||||
title
|
||||
);
|
||||
if (runnable.file) {
|
||||
message += format(' of file %s', runnable.file);
|
||||
}
|
||||
if (originalErr) {
|
||||
message += format('; in addition, done() received error: %s', originalErr);
|
||||
}
|
||||
|
||||
var err = new Error(message);
|
||||
err.code = constants.MULTIPLE_DONE;
|
||||
err.valueType = typeof originalErr;
|
||||
err.value = originalErr;
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error object to be thrown when `.only()` is used with
|
||||
* `--forbid-only`.
|
||||
* @static
|
||||
* @public
|
||||
* @param {Mocha} mocha - Mocha instance
|
||||
* @returns {Error} Error with code {@link constants.FORBIDDEN_EXCLUSIVITY}
|
||||
*/
|
||||
function createForbiddenExclusivityError(mocha) {
|
||||
var err = new Error(
|
||||
mocha.isWorker
|
||||
? '`.only` is not supported in parallel mode'
|
||||
: '`.only` forbidden by --forbid-only'
|
||||
);
|
||||
err.code = constants.FORBIDDEN_EXCLUSIVITY;
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error object to be thrown when a plugin definition is invalid
|
||||
* @static
|
||||
* @param {string} msg - Error message
|
||||
* @param {PluginDefinition} [pluginDef] - Problematic plugin definition
|
||||
* @public
|
||||
* @returns {Error} Error with code {@link constants.INVALID_PLUGIN_DEFINITION}
|
||||
*/
|
||||
function createInvalidPluginDefinitionError(msg, pluginDef) {
|
||||
const err = new Error(msg);
|
||||
err.code = constants.INVALID_PLUGIN_DEFINITION;
|
||||
err.pluginDef = pluginDef;
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error object to be thrown when a plugin implementation (user code) is invalid
|
||||
* @static
|
||||
* @param {string} msg - Error message
|
||||
* @param {Object} [opts] - Plugin definition and user-supplied implementation
|
||||
* @param {PluginDefinition} [opts.pluginDef] - Plugin Definition
|
||||
* @param {*} [opts.pluginImpl] - Plugin Implementation (user-supplied)
|
||||
* @public
|
||||
* @returns {Error} Error with code {@link constants.INVALID_PLUGIN_DEFINITION}
|
||||
*/
|
||||
function createInvalidPluginImplementationError(
|
||||
msg,
|
||||
{pluginDef, pluginImpl} = {}
|
||||
) {
|
||||
const err = new Error(msg);
|
||||
err.code = constants.INVALID_PLUGIN_IMPLEMENTATION;
|
||||
err.pluginDef = pluginDef;
|
||||
err.pluginImpl = pluginImpl;
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error object to be thrown when a runnable exceeds its allowed run time.
|
||||
* @static
|
||||
* @param {string} msg - Error message
|
||||
* @param {number} [timeout] - Timeout in ms
|
||||
* @param {string} [file] - File, if given
|
||||
* @returns {MochaTimeoutError}
|
||||
*/
|
||||
function createTimeoutError(msg, timeout, file) {
|
||||
const err = new Error(msg);
|
||||
err.code = constants.TIMEOUT;
|
||||
err.timeout = timeout;
|
||||
err.file = file;
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error object to be thrown when file is unparsable
|
||||
* @public
|
||||
* @static
|
||||
* @param {string} message - Error message to be displayed.
|
||||
* @param {string} filename - File name
|
||||
* @returns {Error} Error with code {@link constants.UNPARSABLE_FILE}
|
||||
*/
|
||||
function createUnparsableFileError(message, filename) {
|
||||
var err = new Error(message);
|
||||
err.code = constants.UNPARSABLE_FILE;
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if an error came out of Mocha.
|
||||
* _Can suffer from false negatives, but not false positives._
|
||||
* @static
|
||||
* @public
|
||||
* @param {*} err - Error, or anything
|
||||
* @returns {boolean}
|
||||
*/
|
||||
const isMochaError = err =>
|
||||
Boolean(err && typeof err === 'object' && MOCHA_ERRORS.has(err.code));
|
||||
|
||||
module.exports = {
|
||||
constants,
|
||||
createFatalError,
|
||||
createForbiddenExclusivityError,
|
||||
createInvalidArgumentTypeError,
|
||||
createInvalidArgumentValueError,
|
||||
createInvalidExceptionError,
|
||||
createInvalidInterfaceError,
|
||||
createInvalidLegacyPluginError,
|
||||
createInvalidPluginDefinitionError,
|
||||
createInvalidPluginError,
|
||||
createInvalidPluginImplementationError,
|
||||
createInvalidReporterError,
|
||||
createMissingArgumentError,
|
||||
createMochaInstanceAlreadyDisposedError,
|
||||
createMochaInstanceAlreadyRunningError,
|
||||
createMultipleDoneError,
|
||||
createNoFilesMatchPatternError,
|
||||
createTimeoutError,
|
||||
createUnparsableFileError,
|
||||
createUnsupportedError,
|
||||
deprecate,
|
||||
isMochaError,
|
||||
warn
|
||||
};
|
||||
|
||||
/**
|
||||
* The error thrown when a Runnable times out
|
||||
* @memberof module:lib/errors
|
||||
* @typedef {Error} MochaTimeoutError
|
||||
* @property {constants.TIMEOUT} code - Error code
|
||||
* @property {number?} timeout Timeout in ms
|
||||
* @property {string?} file Filepath, if given
|
||||
*/
|
||||
92
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/esm-utils.js
generated
vendored
Normal file
92
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/esm-utils.js
generated
vendored
Normal file
@ -0,0 +1,92 @@
|
||||
const path = require('path');
|
||||
const url = require('url');
|
||||
|
||||
const formattedImport = async file => {
|
||||
if (path.isAbsolute(file)) {
|
||||
try {
|
||||
return await import(url.pathToFileURL(file));
|
||||
} catch (err) {
|
||||
// This is a hack created because ESM in Node.js (at least in Node v15.5.1) does not emit
|
||||
// the location of the syntax error in the error thrown.
|
||||
// This is problematic because the user can't see what file has the problem,
|
||||
// so we add the file location to the error.
|
||||
// This `if` should be removed once Node.js fixes the problem.
|
||||
if (
|
||||
err instanceof SyntaxError &&
|
||||
err.message &&
|
||||
err.stack &&
|
||||
!err.stack.includes(file)
|
||||
) {
|
||||
const newErrorWithFilename = new SyntaxError(err.message);
|
||||
newErrorWithFilename.stack = err.stack.replace(
|
||||
/^SyntaxError/,
|
||||
`SyntaxError[ @${file} ]`
|
||||
);
|
||||
throw newErrorWithFilename;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
return import(file);
|
||||
};
|
||||
|
||||
const hasStableEsmImplementation = (() => {
|
||||
const [major, minor] = process.version.split('.');
|
||||
// ESM is stable from v12.22.0 onward
|
||||
// https://nodejs.org/api/esm.html#esm_modules_ecmascript_modules
|
||||
return parseInt(major.slice(1), 10) > 12 || parseInt(minor, 10) >= 22;
|
||||
})();
|
||||
|
||||
exports.requireOrImport = hasStableEsmImplementation
|
||||
? async file => {
|
||||
if (path.extname(file) === '.mjs') {
|
||||
return formattedImport(file);
|
||||
}
|
||||
try {
|
||||
return dealWithExports(await formattedImport(file));
|
||||
} catch (err) {
|
||||
if (
|
||||
err.code === 'ERR_MODULE_NOT_FOUND' ||
|
||||
err.code === 'ERR_UNKNOWN_FILE_EXTENSION'
|
||||
) {
|
||||
return require(file);
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
: implementationOfRequireOrImportForUnstableEsm;
|
||||
|
||||
function dealWithExports(module) {
|
||||
if (module.default) {
|
||||
return module.default;
|
||||
} else {
|
||||
return {...module, default: undefined};
|
||||
}
|
||||
}
|
||||
|
||||
exports.loadFilesAsync = async (files, preLoadFunc, postLoadFunc) => {
|
||||
for (const file of files) {
|
||||
preLoadFunc(file);
|
||||
const result = await exports.requireOrImport(path.resolve(file));
|
||||
postLoadFunc(file, result);
|
||||
}
|
||||
};
|
||||
|
||||
/* istanbul ignore next */
|
||||
async function implementationOfRequireOrImportForUnstableEsm(file) {
|
||||
if (path.extname(file) === '.mjs') {
|
||||
return formattedImport(file);
|
||||
}
|
||||
// This is currently the only known way of figuring out whether a file is CJS or ESM in
|
||||
// Node.js that doesn't necessitate calling `import` first.
|
||||
try {
|
||||
return require(file);
|
||||
} catch (err) {
|
||||
if (err.code === 'ERR_REQUIRE_ESM') {
|
||||
return formattedImport(file);
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
83
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/hook.js
generated
vendored
Normal file
83
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/hook.js
generated
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
'use strict';
|
||||
|
||||
var Runnable = require('./runnable');
|
||||
const {inherits, constants} = require('./utils');
|
||||
const {MOCHA_ID_PROP_NAME} = constants;
|
||||
|
||||
/**
|
||||
* Expose `Hook`.
|
||||
*/
|
||||
|
||||
module.exports = Hook;
|
||||
|
||||
/**
|
||||
* Initialize a new `Hook` with the given `title` and callback `fn`
|
||||
*
|
||||
* @class
|
||||
* @extends Runnable
|
||||
* @param {String} title
|
||||
* @param {Function} fn
|
||||
*/
|
||||
function Hook(title, fn) {
|
||||
Runnable.call(this, title, fn);
|
||||
this.type = 'hook';
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Runnable.prototype`.
|
||||
*/
|
||||
inherits(Hook, Runnable);
|
||||
|
||||
/**
|
||||
* Resets the state for a next run.
|
||||
*/
|
||||
Hook.prototype.reset = function() {
|
||||
Runnable.prototype.reset.call(this);
|
||||
delete this._error;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get or set the test `err`.
|
||||
*
|
||||
* @memberof Hook
|
||||
* @public
|
||||
* @param {Error} err
|
||||
* @return {Error}
|
||||
*/
|
||||
Hook.prototype.error = function(err) {
|
||||
if (!arguments.length) {
|
||||
err = this._error;
|
||||
this._error = null;
|
||||
return err;
|
||||
}
|
||||
|
||||
this._error = err;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an object suitable for IPC.
|
||||
* Functions are represented by keys beginning with `$$`.
|
||||
* @private
|
||||
* @returns {Object}
|
||||
*/
|
||||
Hook.prototype.serialize = function serialize() {
|
||||
return {
|
||||
$$isPending: this.isPending(),
|
||||
$$titlePath: this.titlePath(),
|
||||
ctx:
|
||||
this.ctx && this.ctx.currentTest
|
||||
? {
|
||||
currentTest: {
|
||||
title: this.ctx.currentTest.title,
|
||||
[MOCHA_ID_PROP_NAME]: this.ctx.currentTest.id
|
||||
}
|
||||
}
|
||||
: {},
|
||||
parent: {
|
||||
[MOCHA_ID_PROP_NAME]: this.parent.id
|
||||
},
|
||||
title: this.title,
|
||||
type: this.type,
|
||||
[MOCHA_ID_PROP_NAME]: this.id
|
||||
};
|
||||
};
|
||||
111
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/interfaces/bdd.js
generated
vendored
Normal file
111
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/interfaces/bdd.js
generated
vendored
Normal file
@ -0,0 +1,111 @@
|
||||
'use strict';
|
||||
|
||||
var Test = require('../test');
|
||||
var EVENT_FILE_PRE_REQUIRE = require('../suite').constants
|
||||
.EVENT_FILE_PRE_REQUIRE;
|
||||
|
||||
/**
|
||||
* BDD-style interface:
|
||||
*
|
||||
* describe('Array', function() {
|
||||
* describe('#indexOf()', function() {
|
||||
* it('should return -1 when not present', function() {
|
||||
* // ...
|
||||
* });
|
||||
*
|
||||
* it('should return the index when present', function() {
|
||||
* // ...
|
||||
* });
|
||||
* });
|
||||
* });
|
||||
*
|
||||
* @param {Suite} suite Root suite.
|
||||
*/
|
||||
module.exports = function bddInterface(suite) {
|
||||
var suites = [suite];
|
||||
|
||||
suite.on(EVENT_FILE_PRE_REQUIRE, function(context, file, mocha) {
|
||||
var common = require('./common')(suites, context, mocha);
|
||||
|
||||
context.before = common.before;
|
||||
context.after = common.after;
|
||||
context.beforeEach = common.beforeEach;
|
||||
context.afterEach = common.afterEach;
|
||||
context.run = mocha.options.delay && common.runWithSuite(suite);
|
||||
/**
|
||||
* Describe a "suite" with the given `title`
|
||||
* and callback `fn` containing nested suites
|
||||
* and/or tests.
|
||||
*/
|
||||
|
||||
context.describe = context.context = function(title, fn) {
|
||||
return common.suite.create({
|
||||
title: title,
|
||||
file: file,
|
||||
fn: fn
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Pending describe.
|
||||
*/
|
||||
|
||||
context.xdescribe = context.xcontext = context.describe.skip = function(
|
||||
title,
|
||||
fn
|
||||
) {
|
||||
return common.suite.skip({
|
||||
title: title,
|
||||
file: file,
|
||||
fn: fn
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Exclusive suite.
|
||||
*/
|
||||
|
||||
context.describe.only = function(title, fn) {
|
||||
return common.suite.only({
|
||||
title: title,
|
||||
file: file,
|
||||
fn: fn
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Describe a specification or test-case
|
||||
* with the given `title` and callback `fn`
|
||||
* acting as a thunk.
|
||||
*/
|
||||
|
||||
context.it = context.specify = function(title, fn) {
|
||||
var suite = suites[0];
|
||||
if (suite.isPending()) {
|
||||
fn = null;
|
||||
}
|
||||
var test = new Test(title, fn);
|
||||
test.file = file;
|
||||
suite.addTest(test);
|
||||
return test;
|
||||
};
|
||||
|
||||
/**
|
||||
* Exclusive test-case.
|
||||
*/
|
||||
|
||||
context.it.only = function(title, fn) {
|
||||
return common.test.only(mocha, context.it(title, fn));
|
||||
};
|
||||
|
||||
/**
|
||||
* Pending test case.
|
||||
*/
|
||||
|
||||
context.xit = context.xspecify = context.it.skip = function(title) {
|
||||
return context.it(title);
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.description = 'BDD or RSpec style [default]';
|
||||
193
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/interfaces/common.js
generated
vendored
Normal file
193
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/interfaces/common.js
generated
vendored
Normal file
@ -0,0 +1,193 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
@module interfaces/common
|
||||
*/
|
||||
|
||||
var Suite = require('../suite');
|
||||
var errors = require('../errors');
|
||||
var createMissingArgumentError = errors.createMissingArgumentError;
|
||||
var createUnsupportedError = errors.createUnsupportedError;
|
||||
var createForbiddenExclusivityError = errors.createForbiddenExclusivityError;
|
||||
|
||||
/**
|
||||
* Functions common to more than one interface.
|
||||
*
|
||||
* @private
|
||||
* @param {Suite[]} suites
|
||||
* @param {Context} context
|
||||
* @param {Mocha} mocha
|
||||
* @return {Object} An object containing common functions.
|
||||
*/
|
||||
module.exports = function(suites, context, mocha) {
|
||||
/**
|
||||
* Check if the suite should be tested.
|
||||
*
|
||||
* @private
|
||||
* @param {Suite} suite - suite to check
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function shouldBeTested(suite) {
|
||||
return (
|
||||
!mocha.options.grep ||
|
||||
(mocha.options.grep &&
|
||||
mocha.options.grep.test(suite.fullTitle()) &&
|
||||
!mocha.options.invert)
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* This is only present if flag --delay is passed into Mocha. It triggers
|
||||
* root suite execution.
|
||||
*
|
||||
* @param {Suite} suite The root suite.
|
||||
* @return {Function} A function which runs the root suite
|
||||
*/
|
||||
runWithSuite: function runWithSuite(suite) {
|
||||
return function run() {
|
||||
suite.run();
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Execute before running tests.
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {Function} fn
|
||||
*/
|
||||
before: function(name, fn) {
|
||||
suites[0].beforeAll(name, fn);
|
||||
},
|
||||
|
||||
/**
|
||||
* Execute after running tests.
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {Function} fn
|
||||
*/
|
||||
after: function(name, fn) {
|
||||
suites[0].afterAll(name, fn);
|
||||
},
|
||||
|
||||
/**
|
||||
* Execute before each test case.
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {Function} fn
|
||||
*/
|
||||
beforeEach: function(name, fn) {
|
||||
suites[0].beforeEach(name, fn);
|
||||
},
|
||||
|
||||
/**
|
||||
* Execute after each test case.
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {Function} fn
|
||||
*/
|
||||
afterEach: function(name, fn) {
|
||||
suites[0].afterEach(name, fn);
|
||||
},
|
||||
|
||||
suite: {
|
||||
/**
|
||||
* Create an exclusive Suite; convenience function
|
||||
* See docstring for create() below.
|
||||
*
|
||||
* @param {Object} opts
|
||||
* @returns {Suite}
|
||||
*/
|
||||
only: function only(opts) {
|
||||
if (mocha.options.forbidOnly) {
|
||||
throw createForbiddenExclusivityError(mocha);
|
||||
}
|
||||
opts.isOnly = true;
|
||||
return this.create(opts);
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a Suite, but skip it; convenience function
|
||||
* See docstring for create() below.
|
||||
*
|
||||
* @param {Object} opts
|
||||
* @returns {Suite}
|
||||
*/
|
||||
skip: function skip(opts) {
|
||||
opts.pending = true;
|
||||
return this.create(opts);
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a suite.
|
||||
*
|
||||
* @param {Object} opts Options
|
||||
* @param {string} opts.title Title of Suite
|
||||
* @param {Function} [opts.fn] Suite Function (not always applicable)
|
||||
* @param {boolean} [opts.pending] Is Suite pending?
|
||||
* @param {string} [opts.file] Filepath where this Suite resides
|
||||
* @param {boolean} [opts.isOnly] Is Suite exclusive?
|
||||
* @returns {Suite}
|
||||
*/
|
||||
create: function create(opts) {
|
||||
var suite = Suite.create(suites[0], opts.title);
|
||||
suite.pending = Boolean(opts.pending);
|
||||
suite.file = opts.file;
|
||||
suites.unshift(suite);
|
||||
if (opts.isOnly) {
|
||||
suite.markOnly();
|
||||
}
|
||||
if (
|
||||
suite.pending &&
|
||||
mocha.options.forbidPending &&
|
||||
shouldBeTested(suite)
|
||||
) {
|
||||
throw createUnsupportedError('Pending test forbidden');
|
||||
}
|
||||
if (typeof opts.fn === 'function') {
|
||||
opts.fn.call(suite);
|
||||
suites.shift();
|
||||
} else if (typeof opts.fn === 'undefined' && !suite.pending) {
|
||||
throw createMissingArgumentError(
|
||||
'Suite "' +
|
||||
suite.fullTitle() +
|
||||
'" was defined but no callback was supplied. ' +
|
||||
'Supply a callback or explicitly skip the suite.',
|
||||
'callback',
|
||||
'function'
|
||||
);
|
||||
} else if (!opts.fn && suite.pending) {
|
||||
suites.shift();
|
||||
}
|
||||
|
||||
return suite;
|
||||
}
|
||||
},
|
||||
|
||||
test: {
|
||||
/**
|
||||
* Exclusive test-case.
|
||||
*
|
||||
* @param {Object} mocha
|
||||
* @param {Function} test
|
||||
* @returns {*}
|
||||
*/
|
||||
only: function(mocha, test) {
|
||||
if (mocha.options.forbidOnly) {
|
||||
throw createForbiddenExclusivityError(mocha);
|
||||
}
|
||||
test.markOnly();
|
||||
return test;
|
||||
},
|
||||
|
||||
/**
|
||||
* Pending test case.
|
||||
*
|
||||
* @param {string} title
|
||||
*/
|
||||
skip: function(title) {
|
||||
context.test(title);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
60
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/interfaces/exports.js
generated
vendored
Normal file
60
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/interfaces/exports.js
generated
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
'use strict';
|
||||
var Suite = require('../suite');
|
||||
var Test = require('../test');
|
||||
|
||||
/**
|
||||
* Exports-style (as Node.js module) interface:
|
||||
*
|
||||
* exports.Array = {
|
||||
* '#indexOf()': {
|
||||
* 'should return -1 when the value is not present': function() {
|
||||
*
|
||||
* },
|
||||
*
|
||||
* 'should return the correct index when the value is present': function() {
|
||||
*
|
||||
* }
|
||||
* }
|
||||
* };
|
||||
*
|
||||
* @param {Suite} suite Root suite.
|
||||
*/
|
||||
module.exports = function(suite) {
|
||||
var suites = [suite];
|
||||
|
||||
suite.on(Suite.constants.EVENT_FILE_REQUIRE, visit);
|
||||
|
||||
function visit(obj, file) {
|
||||
var suite;
|
||||
for (var key in obj) {
|
||||
if (typeof obj[key] === 'function') {
|
||||
var fn = obj[key];
|
||||
switch (key) {
|
||||
case 'before':
|
||||
suites[0].beforeAll(fn);
|
||||
break;
|
||||
case 'after':
|
||||
suites[0].afterAll(fn);
|
||||
break;
|
||||
case 'beforeEach':
|
||||
suites[0].beforeEach(fn);
|
||||
break;
|
||||
case 'afterEach':
|
||||
suites[0].afterEach(fn);
|
||||
break;
|
||||
default:
|
||||
var test = new Test(key, fn);
|
||||
test.file = file;
|
||||
suites[0].addTest(test);
|
||||
}
|
||||
} else {
|
||||
suite = Suite.create(suites[0], key);
|
||||
suites.unshift(suite);
|
||||
visit(obj[key], file);
|
||||
suites.shift();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.description = 'Node.js module ("exports") style';
|
||||
6
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/interfaces/index.js
generated
vendored
Normal file
6
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/interfaces/index.js
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
exports.bdd = require('./bdd');
|
||||
exports.tdd = require('./tdd');
|
||||
exports.qunit = require('./qunit');
|
||||
exports.exports = require('./exports');
|
||||
98
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/interfaces/qunit.js
generated
vendored
Normal file
98
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/interfaces/qunit.js
generated
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
'use strict';
|
||||
|
||||
var Test = require('../test');
|
||||
var EVENT_FILE_PRE_REQUIRE = require('../suite').constants
|
||||
.EVENT_FILE_PRE_REQUIRE;
|
||||
|
||||
/**
|
||||
* QUnit-style interface:
|
||||
*
|
||||
* suite('Array');
|
||||
*
|
||||
* test('#length', function() {
|
||||
* var arr = [1,2,3];
|
||||
* ok(arr.length == 3);
|
||||
* });
|
||||
*
|
||||
* test('#indexOf()', function() {
|
||||
* var arr = [1,2,3];
|
||||
* ok(arr.indexOf(1) == 0);
|
||||
* ok(arr.indexOf(2) == 1);
|
||||
* ok(arr.indexOf(3) == 2);
|
||||
* });
|
||||
*
|
||||
* suite('String');
|
||||
*
|
||||
* test('#length', function() {
|
||||
* ok('foo'.length == 3);
|
||||
* });
|
||||
*
|
||||
* @param {Suite} suite Root suite.
|
||||
*/
|
||||
module.exports = function qUnitInterface(suite) {
|
||||
var suites = [suite];
|
||||
|
||||
suite.on(EVENT_FILE_PRE_REQUIRE, function(context, file, mocha) {
|
||||
var common = require('./common')(suites, context, mocha);
|
||||
|
||||
context.before = common.before;
|
||||
context.after = common.after;
|
||||
context.beforeEach = common.beforeEach;
|
||||
context.afterEach = common.afterEach;
|
||||
context.run = mocha.options.delay && common.runWithSuite(suite);
|
||||
/**
|
||||
* Describe a "suite" with the given `title`.
|
||||
*/
|
||||
|
||||
context.suite = function(title) {
|
||||
if (suites.length > 1) {
|
||||
suites.shift();
|
||||
}
|
||||
return common.suite.create({
|
||||
title: title,
|
||||
file: file,
|
||||
fn: false
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Exclusive Suite.
|
||||
*/
|
||||
|
||||
context.suite.only = function(title) {
|
||||
if (suites.length > 1) {
|
||||
suites.shift();
|
||||
}
|
||||
return common.suite.only({
|
||||
title: title,
|
||||
file: file,
|
||||
fn: false
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Describe a specification or test-case
|
||||
* with the given `title` and callback `fn`
|
||||
* acting as a thunk.
|
||||
*/
|
||||
|
||||
context.test = function(title, fn) {
|
||||
var test = new Test(title, fn);
|
||||
test.file = file;
|
||||
suites[0].addTest(test);
|
||||
return test;
|
||||
};
|
||||
|
||||
/**
|
||||
* Exclusive test-case.
|
||||
*/
|
||||
|
||||
context.test.only = function(title, fn) {
|
||||
return common.test.only(mocha, context.test(title, fn));
|
||||
};
|
||||
|
||||
context.test.skip = common.test.skip;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.description = 'QUnit style';
|
||||
106
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/interfaces/tdd.js
generated
vendored
Normal file
106
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/interfaces/tdd.js
generated
vendored
Normal file
@ -0,0 +1,106 @@
|
||||
'use strict';
|
||||
|
||||
var Test = require('../test');
|
||||
var EVENT_FILE_PRE_REQUIRE = require('../suite').constants
|
||||
.EVENT_FILE_PRE_REQUIRE;
|
||||
|
||||
/**
|
||||
* TDD-style interface:
|
||||
*
|
||||
* suite('Array', function() {
|
||||
* suite('#indexOf()', function() {
|
||||
* suiteSetup(function() {
|
||||
*
|
||||
* });
|
||||
*
|
||||
* test('should return -1 when not present', function() {
|
||||
*
|
||||
* });
|
||||
*
|
||||
* test('should return the index when present', function() {
|
||||
*
|
||||
* });
|
||||
*
|
||||
* suiteTeardown(function() {
|
||||
*
|
||||
* });
|
||||
* });
|
||||
* });
|
||||
*
|
||||
* @param {Suite} suite Root suite.
|
||||
*/
|
||||
module.exports = function(suite) {
|
||||
var suites = [suite];
|
||||
|
||||
suite.on(EVENT_FILE_PRE_REQUIRE, function(context, file, mocha) {
|
||||
var common = require('./common')(suites, context, mocha);
|
||||
|
||||
context.setup = common.beforeEach;
|
||||
context.teardown = common.afterEach;
|
||||
context.suiteSetup = common.before;
|
||||
context.suiteTeardown = common.after;
|
||||
context.run = mocha.options.delay && common.runWithSuite(suite);
|
||||
|
||||
/**
|
||||
* Describe a "suite" with the given `title` and callback `fn` containing
|
||||
* nested suites and/or tests.
|
||||
*/
|
||||
context.suite = function(title, fn) {
|
||||
return common.suite.create({
|
||||
title: title,
|
||||
file: file,
|
||||
fn: fn
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Pending suite.
|
||||
*/
|
||||
context.suite.skip = function(title, fn) {
|
||||
return common.suite.skip({
|
||||
title: title,
|
||||
file: file,
|
||||
fn: fn
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Exclusive test-case.
|
||||
*/
|
||||
context.suite.only = function(title, fn) {
|
||||
return common.suite.only({
|
||||
title: title,
|
||||
file: file,
|
||||
fn: fn
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Describe a specification or test-case with the given `title` and
|
||||
* callback `fn` acting as a thunk.
|
||||
*/
|
||||
context.test = function(title, fn) {
|
||||
var suite = suites[0];
|
||||
if (suite.isPending()) {
|
||||
fn = null;
|
||||
}
|
||||
var test = new Test(title, fn);
|
||||
test.file = file;
|
||||
suite.addTest(test);
|
||||
return test;
|
||||
};
|
||||
|
||||
/**
|
||||
* Exclusive test-case.
|
||||
*/
|
||||
|
||||
context.test.only = function(title, fn) {
|
||||
return common.test.only(mocha, context.test(title, fn));
|
||||
};
|
||||
|
||||
context.test.skip = common.test.skip;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.description =
|
||||
'traditional "suite"/"test" instead of BDD\'s "describe"/"it"';
|
||||
1365
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/mocha.js
generated
vendored
Normal file
1365
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/mocha.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
10
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/mocharc.json
generated
vendored
Normal file
10
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/mocharc.json
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"diff": true,
|
||||
"extension": ["js", "cjs", "mjs"],
|
||||
"package": "./package.json",
|
||||
"reporter": "spec",
|
||||
"slow": 75,
|
||||
"timeout": 2000,
|
||||
"ui": "bdd",
|
||||
"watch-ignore": ["node_modules", ".git"]
|
||||
}
|
||||
172
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/nodejs/buffered-worker-pool.js
generated
vendored
Normal file
172
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/nodejs/buffered-worker-pool.js
generated
vendored
Normal file
@ -0,0 +1,172 @@
|
||||
/**
|
||||
* A wrapper around a third-party child process worker pool implementation.
|
||||
* Used by {@link module:buffered-runner}.
|
||||
* @private
|
||||
* @module buffered-worker-pool
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const serializeJavascript = require('serialize-javascript');
|
||||
const workerpool = require('workerpool');
|
||||
const {deserialize} = require('./serializer');
|
||||
const debug = require('debug')('mocha:parallel:buffered-worker-pool');
|
||||
const {createInvalidArgumentTypeError} = require('../errors');
|
||||
|
||||
const WORKER_PATH = require.resolve('./worker.js');
|
||||
|
||||
/**
|
||||
* A mapping of Mocha `Options` objects to serialized values.
|
||||
*
|
||||
* This is helpful because we tend to same the same options over and over
|
||||
* over IPC.
|
||||
* @type {WeakMap<Options,string>}
|
||||
*/
|
||||
let optionsCache = new WeakMap();
|
||||
|
||||
/**
|
||||
* These options are passed into the [workerpool](https://npm.im/workerpool) module.
|
||||
* @type {Partial<WorkerPoolOptions>}
|
||||
*/
|
||||
const WORKER_POOL_DEFAULT_OPTS = {
|
||||
// use child processes, not worker threads!
|
||||
workerType: 'process',
|
||||
// ensure the same flags sent to `node` for this `mocha` invocation are passed
|
||||
// along to children
|
||||
forkOpts: {execArgv: process.execArgv},
|
||||
maxWorkers: workerpool.cpus - 1
|
||||
};
|
||||
|
||||
/**
|
||||
* A wrapper around a third-party worker pool implementation.
|
||||
* @private
|
||||
*/
|
||||
class BufferedWorkerPool {
|
||||
/**
|
||||
* Creates an underlying worker pool instance; determines max worker count
|
||||
* @param {Partial<WorkerPoolOptions>} [opts] - Options
|
||||
*/
|
||||
constructor(opts = {}) {
|
||||
const maxWorkers = Math.max(
|
||||
1,
|
||||
typeof opts.maxWorkers === 'undefined'
|
||||
? WORKER_POOL_DEFAULT_OPTS.maxWorkers
|
||||
: opts.maxWorkers
|
||||
);
|
||||
|
||||
/* istanbul ignore next */
|
||||
if (workerpool.cpus < 2) {
|
||||
// TODO: decide whether we should warn
|
||||
debug(
|
||||
'not enough CPU cores available to run multiple jobs; avoid --parallel on this machine'
|
||||
);
|
||||
} else if (maxWorkers >= workerpool.cpus) {
|
||||
// TODO: decide whether we should warn
|
||||
debug(
|
||||
'%d concurrent job(s) requested, but only %d core(s) available',
|
||||
maxWorkers,
|
||||
workerpool.cpus
|
||||
);
|
||||
}
|
||||
/* istanbul ignore next */
|
||||
debug(
|
||||
'run(): starting worker pool of max size %d, using node args: %s',
|
||||
maxWorkers,
|
||||
process.execArgv.join(' ')
|
||||
);
|
||||
|
||||
this.options = {...WORKER_POOL_DEFAULT_OPTS, opts, maxWorkers};
|
||||
this._pool = workerpool.pool(WORKER_PATH, this.options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Terminates all workers in the pool.
|
||||
* @param {boolean} [force] - Whether to force-kill workers. By default, lets workers finish their current task before termination.
|
||||
* @private
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async terminate(force = false) {
|
||||
/* istanbul ignore next */
|
||||
debug('terminate(): terminating with force = %s', force);
|
||||
return this._pool.terminate(force);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a test file run to the worker pool queue for execution by a worker process.
|
||||
*
|
||||
* Handles serialization/deserialization.
|
||||
*
|
||||
* @param {string} filepath - Filepath of test
|
||||
* @param {Options} [options] - Options for Mocha instance
|
||||
* @private
|
||||
* @returns {Promise<SerializedWorkerResult>}
|
||||
*/
|
||||
async run(filepath, options = {}) {
|
||||
if (!filepath || typeof filepath !== 'string') {
|
||||
throw createInvalidArgumentTypeError(
|
||||
'Expected a non-empty filepath',
|
||||
'filepath',
|
||||
'string'
|
||||
);
|
||||
}
|
||||
const serializedOptions = BufferedWorkerPool.serializeOptions(options);
|
||||
const result = await this._pool.exec('run', [filepath, serializedOptions]);
|
||||
return deserialize(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns stats about the state of the worker processes in the pool.
|
||||
*
|
||||
* Used for debugging.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
stats() {
|
||||
return this._pool.stats();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a {@link WorkerPool}.
|
||||
* @private
|
||||
*/
|
||||
static create(...args) {
|
||||
return new BufferedWorkerPool(...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given Mocha options object `opts`, serialize into a format suitable for
|
||||
* transmission over IPC.
|
||||
*
|
||||
* @param {Options} [opts] - Mocha options
|
||||
* @private
|
||||
* @returns {string} Serialized options
|
||||
*/
|
||||
static serializeOptions(opts = {}) {
|
||||
if (!optionsCache.has(opts)) {
|
||||
const serialized = serializeJavascript(opts, {
|
||||
unsafe: true, // this means we don't care about XSS
|
||||
ignoreFunction: true // do not serialize functions
|
||||
});
|
||||
optionsCache.set(opts, serialized);
|
||||
/* istanbul ignore next */
|
||||
debug(
|
||||
'serializeOptions(): serialized options %O to: %s',
|
||||
opts,
|
||||
serialized
|
||||
);
|
||||
}
|
||||
return optionsCache.get(opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets internal cache of serialized options objects.
|
||||
*
|
||||
* For testing/debugging
|
||||
* @private
|
||||
*/
|
||||
static resetOptionsCache() {
|
||||
optionsCache = new WeakMap();
|
||||
}
|
||||
}
|
||||
|
||||
exports.BufferedWorkerPool = BufferedWorkerPool;
|
||||
15
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/nodejs/file-unloader.js
generated
vendored
Normal file
15
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/nodejs/file-unloader.js
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* This module should not be in the browser bundle, so it's here.
|
||||
* @private
|
||||
* @module
|
||||
*/
|
||||
|
||||
/**
|
||||
* Deletes a file from the `require` cache.
|
||||
* @param {string} file - File
|
||||
*/
|
||||
exports.unloadFile = file => {
|
||||
delete require.cache[require.resolve(file)];
|
||||
};
|
||||
137
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/nodejs/growl.js
generated
vendored
Normal file
137
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/nodejs/growl.js
generated
vendored
Normal file
@ -0,0 +1,137 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Desktop Notifications module.
|
||||
* @module Growl
|
||||
*/
|
||||
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const {sync: which} = require('which');
|
||||
const {EVENT_RUN_END} = require('../runner').constants;
|
||||
const {isBrowser} = require('../utils');
|
||||
|
||||
/**
|
||||
* @summary
|
||||
* Checks if Growl notification support seems likely.
|
||||
*
|
||||
* @description
|
||||
* Glosses over the distinction between an unsupported platform
|
||||
* and one that lacks prerequisite software installations.
|
||||
*
|
||||
* @public
|
||||
* @see {@link https://github.com/tj/node-growl/blob/master/README.md|Prerequisite Installs}
|
||||
* @see {@link Mocha#growl}
|
||||
* @see {@link Mocha#isGrowlCapable}
|
||||
* @return {boolean} whether Growl notification support can be expected
|
||||
*/
|
||||
exports.isCapable = () => {
|
||||
if (!isBrowser()) {
|
||||
return getSupportBinaries().reduce(
|
||||
(acc, binary) => acc || Boolean(which(binary, {nothrow: true})),
|
||||
false
|
||||
);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Implements desktop notifications as a pseudo-reporter.
|
||||
*
|
||||
* @public
|
||||
* @see {@link Mocha#_growl}
|
||||
* @param {Runner} runner - Runner instance.
|
||||
*/
|
||||
exports.notify = runner => {
|
||||
runner.once(EVENT_RUN_END, () => {
|
||||
display(runner);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Displays the notification.
|
||||
*
|
||||
* @private
|
||||
* @param {Runner} runner - Runner instance.
|
||||
*/
|
||||
const display = runner => {
|
||||
const growl = require('growl');
|
||||
const stats = runner.stats;
|
||||
const symbol = {
|
||||
cross: '\u274C',
|
||||
tick: '\u2705'
|
||||
};
|
||||
let _message;
|
||||
let message;
|
||||
let title;
|
||||
|
||||
if (stats.failures) {
|
||||
_message = `${stats.failures} of ${stats.tests} tests failed`;
|
||||
message = `${symbol.cross} ${_message}`;
|
||||
title = 'Failed';
|
||||
} else {
|
||||
_message = `${stats.passes} tests passed in ${stats.duration}ms`;
|
||||
message = `${symbol.tick} ${_message}`;
|
||||
title = 'Passed';
|
||||
}
|
||||
|
||||
// Send notification
|
||||
const options = {
|
||||
image: logo(),
|
||||
name: 'mocha',
|
||||
title
|
||||
};
|
||||
growl(message, options, onCompletion);
|
||||
};
|
||||
|
||||
/**
|
||||
* @summary
|
||||
* Callback for result of attempted Growl notification.
|
||||
*
|
||||
* @description
|
||||
* Despite its appearance, this is <strong>not</strong> an Error-first
|
||||
* callback -- all parameters are populated regardless of success.
|
||||
*
|
||||
* @private
|
||||
* @callback Growl~growlCB
|
||||
* @param {*} err - Error object, or <code>null</code> if successful.
|
||||
*/
|
||||
function onCompletion(err) {
|
||||
if (err) {
|
||||
// As notifications are tangential to our purpose, just log the error.
|
||||
const message =
|
||||
err.code === 'ENOENT' ? 'prerequisite software not found' : err.message;
|
||||
console.error('notification error:', message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Mocha logo image path.
|
||||
*
|
||||
* @private
|
||||
* @return {string} Pathname of Mocha logo
|
||||
*/
|
||||
const logo = () => {
|
||||
return path.join(__dirname, '..', 'assets', 'mocha-logo-96.png');
|
||||
};
|
||||
|
||||
/**
|
||||
* @summary
|
||||
* Gets platform-specific Growl support binaries.
|
||||
*
|
||||
* @description
|
||||
* Somewhat brittle dependency on `growl` package implementation, but it
|
||||
* rarely changes.
|
||||
*
|
||||
* @private
|
||||
* @see {@link https://github.com/tj/node-growl/blob/master/lib/growl.js#L28-L126|setupCmd}
|
||||
* @return {string[]} names of Growl support binaries
|
||||
*/
|
||||
const getSupportBinaries = () => {
|
||||
const binaries = {
|
||||
Darwin: ['terminal-notifier', 'growlnotify'],
|
||||
Linux: ['notify-send', 'growl'],
|
||||
Windows_NT: ['growlnotify.exe']
|
||||
};
|
||||
return binaries[os.type()] || [];
|
||||
};
|
||||
433
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/nodejs/parallel-buffered-runner.js
generated
vendored
Normal file
433
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/nodejs/parallel-buffered-runner.js
generated
vendored
Normal file
@ -0,0 +1,433 @@
|
||||
/**
|
||||
* A test Runner that uses a {@link module:buffered-worker-pool}.
|
||||
* @module parallel-buffered-runner
|
||||
* @private
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const allSettled = require('@ungap/promise-all-settled').bind(Promise);
|
||||
const Runner = require('../runner');
|
||||
const {EVENT_RUN_BEGIN, EVENT_RUN_END} = Runner.constants;
|
||||
const debug = require('debug')('mocha:parallel:parallel-buffered-runner');
|
||||
const {BufferedWorkerPool} = require('./buffered-worker-pool');
|
||||
const {setInterval, clearInterval} = global;
|
||||
const {createMap, constants} = require('../utils');
|
||||
const {MOCHA_ID_PROP_NAME} = constants;
|
||||
const {createFatalError} = require('../errors');
|
||||
|
||||
const DEFAULT_WORKER_REPORTER = require.resolve(
|
||||
'./reporters/parallel-buffered'
|
||||
);
|
||||
|
||||
/**
|
||||
* List of options to _not_ serialize for transmission to workers
|
||||
*/
|
||||
const DENY_OPTIONS = [
|
||||
'globalSetup',
|
||||
'globalTeardown',
|
||||
'parallel',
|
||||
'p',
|
||||
'jobs',
|
||||
'j'
|
||||
];
|
||||
|
||||
/**
|
||||
* Outputs a debug statement with worker stats
|
||||
* @param {BufferedWorkerPool} pool - Worker pool
|
||||
*/
|
||||
/* istanbul ignore next */
|
||||
const debugStats = pool => {
|
||||
const {totalWorkers, busyWorkers, idleWorkers, pendingTasks} = pool.stats();
|
||||
debug(
|
||||
'%d/%d busy workers; %d idle; %d tasks queued',
|
||||
busyWorkers,
|
||||
totalWorkers,
|
||||
idleWorkers,
|
||||
pendingTasks
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* The interval at which we will display stats for worker processes in debug mode
|
||||
*/
|
||||
const DEBUG_STATS_INTERVAL = 5000;
|
||||
|
||||
const ABORTED = 'ABORTED';
|
||||
const IDLE = 'IDLE';
|
||||
const ABORTING = 'ABORTING';
|
||||
const RUNNING = 'RUNNING';
|
||||
const BAILING = 'BAILING';
|
||||
const BAILED = 'BAILED';
|
||||
const COMPLETE = 'COMPLETE';
|
||||
|
||||
const states = createMap({
|
||||
[IDLE]: new Set([RUNNING, ABORTING]),
|
||||
[RUNNING]: new Set([COMPLETE, BAILING, ABORTING]),
|
||||
[COMPLETE]: new Set(),
|
||||
[ABORTED]: new Set(),
|
||||
[ABORTING]: new Set([ABORTED]),
|
||||
[BAILING]: new Set([BAILED, ABORTING]),
|
||||
[BAILED]: new Set([COMPLETE, ABORTING])
|
||||
});
|
||||
|
||||
/**
|
||||
* This `Runner` delegates tests runs to worker threads. Does not execute any
|
||||
* {@link Runnable}s by itself!
|
||||
* @public
|
||||
*/
|
||||
class ParallelBufferedRunner extends Runner {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
let state = IDLE;
|
||||
Object.defineProperty(this, '_state', {
|
||||
get() {
|
||||
return state;
|
||||
},
|
||||
set(newState) {
|
||||
if (states[state].has(newState)) {
|
||||
state = newState;
|
||||
} else {
|
||||
throw new Error(`invalid state transition: ${state} => ${newState}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this._workerReporter = DEFAULT_WORKER_REPORTER;
|
||||
this._linkPartialObjects = false;
|
||||
this._linkedObjectMap = new Map();
|
||||
|
||||
this.once(Runner.constants.EVENT_RUN_END, () => {
|
||||
this._state = COMPLETE;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a mapping function to enqueue a file in the worker pool and return results of its execution.
|
||||
* @param {BufferedWorkerPool} pool - Worker pool
|
||||
* @param {Options} options - Mocha options
|
||||
* @returns {FileRunner} Mapping function
|
||||
* @private
|
||||
*/
|
||||
_createFileRunner(pool, options) {
|
||||
/**
|
||||
* Emits event and sets `BAILING` state, if necessary.
|
||||
* @param {Object} event - Event having `eventName`, maybe `data` and maybe `error`
|
||||
* @param {number} failureCount - Failure count
|
||||
*/
|
||||
const emitEvent = (event, failureCount) => {
|
||||
this.emit(event.eventName, event.data, event.error);
|
||||
if (
|
||||
this._state !== BAILING &&
|
||||
event.data &&
|
||||
event.data._bail &&
|
||||
(failureCount || event.error)
|
||||
) {
|
||||
debug('run(): nonzero failure count & found bail flag');
|
||||
// we need to let the events complete for this file, as the worker
|
||||
// should run any cleanup hooks
|
||||
this._state = BAILING;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Given an event, recursively find any objects in its data that have ID's, and create object references to already-seen objects.
|
||||
* @param {Object} event - Event having `eventName`, maybe `data` and maybe `error`
|
||||
*/
|
||||
const linkEvent = event => {
|
||||
const stack = [{parent: event, prop: 'data'}];
|
||||
while (stack.length) {
|
||||
const {parent, prop} = stack.pop();
|
||||
const obj = parent[prop];
|
||||
let newObj;
|
||||
if (obj && typeof obj === 'object') {
|
||||
if (obj[MOCHA_ID_PROP_NAME]) {
|
||||
const id = obj[MOCHA_ID_PROP_NAME];
|
||||
newObj = this._linkedObjectMap.has(id)
|
||||
? Object.assign(this._linkedObjectMap.get(id), obj)
|
||||
: obj;
|
||||
this._linkedObjectMap.set(id, newObj);
|
||||
parent[prop] = newObj;
|
||||
} else {
|
||||
throw createFatalError(
|
||||
'Object missing ID received in event data',
|
||||
obj
|
||||
);
|
||||
}
|
||||
}
|
||||
Object.keys(newObj).forEach(key => {
|
||||
const value = obj[key];
|
||||
if (value && typeof value === 'object' && value[MOCHA_ID_PROP_NAME]) {
|
||||
stack.push({obj: value, parent: newObj, prop: key});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return async file => {
|
||||
debug('run(): enqueueing test file %s', file);
|
||||
try {
|
||||
const {failureCount, events} = await pool.run(file, options);
|
||||
|
||||
if (this._state === BAILED) {
|
||||
// short-circuit after a graceful bail. if this happens,
|
||||
// some other worker has bailed.
|
||||
// TODO: determine if this is the desired behavior, or if we
|
||||
// should report the events of this run anyway.
|
||||
return;
|
||||
}
|
||||
debug(
|
||||
'run(): completed run of file %s; %d failures / %d events',
|
||||
file,
|
||||
failureCount,
|
||||
events.length
|
||||
);
|
||||
this.failures += failureCount; // can this ever be non-numeric?
|
||||
let event = events.shift();
|
||||
|
||||
if (this._linkPartialObjects) {
|
||||
while (event) {
|
||||
linkEvent(event);
|
||||
emitEvent(event, failureCount);
|
||||
event = events.shift();
|
||||
}
|
||||
} else {
|
||||
while (event) {
|
||||
emitEvent(event, failureCount);
|
||||
event = events.shift();
|
||||
}
|
||||
}
|
||||
if (this._state === BAILING) {
|
||||
debug('run(): terminating pool due to "bail" flag');
|
||||
this._state = BAILED;
|
||||
await pool.terminate();
|
||||
}
|
||||
} catch (err) {
|
||||
if (this._state === BAILED || this._state === ABORTING) {
|
||||
debug(
|
||||
'run(): worker pool terminated with intent; skipping file %s',
|
||||
file
|
||||
);
|
||||
} else {
|
||||
// this is an uncaught exception
|
||||
debug('run(): encountered uncaught exception: %O', err);
|
||||
if (this.allowUncaught) {
|
||||
// still have to clean up
|
||||
this._state = ABORTING;
|
||||
await pool.terminate(true);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
} finally {
|
||||
debug('run(): done running file %s', file);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen on `Process.SIGINT`; terminate pool if caught.
|
||||
* Returns the listener for later call to `process.removeListener()`.
|
||||
* @param {BufferedWorkerPool} pool - Worker pool
|
||||
* @returns {SigIntListener} Listener
|
||||
* @private
|
||||
*/
|
||||
_bindSigIntListener(pool) {
|
||||
const sigIntListener = async () => {
|
||||
debug('run(): caught a SIGINT');
|
||||
this._state = ABORTING;
|
||||
|
||||
try {
|
||||
debug('run(): force-terminating worker pool');
|
||||
await pool.terminate(true);
|
||||
} catch (err) {
|
||||
console.error(
|
||||
`Error while attempting to force-terminate worker pool: ${err}`
|
||||
);
|
||||
process.exitCode = 1;
|
||||
} finally {
|
||||
process.nextTick(() => {
|
||||
debug('run(): imminent death');
|
||||
this._state = ABORTED;
|
||||
process.kill(process.pid, 'SIGINT');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
process.once('SIGINT', sigIntListener);
|
||||
|
||||
return sigIntListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs Mocha tests by creating a thread pool, then delegating work to the
|
||||
* worker threads.
|
||||
*
|
||||
* Each worker receives one file, and as workers become available, they take a
|
||||
* file from the queue and run it. The worker thread execution is treated like
|
||||
* an RPC--it returns a `Promise` containing serialized information about the
|
||||
* run. The information is processed as it's received, and emitted to a
|
||||
* {@link Reporter}, which is likely listening for these events.
|
||||
*
|
||||
* @param {Function} callback - Called with an exit code corresponding to
|
||||
* number of test failures.
|
||||
* @param {{files: string[], options: Options}} opts - Files to run and
|
||||
* command-line options, respectively.
|
||||
*/
|
||||
run(callback, {files, options = {}} = {}) {
|
||||
/**
|
||||
* Listener on `Process.SIGINT` which tries to cleanly terminate the worker pool.
|
||||
*/
|
||||
let sigIntListener;
|
||||
|
||||
// assign the reporter the worker will use, which will be different than the
|
||||
// main process' reporter
|
||||
options = {...options, reporter: this._workerReporter};
|
||||
|
||||
// This function should _not_ return a `Promise`; its parent (`Runner#run`)
|
||||
// returns this instance, so this should do the same. However, we want to make
|
||||
// use of `async`/`await`, so we use this IIFE.
|
||||
(async () => {
|
||||
/**
|
||||
* This is an interval that outputs stats about the worker pool every so often
|
||||
*/
|
||||
let debugInterval;
|
||||
|
||||
/**
|
||||
* @type {BufferedWorkerPool}
|
||||
*/
|
||||
let pool;
|
||||
|
||||
try {
|
||||
pool = BufferedWorkerPool.create({maxWorkers: options.jobs});
|
||||
|
||||
sigIntListener = this._bindSigIntListener(pool);
|
||||
|
||||
/* istanbul ignore next */
|
||||
debugInterval = setInterval(
|
||||
() => debugStats(pool),
|
||||
DEBUG_STATS_INTERVAL
|
||||
).unref();
|
||||
|
||||
// this is set for uncaught exception handling in `Runner#uncaught`
|
||||
// TODO: `Runner` should be using a state machine instead.
|
||||
this.started = true;
|
||||
this._state = RUNNING;
|
||||
|
||||
this.emit(EVENT_RUN_BEGIN);
|
||||
|
||||
options = {...options};
|
||||
DENY_OPTIONS.forEach(opt => {
|
||||
delete options[opt];
|
||||
});
|
||||
|
||||
const results = await allSettled(
|
||||
files.map(this._createFileRunner(pool, options))
|
||||
);
|
||||
|
||||
// note that pool may already be terminated due to --bail
|
||||
await pool.terminate();
|
||||
|
||||
results
|
||||
.filter(({status}) => status === 'rejected')
|
||||
.forEach(({reason}) => {
|
||||
if (this.allowUncaught) {
|
||||
// yep, just the first one.
|
||||
throw reason;
|
||||
}
|
||||
// "rejected" will correspond to uncaught exceptions.
|
||||
// unlike the serial runner, the parallel runner can always recover.
|
||||
this.uncaught(reason);
|
||||
});
|
||||
|
||||
if (this._state === ABORTING) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.emit(EVENT_RUN_END);
|
||||
debug('run(): completing with failure count %d', this.failures);
|
||||
callback(this.failures);
|
||||
} catch (err) {
|
||||
// this `nextTick` takes us out of the `Promise` scope, so the
|
||||
// exception will not be caught and returned as a rejected `Promise`,
|
||||
// which would lead to an `unhandledRejection` event.
|
||||
process.nextTick(() => {
|
||||
debug('run(): re-throwing uncaught exception');
|
||||
throw err;
|
||||
});
|
||||
} finally {
|
||||
clearInterval(debugInterval);
|
||||
process.removeListener('SIGINT', sigIntListener);
|
||||
}
|
||||
})();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle partial object linking behavior; used for building object references from
|
||||
* unique ID's.
|
||||
* @param {boolean} [value] - If `true`, enable partial object linking, otherwise disable
|
||||
* @returns {Runner}
|
||||
* @chainable
|
||||
* @public
|
||||
* @example
|
||||
* // this reporter needs proper object references when run in parallel mode
|
||||
* class MyReporter() {
|
||||
* constructor(runner) {
|
||||
* this.runner.linkPartialObjects(true)
|
||||
* .on(EVENT_SUITE_BEGIN, suite => {
|
||||
// this Suite may be the same object...
|
||||
* })
|
||||
* .on(EVENT_TEST_BEGIN, test => {
|
||||
* // ...as the `test.parent` property
|
||||
* });
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
linkPartialObjects(value) {
|
||||
this._linkPartialObjects = Boolean(value);
|
||||
return super.linkPartialObjects(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* If this class is the `Runner` in use, then this is going to return `true`.
|
||||
*
|
||||
* For use by reporters.
|
||||
* @returns {true}
|
||||
* @public
|
||||
*/
|
||||
isParallelMode() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures an alternate reporter for worker processes to use. Subclasses
|
||||
* using worker processes should implement this.
|
||||
* @public
|
||||
* @param {string} path - Absolute path to alternate reporter for worker processes to use
|
||||
* @returns {Runner}
|
||||
* @throws When in serial mode
|
||||
* @chainable
|
||||
*/
|
||||
workerReporter(reporter) {
|
||||
this._workerReporter = reporter;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ParallelBufferedRunner;
|
||||
|
||||
/**
|
||||
* Listener function intended to be bound to `Process.SIGINT` event
|
||||
* @private
|
||||
* @callback SigIntListener
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
|
||||
/**
|
||||
* A function accepting a test file path and returning the results of a test run
|
||||
* @private
|
||||
* @callback FileRunner
|
||||
* @param {string} filename - File to run
|
||||
* @returns {Promise<SerializedWorkerResult>}
|
||||
*/
|
||||
165
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/nodejs/reporters/parallel-buffered.js
generated
vendored
Normal file
165
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/nodejs/reporters/parallel-buffered.js
generated
vendored
Normal file
@ -0,0 +1,165 @@
|
||||
/**
|
||||
* "Buffered" reporter used internally by a worker process when running in parallel mode.
|
||||
* @module nodejs/reporters/parallel-buffered
|
||||
* @public
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const {
|
||||
EVENT_SUITE_BEGIN,
|
||||
EVENT_SUITE_END,
|
||||
EVENT_TEST_FAIL,
|
||||
EVENT_TEST_PASS,
|
||||
EVENT_TEST_PENDING,
|
||||
EVENT_TEST_BEGIN,
|
||||
EVENT_TEST_END,
|
||||
EVENT_TEST_RETRY,
|
||||
EVENT_DELAY_BEGIN,
|
||||
EVENT_DELAY_END,
|
||||
EVENT_HOOK_BEGIN,
|
||||
EVENT_HOOK_END,
|
||||
EVENT_RUN_END
|
||||
} = require('../../runner').constants;
|
||||
const {SerializableEvent, SerializableWorkerResult} = require('../serializer');
|
||||
const debug = require('debug')('mocha:reporters:buffered');
|
||||
const Base = require('../../reporters/base');
|
||||
|
||||
/**
|
||||
* List of events to listen to; these will be buffered and sent
|
||||
* when `Mocha#run` is complete (via {@link ParallelBuffered#done}).
|
||||
*/
|
||||
const EVENT_NAMES = [
|
||||
EVENT_SUITE_BEGIN,
|
||||
EVENT_SUITE_END,
|
||||
EVENT_TEST_BEGIN,
|
||||
EVENT_TEST_PENDING,
|
||||
EVENT_TEST_FAIL,
|
||||
EVENT_TEST_PASS,
|
||||
EVENT_TEST_RETRY,
|
||||
EVENT_TEST_END,
|
||||
EVENT_HOOK_BEGIN,
|
||||
EVENT_HOOK_END
|
||||
];
|
||||
|
||||
/**
|
||||
* Like {@link EVENT_NAMES}, except we expect these events to only be emitted
|
||||
* by the `Runner` once.
|
||||
*/
|
||||
const ONCE_EVENT_NAMES = [EVENT_DELAY_BEGIN, EVENT_DELAY_END];
|
||||
|
||||
/**
|
||||
* The `ParallelBuffered` reporter is used by each worker process in "parallel"
|
||||
* mode, by default. Instead of reporting to to `STDOUT`, etc., it retains a
|
||||
* list of events it receives and hands these off to the callback passed into
|
||||
* {@link Mocha#run}. That callback will then return the data to the main
|
||||
* process.
|
||||
* @public
|
||||
*/
|
||||
class ParallelBuffered extends Base {
|
||||
/**
|
||||
* Calls {@link ParallelBuffered#createListeners}
|
||||
* @param {Runner} runner
|
||||
*/
|
||||
constructor(runner, opts) {
|
||||
super(runner, opts);
|
||||
|
||||
/**
|
||||
* Retained list of events emitted from the {@link Runner} instance.
|
||||
* @type {BufferedEvent[]}
|
||||
* @public
|
||||
*/
|
||||
this.events = [];
|
||||
|
||||
/**
|
||||
* Map of `Runner` event names to listeners (for later teardown)
|
||||
* @public
|
||||
* @type {Map<string,EventListener>}
|
||||
*/
|
||||
this.listeners = new Map();
|
||||
|
||||
this.createListeners(runner);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new listener which saves event data in memory to
|
||||
* {@link ParallelBuffered#events}. Listeners are indexed by `eventName` and stored
|
||||
* in {@link ParallelBuffered#listeners}. This is a defensive measure, so that we
|
||||
* don't a) leak memory or b) remove _other_ listeners that may not be
|
||||
* associated with this reporter.
|
||||
*
|
||||
* Subclasses could override this behavior.
|
||||
*
|
||||
* @public
|
||||
* @param {string} eventName - Name of event to create listener for
|
||||
* @returns {EventListener}
|
||||
*/
|
||||
createListener(eventName) {
|
||||
const listener = (runnable, err) => {
|
||||
this.events.push(SerializableEvent.create(eventName, runnable, err));
|
||||
};
|
||||
return this.listeners.set(eventName, listener).get(eventName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates event listeners (using {@link ParallelBuffered#createListener}) for each
|
||||
* reporter-relevant event emitted by a {@link Runner}. This array is drained when
|
||||
* {@link ParallelBuffered#done} is called by {@link Runner#run}.
|
||||
*
|
||||
* Subclasses could override this behavior.
|
||||
* @public
|
||||
* @param {Runner} runner - Runner instance
|
||||
* @returns {ParallelBuffered}
|
||||
* @chainable
|
||||
*/
|
||||
createListeners(runner) {
|
||||
EVENT_NAMES.forEach(evt => {
|
||||
runner.on(evt, this.createListener(evt));
|
||||
});
|
||||
ONCE_EVENT_NAMES.forEach(evt => {
|
||||
runner.once(evt, this.createListener(evt));
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_END, () => {
|
||||
debug('received EVENT_RUN_END');
|
||||
this.listeners.forEach((listener, evt) => {
|
||||
runner.removeListener(evt, listener);
|
||||
this.listeners.delete(evt);
|
||||
});
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the {@link Mocha#run} callback (`callback`) with the test failure
|
||||
* count and the array of {@link BufferedEvent} objects. Resets the array.
|
||||
*
|
||||
* This is called directly by `Runner#run` and should not be called by any other consumer.
|
||||
*
|
||||
* Subclasses could override this.
|
||||
*
|
||||
* @param {number} failures - Number of failed tests
|
||||
* @param {Function} callback - The callback passed to {@link Mocha#run}.
|
||||
* @public
|
||||
*/
|
||||
done(failures, callback) {
|
||||
callback(SerializableWorkerResult.create(this.events, failures));
|
||||
this.events = []; // defensive
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializable event data from a `Runner`. Keys of the `data` property
|
||||
* beginning with `__` will be converted into a function which returns the value
|
||||
* upon deserialization.
|
||||
* @typedef {Object} BufferedEvent
|
||||
* @property {string} name - Event name
|
||||
* @property {object} data - Event parameters
|
||||
*/
|
||||
|
||||
module.exports = ParallelBuffered;
|
||||
412
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/nodejs/serializer.js
generated
vendored
Normal file
412
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/nodejs/serializer.js
generated
vendored
Normal file
@ -0,0 +1,412 @@
|
||||
/**
|
||||
* Serialization/deserialization classes and functions for communication between a main Mocha process and worker processes.
|
||||
* @module serializer
|
||||
* @private
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const {type} = require('../utils');
|
||||
const {createInvalidArgumentTypeError} = require('../errors');
|
||||
// this is not named `mocha:parallel:serializer` because it's noisy and it's
|
||||
// helpful to be able to write `DEBUG=mocha:parallel*` and get everything else.
|
||||
const debug = require('debug')('mocha:serializer');
|
||||
|
||||
const SERIALIZABLE_RESULT_NAME = 'SerializableWorkerResult';
|
||||
const SERIALIZABLE_TYPES = new Set(['object', 'array', 'function', 'error']);
|
||||
|
||||
/**
|
||||
* The serializable result of a test file run from a worker.
|
||||
* @private
|
||||
*/
|
||||
class SerializableWorkerResult {
|
||||
/**
|
||||
* Creates instance props; of note, the `__type` prop.
|
||||
*
|
||||
* Note that the failure count is _redundant_ and could be derived from the
|
||||
* list of events; but since we're already doing the work, might as well use
|
||||
* it.
|
||||
* @param {SerializableEvent[]} [events=[]] - Events to eventually serialize
|
||||
* @param {number} [failureCount=0] - Failure count
|
||||
*/
|
||||
constructor(events = [], failureCount = 0) {
|
||||
/**
|
||||
* The number of failures in this run
|
||||
* @type {number}
|
||||
*/
|
||||
this.failureCount = failureCount;
|
||||
/**
|
||||
* All relevant events emitted from the {@link Runner}.
|
||||
* @type {SerializableEvent[]}
|
||||
*/
|
||||
this.events = events;
|
||||
|
||||
/**
|
||||
* Symbol-like value needed to distinguish when attempting to deserialize
|
||||
* this object (once it's been received over IPC).
|
||||
* @type {Readonly<"SerializableWorkerResult">}
|
||||
*/
|
||||
Object.defineProperty(this, '__type', {
|
||||
value: SERIALIZABLE_RESULT_NAME,
|
||||
enumerable: true,
|
||||
writable: false
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new {@link SerializableWorkerResult}.
|
||||
* @param {...any} args - Args to constructor
|
||||
* @returns {SerializableWorkerResult}
|
||||
*/
|
||||
static create(...args) {
|
||||
return new SerializableWorkerResult(...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes each {@link SerializableEvent} in our `events` prop;
|
||||
* makes this object read-only.
|
||||
* @returns {Readonly<SerializableWorkerResult>}
|
||||
*/
|
||||
serialize() {
|
||||
this.events.forEach(event => {
|
||||
event.serialize();
|
||||
});
|
||||
return Object.freeze(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a {@link SerializedWorkerResult} into something reporters can
|
||||
* use; calls {@link SerializableEvent.deserialize} on each item in its
|
||||
* `events` prop.
|
||||
* @param {SerializedWorkerResult} obj
|
||||
* @returns {SerializedWorkerResult}
|
||||
*/
|
||||
static deserialize(obj) {
|
||||
obj.events.forEach(event => {
|
||||
SerializableEvent.deserialize(event);
|
||||
});
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if this is a {@link SerializedWorkerResult} or a
|
||||
* {@link SerializableWorkerResult}.
|
||||
* @param {*} value - A value to check
|
||||
* @returns {boolean} If true, it's deserializable
|
||||
*/
|
||||
static isSerializedWorkerResult(value) {
|
||||
return (
|
||||
value instanceof SerializableWorkerResult ||
|
||||
(type(value) === 'object' && value.__type === SERIALIZABLE_RESULT_NAME)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an event, emitted by a {@link Runner}, which is to be transmitted
|
||||
* over IPC.
|
||||
*
|
||||
* Due to the contents of the event data, it's not possible to send them
|
||||
* verbatim. When received by the main process--and handled by reporters--these
|
||||
* objects are expected to contain {@link Runnable} instances. This class
|
||||
* provides facilities to perform the translation via serialization and
|
||||
* deserialization.
|
||||
* @private
|
||||
*/
|
||||
class SerializableEvent {
|
||||
/**
|
||||
* Constructs a `SerializableEvent`, throwing if we receive unexpected data.
|
||||
*
|
||||
* Practically, events emitted from `Runner` have a minumum of zero (0)
|
||||
* arguments-- (for example, {@link Runnable.constants.EVENT_RUN_BEGIN}) and a
|
||||
* maximum of two (2) (for example,
|
||||
* {@link Runnable.constants.EVENT_TEST_FAIL}, where the second argument is an
|
||||
* `Error`). The first argument, if present, is a {@link Runnable}. This
|
||||
* constructor's arguments adhere to this convention.
|
||||
* @param {string} eventName - A non-empty event name.
|
||||
* @param {any} [originalValue] - Some data. Corresponds to extra arguments
|
||||
* passed to `EventEmitter#emit`.
|
||||
* @param {Error} [originalError] - An error, if there's an error.
|
||||
* @throws If `eventName` is empty, or `originalValue` is a non-object.
|
||||
*/
|
||||
constructor(eventName, originalValue, originalError) {
|
||||
if (!eventName) {
|
||||
throw createInvalidArgumentTypeError(
|
||||
'Empty `eventName` string argument',
|
||||
'eventName',
|
||||
'string'
|
||||
);
|
||||
}
|
||||
/**
|
||||
* The event name.
|
||||
* @memberof SerializableEvent
|
||||
*/
|
||||
this.eventName = eventName;
|
||||
const originalValueType = type(originalValue);
|
||||
if (originalValueType !== 'object' && originalValueType !== 'undefined') {
|
||||
throw createInvalidArgumentTypeError(
|
||||
`Expected object but received ${originalValueType}`,
|
||||
'originalValue',
|
||||
'object'
|
||||
);
|
||||
}
|
||||
/**
|
||||
* An error, if present.
|
||||
* @memberof SerializableEvent
|
||||
*/
|
||||
Object.defineProperty(this, 'originalError', {
|
||||
value: originalError,
|
||||
enumerable: false
|
||||
});
|
||||
|
||||
/**
|
||||
* The raw value.
|
||||
*
|
||||
* We don't want this value sent via IPC; making it non-enumerable will do that.
|
||||
*
|
||||
* @memberof SerializableEvent
|
||||
*/
|
||||
Object.defineProperty(this, 'originalValue', {
|
||||
value: originalValue,
|
||||
enumerable: false
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* In case you hated using `new` (I do).
|
||||
*
|
||||
* @param {...any} args - Args for {@link SerializableEvent#constructor}.
|
||||
* @returns {SerializableEvent} A new `SerializableEvent`
|
||||
*/
|
||||
static create(...args) {
|
||||
return new SerializableEvent(...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used internally by {@link SerializableEvent#serialize}.
|
||||
* @ignore
|
||||
* @param {Array<object|string>} pairs - List of parent/key tuples to process; modified in-place. This JSDoc type is an approximation
|
||||
* @param {object} parent - Some parent object
|
||||
* @param {string} key - Key to inspect
|
||||
* @param {WeakSet<Object>} seenObjects - For avoiding circular references
|
||||
*/
|
||||
static _serialize(pairs, parent, key, seenObjects) {
|
||||
let value = parent[key];
|
||||
if (seenObjects.has(value)) {
|
||||
parent[key] = Object.create(null);
|
||||
return;
|
||||
}
|
||||
let _type = type(value);
|
||||
if (_type === 'error') {
|
||||
// we need to reference the stack prop b/c it's lazily-loaded.
|
||||
// `__type` is necessary for deserialization to create an `Error` later.
|
||||
// `message` is apparently not enumerable, so we must handle it specifically.
|
||||
value = Object.assign(Object.create(null), value, {
|
||||
stack: value.stack,
|
||||
message: value.message,
|
||||
__type: 'Error'
|
||||
});
|
||||
parent[key] = value;
|
||||
// after this, set the result of type(value) to be `object`, and we'll throw
|
||||
// whatever other junk is in the original error into the new `value`.
|
||||
_type = 'object';
|
||||
}
|
||||
switch (_type) {
|
||||
case 'object':
|
||||
if (type(value.serialize) === 'function') {
|
||||
parent[key] = value.serialize();
|
||||
} else {
|
||||
// by adding props to the `pairs` array, we will process it further
|
||||
pairs.push(
|
||||
...Object.keys(value)
|
||||
.filter(key => SERIALIZABLE_TYPES.has(type(value[key])))
|
||||
.map(key => [value, key])
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'function':
|
||||
// we _may_ want to dig in to functions for some assertion libraries
|
||||
// that might put a usable property on a function.
|
||||
// for now, just zap it.
|
||||
delete parent[key];
|
||||
break;
|
||||
case 'array':
|
||||
pairs.push(
|
||||
...value
|
||||
.filter(value => SERIALIZABLE_TYPES.has(type(value)))
|
||||
.map((value, index) => [value, index])
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies this object *in place* (for theoretical memory consumption &
|
||||
* performance reasons); serializes `SerializableEvent#originalValue` (placing
|
||||
* the result in `SerializableEvent#data`) and `SerializableEvent#error`.
|
||||
* Freezes this object. The result is an object that can be transmitted over
|
||||
* IPC.
|
||||
* If this quickly becomes unmaintainable, we will want to move towards immutable
|
||||
* objects post-haste.
|
||||
*/
|
||||
serialize() {
|
||||
// given a parent object and a key, inspect the value and decide whether
|
||||
// to replace it, remove it, or add it to our `pairs` array to further process.
|
||||
// this is recursion in loop form.
|
||||
const originalValue = this.originalValue;
|
||||
const result = Object.assign(Object.create(null), {
|
||||
data:
|
||||
type(originalValue) === 'object' &&
|
||||
type(originalValue.serialize) === 'function'
|
||||
? originalValue.serialize()
|
||||
: originalValue,
|
||||
error: this.originalError
|
||||
});
|
||||
|
||||
const pairs = Object.keys(result).map(key => [result, key]);
|
||||
const seenObjects = new WeakSet();
|
||||
|
||||
let pair;
|
||||
while ((pair = pairs.shift())) {
|
||||
SerializableEvent._serialize(pairs, ...pair, seenObjects);
|
||||
seenObjects.add(pair[0]);
|
||||
}
|
||||
|
||||
this.data = result.data;
|
||||
this.error = result.error;
|
||||
|
||||
return Object.freeze(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used internally by {@link SerializableEvent.deserialize}; creates an `Error`
|
||||
* from an `Error`-like (serialized) object
|
||||
* @ignore
|
||||
* @param {Object} value - An Error-like value
|
||||
* @returns {Error} Real error
|
||||
*/
|
||||
static _deserializeError(value) {
|
||||
const error = new Error(value.message);
|
||||
error.stack = value.stack;
|
||||
Object.assign(error, value);
|
||||
delete error.__type;
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used internally by {@link SerializableEvent.deserialize}; recursively
|
||||
* deserializes an object in-place.
|
||||
* @param {object|Array} parent - Some object or array
|
||||
* @param {string|number} key - Some prop name or array index within `parent`
|
||||
*/
|
||||
static _deserializeObject(parent, key) {
|
||||
if (key === '__proto__') {
|
||||
delete parent[key];
|
||||
return;
|
||||
}
|
||||
const value = parent[key];
|
||||
// keys beginning with `$$` are converted into functions returning the value
|
||||
// and renamed, stripping the `$$` prefix.
|
||||
// functions defined this way cannot be array members!
|
||||
if (type(key) === 'string' && key.startsWith('$$')) {
|
||||
const newKey = key.slice(2);
|
||||
parent[newKey] = () => value;
|
||||
delete parent[key];
|
||||
key = newKey;
|
||||
}
|
||||
if (type(value) === 'array') {
|
||||
value.forEach((_, idx) => {
|
||||
SerializableEvent._deserializeObject(value, idx);
|
||||
});
|
||||
} else if (type(value) === 'object') {
|
||||
if (value.__type === 'Error') {
|
||||
parent[key] = SerializableEvent._deserializeError(value);
|
||||
} else {
|
||||
Object.keys(value).forEach(key => {
|
||||
SerializableEvent._deserializeObject(value, key);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize value returned from a worker into something more useful.
|
||||
* Does not return the same object.
|
||||
* @todo do this in a loop instead of with recursion (if necessary)
|
||||
* @param {SerializedEvent} obj - Object returned from worker
|
||||
* @returns {SerializedEvent} Deserialized result
|
||||
*/
|
||||
static deserialize(obj) {
|
||||
if (!obj) {
|
||||
throw createInvalidArgumentTypeError('Expected value', obj);
|
||||
}
|
||||
|
||||
obj = Object.assign(Object.create(null), obj);
|
||||
|
||||
if (obj.data) {
|
||||
Object.keys(obj.data).forEach(key => {
|
||||
SerializableEvent._deserializeObject(obj.data, key);
|
||||
});
|
||||
}
|
||||
|
||||
if (obj.error) {
|
||||
obj.error = SerializableEvent._deserializeError(obj.error);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* "Serializes" a value for transmission over IPC as a message.
|
||||
*
|
||||
* If value is an object and has a `serialize()` method, call that method; otherwise return the object and hope for the best.
|
||||
*
|
||||
* @param {*} [value] - A value to serialize
|
||||
*/
|
||||
exports.serialize = function serialize(value) {
|
||||
const result =
|
||||
type(value) === 'object' && type(value.serialize) === 'function'
|
||||
? value.serialize()
|
||||
: value;
|
||||
debug('serialized: %O', result);
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* "Deserializes" a "message" received over IPC.
|
||||
*
|
||||
* This could be expanded with other objects that need deserialization,
|
||||
* but at present time we only care about {@link SerializableWorkerResult} objects.
|
||||
*
|
||||
* @param {*} [value] - A "message" to deserialize
|
||||
*/
|
||||
exports.deserialize = function deserialize(value) {
|
||||
const result = SerializableWorkerResult.isSerializedWorkerResult(value)
|
||||
? SerializableWorkerResult.deserialize(value)
|
||||
: value;
|
||||
debug('deserialized: %O', result);
|
||||
return result;
|
||||
};
|
||||
|
||||
exports.SerializableEvent = SerializableEvent;
|
||||
exports.SerializableWorkerResult = SerializableWorkerResult;
|
||||
|
||||
/**
|
||||
* The result of calling `SerializableEvent.serialize`, as received
|
||||
* by the deserializer.
|
||||
* @private
|
||||
* @typedef {Object} SerializedEvent
|
||||
* @property {object?} data - Optional serialized data
|
||||
* @property {object?} error - Optional serialized `Error`
|
||||
*/
|
||||
|
||||
/**
|
||||
* The result of calling `SerializableWorkerResult.serialize` as received
|
||||
* by the deserializer.
|
||||
* @private
|
||||
* @typedef {Object} SerializedWorkerResult
|
||||
* @property {number} failureCount - Number of failures
|
||||
* @property {SerializedEvent[]} events - Serialized events
|
||||
* @property {"SerializedWorkerResult"} __type - Symbol-like to denote the type of object this is
|
||||
*/
|
||||
151
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/nodejs/worker.js
generated
vendored
Normal file
151
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/nodejs/worker.js
generated
vendored
Normal file
@ -0,0 +1,151 @@
|
||||
/**
|
||||
* A worker process. Consumes {@link module:reporters/parallel-buffered} reporter.
|
||||
* @module worker
|
||||
* @private
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
createInvalidArgumentTypeError,
|
||||
createInvalidArgumentValueError
|
||||
} = require('../errors');
|
||||
const workerpool = require('workerpool');
|
||||
const Mocha = require('../mocha');
|
||||
const {handleRequires, validateLegacyPlugin} = require('../cli/run-helpers');
|
||||
const d = require('debug');
|
||||
const debug = d.debug(`mocha:parallel:worker:${process.pid}`);
|
||||
const isDebugEnabled = d.enabled(`mocha:parallel:worker:${process.pid}`);
|
||||
const {serialize} = require('./serializer');
|
||||
const {setInterval, clearInterval} = global;
|
||||
|
||||
let rootHooks;
|
||||
|
||||
if (workerpool.isMainThread) {
|
||||
throw new Error(
|
||||
'This script is intended to be run as a worker (by the `workerpool` package).'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes some stuff on the first call to {@link run}.
|
||||
*
|
||||
* Handles `--require` and `--ui`. Does _not_ handle `--reporter`,
|
||||
* as only the `Buffered` reporter is used.
|
||||
*
|
||||
* **This function only runs once per worker**; it overwrites itself with a no-op
|
||||
* before returning.
|
||||
*
|
||||
* @param {Options} argv - Command-line options
|
||||
*/
|
||||
let bootstrap = async argv => {
|
||||
// globalSetup and globalTeardown do not run in workers
|
||||
const plugins = await handleRequires(argv.require, {
|
||||
ignoredPlugins: ['mochaGlobalSetup', 'mochaGlobalTeardown']
|
||||
});
|
||||
validateLegacyPlugin(argv, 'ui', Mocha.interfaces);
|
||||
|
||||
rootHooks = plugins.rootHooks;
|
||||
bootstrap = () => {};
|
||||
debug('bootstrap(): finished with args: %O', argv);
|
||||
};
|
||||
|
||||
/**
|
||||
* Runs a single test file in a worker thread.
|
||||
* @param {string} filepath - Filepath of test file
|
||||
* @param {string} [serializedOptions] - **Serialized** options. This string will be eval'd!
|
||||
* @see https://npm.im/serialize-javascript
|
||||
* @returns {Promise<{failures: number, events: BufferedEvent[]}>} - Test
|
||||
* failure count and list of events.
|
||||
*/
|
||||
async function run(filepath, serializedOptions = '{}') {
|
||||
if (!filepath) {
|
||||
throw createInvalidArgumentTypeError(
|
||||
'Expected a non-empty "filepath" argument',
|
||||
'file',
|
||||
'string'
|
||||
);
|
||||
}
|
||||
|
||||
debug('run(): running test file %s', filepath);
|
||||
|
||||
if (typeof serializedOptions !== 'string') {
|
||||
throw createInvalidArgumentTypeError(
|
||||
'run() expects second parameter to be a string which was serialized by the `serialize-javascript` module',
|
||||
'serializedOptions',
|
||||
'string'
|
||||
);
|
||||
}
|
||||
let argv;
|
||||
try {
|
||||
// eslint-disable-next-line no-eval
|
||||
argv = eval('(' + serializedOptions + ')');
|
||||
} catch (err) {
|
||||
throw createInvalidArgumentValueError(
|
||||
'run() was unable to deserialize the options',
|
||||
'serializedOptions',
|
||||
serializedOptions
|
||||
);
|
||||
}
|
||||
|
||||
const opts = Object.assign({ui: 'bdd'}, argv, {
|
||||
// if this was true, it would cause infinite recursion.
|
||||
parallel: false,
|
||||
// this doesn't work in parallel mode
|
||||
forbidOnly: true,
|
||||
// it's useful for a Mocha instance to know if it's running in a worker process.
|
||||
isWorker: true
|
||||
});
|
||||
|
||||
await bootstrap(opts);
|
||||
|
||||
opts.rootHooks = rootHooks;
|
||||
|
||||
const mocha = new Mocha(opts).addFile(filepath);
|
||||
|
||||
try {
|
||||
await mocha.loadFilesAsync();
|
||||
} catch (err) {
|
||||
debug('run(): could not load file %s: %s', filepath, err);
|
||||
throw err;
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
let debugInterval;
|
||||
/* istanbul ignore next */
|
||||
if (isDebugEnabled) {
|
||||
debugInterval = setInterval(() => {
|
||||
debug('run(): still running %s...', filepath);
|
||||
}, 5000).unref();
|
||||
}
|
||||
mocha.run(result => {
|
||||
// Runner adds these; if we don't remove them, we'll get a leak.
|
||||
process.removeAllListeners('uncaughtException');
|
||||
process.removeAllListeners('unhandledRejection');
|
||||
|
||||
try {
|
||||
const serialized = serialize(result);
|
||||
debug(
|
||||
'run(): completed run with %d test failures; returning to main process',
|
||||
typeof result.failures === 'number' ? result.failures : 0
|
||||
);
|
||||
resolve(serialized);
|
||||
} catch (err) {
|
||||
// TODO: figure out exactly what the sad path looks like here.
|
||||
// rejection should only happen if an error is "unrecoverable"
|
||||
debug('run(): serialization failed; rejecting: %O', err);
|
||||
reject(err);
|
||||
} finally {
|
||||
clearInterval(debugInterval);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// this registers the `run` function.
|
||||
workerpool.worker({run});
|
||||
|
||||
debug('started worker process');
|
||||
|
||||
// for testing
|
||||
exports.run = run;
|
||||
16
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/pending.js
generated
vendored
Normal file
16
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/pending.js
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
@module Pending
|
||||
*/
|
||||
|
||||
module.exports = Pending;
|
||||
|
||||
/**
|
||||
* Initialize a new `Pending` error with the given message.
|
||||
*
|
||||
* @param {string} message
|
||||
*/
|
||||
function Pending(message) {
|
||||
this.message = message;
|
||||
}
|
||||
286
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/plugin-loader.js
generated
vendored
Normal file
286
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/plugin-loader.js
generated
vendored
Normal file
@ -0,0 +1,286 @@
|
||||
/**
|
||||
* Provides a way to load "plugins" as provided by the user.
|
||||
*
|
||||
* Currently supports:
|
||||
*
|
||||
* - Root hooks
|
||||
* - Global fixtures (setup/teardown)
|
||||
* @private
|
||||
* @module plugin
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const debug = require('debug')('mocha:plugin-loader');
|
||||
const {
|
||||
createInvalidPluginDefinitionError,
|
||||
createInvalidPluginImplementationError
|
||||
} = require('./errors');
|
||||
const {castArray} = require('./utils');
|
||||
|
||||
/**
|
||||
* Built-in plugin definitions.
|
||||
*/
|
||||
const MochaPlugins = [
|
||||
/**
|
||||
* Root hook plugin definition
|
||||
* @type {PluginDefinition}
|
||||
*/
|
||||
{
|
||||
exportName: 'mochaHooks',
|
||||
optionName: 'rootHooks',
|
||||
validate(value) {
|
||||
if (
|
||||
Array.isArray(value) ||
|
||||
(typeof value !== 'function' && typeof value !== 'object')
|
||||
) {
|
||||
throw createInvalidPluginImplementationError(
|
||||
`mochaHooks must be an object or a function returning (or fulfilling with) an object`
|
||||
);
|
||||
}
|
||||
},
|
||||
async finalize(rootHooks) {
|
||||
if (rootHooks.length) {
|
||||
const rootHookObjects = await Promise.all(
|
||||
rootHooks.map(async hook =>
|
||||
typeof hook === 'function' ? hook() : hook
|
||||
)
|
||||
);
|
||||
|
||||
return rootHookObjects.reduce(
|
||||
(acc, hook) => {
|
||||
hook = {
|
||||
beforeAll: [],
|
||||
beforeEach: [],
|
||||
afterAll: [],
|
||||
afterEach: [],
|
||||
...hook
|
||||
};
|
||||
return {
|
||||
beforeAll: [...acc.beforeAll, ...castArray(hook.beforeAll)],
|
||||
beforeEach: [...acc.beforeEach, ...castArray(hook.beforeEach)],
|
||||
afterAll: [...acc.afterAll, ...castArray(hook.afterAll)],
|
||||
afterEach: [...acc.afterEach, ...castArray(hook.afterEach)]
|
||||
};
|
||||
},
|
||||
{beforeAll: [], beforeEach: [], afterAll: [], afterEach: []}
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Global setup fixture plugin definition
|
||||
* @type {PluginDefinition}
|
||||
*/
|
||||
{
|
||||
exportName: 'mochaGlobalSetup',
|
||||
optionName: 'globalSetup',
|
||||
validate(value) {
|
||||
let isValid = true;
|
||||
if (Array.isArray(value)) {
|
||||
if (value.some(item => typeof item !== 'function')) {
|
||||
isValid = false;
|
||||
}
|
||||
} else if (typeof value !== 'function') {
|
||||
isValid = false;
|
||||
}
|
||||
if (!isValid) {
|
||||
throw createInvalidPluginImplementationError(
|
||||
`mochaGlobalSetup must be a function or an array of functions`,
|
||||
{pluginDef: this, pluginImpl: value}
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Global teardown fixture plugin definition
|
||||
* @type {PluginDefinition}
|
||||
*/
|
||||
{
|
||||
exportName: 'mochaGlobalTeardown',
|
||||
optionName: 'globalTeardown',
|
||||
validate(value) {
|
||||
let isValid = true;
|
||||
if (Array.isArray(value)) {
|
||||
if (value.some(item => typeof item !== 'function')) {
|
||||
isValid = false;
|
||||
}
|
||||
} else if (typeof value !== 'function') {
|
||||
isValid = false;
|
||||
}
|
||||
if (!isValid) {
|
||||
throw createInvalidPluginImplementationError(
|
||||
`mochaGlobalTeardown must be a function or an array of functions`,
|
||||
{pluginDef: this, pluginImpl: value}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
/**
|
||||
* Contains a registry of [plugin definitions]{@link PluginDefinition} and discovers plugin implementations in user-supplied code.
|
||||
*
|
||||
* - [load()]{@link #load} should be called for all required modules
|
||||
* - The result of [finalize()]{@link #finalize} should be merged into the options for the [Mocha]{@link Mocha} constructor.
|
||||
* @private
|
||||
*/
|
||||
class PluginLoader {
|
||||
/**
|
||||
* Initializes plugin names, plugin map, etc.
|
||||
* @param {PluginLoaderOptions} [opts] - Options
|
||||
*/
|
||||
constructor({pluginDefs = MochaPlugins, ignore = []} = {}) {
|
||||
/**
|
||||
* Map of registered plugin defs
|
||||
* @type {Map<string,PluginDefinition>}
|
||||
*/
|
||||
this.registered = new Map();
|
||||
|
||||
/**
|
||||
* Cache of known `optionName` values for checking conflicts
|
||||
* @type {Set<string>}
|
||||
*/
|
||||
this.knownOptionNames = new Set();
|
||||
|
||||
/**
|
||||
* Cache of known `exportName` values for checking conflicts
|
||||
* @type {Set<string>}
|
||||
*/
|
||||
this.knownExportNames = new Set();
|
||||
|
||||
/**
|
||||
* Map of user-supplied plugin implementations
|
||||
* @type {Map<string,Array<*>>}
|
||||
*/
|
||||
this.loaded = new Map();
|
||||
|
||||
/**
|
||||
* Set of ignored plugins by export name
|
||||
* @type {Set<string>}
|
||||
*/
|
||||
this.ignoredExportNames = new Set(castArray(ignore));
|
||||
|
||||
castArray(pluginDefs).forEach(pluginDef => {
|
||||
this.register(pluginDef);
|
||||
});
|
||||
|
||||
debug(
|
||||
'registered %d plugin defs (%d ignored)',
|
||||
this.registered.size,
|
||||
this.ignoredExportNames.size
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a plugin
|
||||
* @param {PluginDefinition} pluginDef - Plugin definition
|
||||
*/
|
||||
register(pluginDef) {
|
||||
if (!pluginDef || typeof pluginDef !== 'object') {
|
||||
throw createInvalidPluginDefinitionError(
|
||||
'pluginDef is non-object or falsy',
|
||||
pluginDef
|
||||
);
|
||||
}
|
||||
if (!pluginDef.exportName) {
|
||||
throw createInvalidPluginDefinitionError(
|
||||
`exportName is expected to be a non-empty string`,
|
||||
pluginDef
|
||||
);
|
||||
}
|
||||
let {exportName} = pluginDef;
|
||||
if (this.ignoredExportNames.has(exportName)) {
|
||||
debug(
|
||||
'refusing to register ignored plugin with export name "%s"',
|
||||
exportName
|
||||
);
|
||||
return;
|
||||
}
|
||||
exportName = String(exportName);
|
||||
pluginDef.optionName = String(pluginDef.optionName || exportName);
|
||||
if (this.knownExportNames.has(exportName)) {
|
||||
throw createInvalidPluginDefinitionError(
|
||||
`Plugin definition conflict: ${exportName}; exportName must be unique`,
|
||||
pluginDef
|
||||
);
|
||||
}
|
||||
this.loaded.set(exportName, []);
|
||||
this.registered.set(exportName, pluginDef);
|
||||
this.knownExportNames.add(exportName);
|
||||
this.knownOptionNames.add(pluginDef.optionName);
|
||||
debug('registered plugin def "%s"', exportName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inspects a module's exports for known plugins and keeps them in memory.
|
||||
*
|
||||
* @param {*} requiredModule - The exports of a module loaded via `--require`
|
||||
* @returns {boolean} If one or more plugins was found, return `true`.
|
||||
*/
|
||||
load(requiredModule) {
|
||||
// we should explicitly NOT fail if other stuff is exported.
|
||||
// we only care about the plugins we know about.
|
||||
if (requiredModule && typeof requiredModule === 'object') {
|
||||
return Array.from(this.knownExportNames).reduce(
|
||||
(pluginImplFound, pluginName) => {
|
||||
const pluginImpl = requiredModule[pluginName];
|
||||
if (pluginImpl) {
|
||||
const plugin = this.registered.get(pluginName);
|
||||
if (typeof plugin.validate === 'function') {
|
||||
plugin.validate(pluginImpl);
|
||||
}
|
||||
this.loaded.set(pluginName, [
|
||||
...this.loaded.get(pluginName),
|
||||
...castArray(pluginImpl)
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
return pluginImplFound;
|
||||
},
|
||||
false
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the `finalize()` function of each known plugin definition on the plugins found by [load()]{@link PluginLoader#load}.
|
||||
*
|
||||
* Output suitable for passing as input into {@link Mocha} constructor.
|
||||
* @returns {Promise<object>} Object having keys corresponding to registered plugin definitions' `optionName` prop (or `exportName`, if none), and the values are the implementations as provided by a user.
|
||||
*/
|
||||
async finalize() {
|
||||
const finalizedPlugins = Object.create(null);
|
||||
|
||||
for await (const [exportName, pluginImpls] of this.loaded.entries()) {
|
||||
if (pluginImpls.length) {
|
||||
const plugin = this.registered.get(exportName);
|
||||
finalizedPlugins[plugin.optionName] =
|
||||
typeof plugin.finalize === 'function'
|
||||
? await plugin.finalize(pluginImpls)
|
||||
: pluginImpls;
|
||||
}
|
||||
}
|
||||
|
||||
debug('finalized plugins: %O', finalizedPlugins);
|
||||
return finalizedPlugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@link PluginLoader}
|
||||
* @param {PluginLoaderOptions} [opts] - Plugin loader options
|
||||
*/
|
||||
static create({pluginDefs = MochaPlugins, ignore = []} = {}) {
|
||||
return new PluginLoader({pluginDefs, ignore});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PluginLoader;
|
||||
|
||||
/**
|
||||
* Options for {@link PluginLoader}
|
||||
* @typedef {Object} PluginLoaderOptions
|
||||
* @property {PluginDefinition[]} [pluginDefs] - Plugin definitions
|
||||
* @property {string[]} [ignore] - A list of plugins to ignore when loading
|
||||
*/
|
||||
537
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/base.js
generated
vendored
Normal file
537
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/base.js
generated
vendored
Normal file
@ -0,0 +1,537 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module Base
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var diff = require('diff');
|
||||
var milliseconds = require('ms');
|
||||
var utils = require('../utils');
|
||||
var supportsColor = require('supports-color');
|
||||
var symbols = require('log-symbols');
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
|
||||
const isBrowser = utils.isBrowser();
|
||||
|
||||
function getBrowserWindowSize() {
|
||||
if ('innerHeight' in global) {
|
||||
return [global.innerHeight, global.innerWidth];
|
||||
}
|
||||
// In a Web Worker, the DOM Window is not available.
|
||||
return [640, 480];
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose `Base`.
|
||||
*/
|
||||
|
||||
exports = module.exports = Base;
|
||||
|
||||
/**
|
||||
* Check if both stdio streams are associated with a tty.
|
||||
*/
|
||||
|
||||
var isatty = isBrowser || (process.stdout.isTTY && process.stderr.isTTY);
|
||||
|
||||
/**
|
||||
* Save log references to avoid tests interfering (see GH-3604).
|
||||
*/
|
||||
var consoleLog = console.log;
|
||||
|
||||
/**
|
||||
* Enable coloring by default, except in the browser interface.
|
||||
*/
|
||||
|
||||
exports.useColors =
|
||||
!isBrowser &&
|
||||
(supportsColor.stdout || process.env.MOCHA_COLORS !== undefined);
|
||||
|
||||
/**
|
||||
* Inline diffs instead of +/-
|
||||
*/
|
||||
|
||||
exports.inlineDiffs = false;
|
||||
|
||||
/**
|
||||
* Default color map.
|
||||
*/
|
||||
|
||||
exports.colors = {
|
||||
pass: 90,
|
||||
fail: 31,
|
||||
'bright pass': 92,
|
||||
'bright fail': 91,
|
||||
'bright yellow': 93,
|
||||
pending: 36,
|
||||
suite: 0,
|
||||
'error title': 0,
|
||||
'error message': 31,
|
||||
'error stack': 90,
|
||||
checkmark: 32,
|
||||
fast: 90,
|
||||
medium: 33,
|
||||
slow: 31,
|
||||
green: 32,
|
||||
light: 90,
|
||||
'diff gutter': 90,
|
||||
'diff added': 32,
|
||||
'diff removed': 31,
|
||||
'diff added inline': '30;42',
|
||||
'diff removed inline': '30;41'
|
||||
};
|
||||
|
||||
/**
|
||||
* Default symbol map.
|
||||
*/
|
||||
|
||||
exports.symbols = {
|
||||
ok: symbols.success,
|
||||
err: symbols.err,
|
||||
dot: '.',
|
||||
comma: ',',
|
||||
bang: '!'
|
||||
};
|
||||
|
||||
/**
|
||||
* Color `str` with the given `type`,
|
||||
* allowing colors to be disabled,
|
||||
* as well as user-defined color
|
||||
* schemes.
|
||||
*
|
||||
* @private
|
||||
* @param {string} type
|
||||
* @param {string} str
|
||||
* @return {string}
|
||||
*/
|
||||
var color = (exports.color = function(type, str) {
|
||||
if (!exports.useColors) {
|
||||
return String(str);
|
||||
}
|
||||
return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';
|
||||
});
|
||||
|
||||
/**
|
||||
* Expose term window size, with some defaults for when stderr is not a tty.
|
||||
*/
|
||||
|
||||
exports.window = {
|
||||
width: 75
|
||||
};
|
||||
|
||||
if (isatty) {
|
||||
if (isBrowser) {
|
||||
exports.window.width = getBrowserWindowSize()[1];
|
||||
} else {
|
||||
exports.window.width = process.stdout.getWindowSize(1)[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose some basic cursor interactions that are common among reporters.
|
||||
*/
|
||||
|
||||
exports.cursor = {
|
||||
hide: function() {
|
||||
isatty && process.stdout.write('\u001b[?25l');
|
||||
},
|
||||
|
||||
show: function() {
|
||||
isatty && process.stdout.write('\u001b[?25h');
|
||||
},
|
||||
|
||||
deleteLine: function() {
|
||||
isatty && process.stdout.write('\u001b[2K');
|
||||
},
|
||||
|
||||
beginningOfLine: function() {
|
||||
isatty && process.stdout.write('\u001b[0G');
|
||||
},
|
||||
|
||||
CR: function() {
|
||||
if (isatty) {
|
||||
exports.cursor.deleteLine();
|
||||
exports.cursor.beginningOfLine();
|
||||
} else {
|
||||
process.stdout.write('\r');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var showDiff = (exports.showDiff = function(err) {
|
||||
return (
|
||||
err &&
|
||||
err.showDiff !== false &&
|
||||
sameType(err.actual, err.expected) &&
|
||||
err.expected !== undefined
|
||||
);
|
||||
});
|
||||
|
||||
function stringifyDiffObjs(err) {
|
||||
if (!utils.isString(err.actual) || !utils.isString(err.expected)) {
|
||||
err.actual = utils.stringify(err.actual);
|
||||
err.expected = utils.stringify(err.expected);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a diff between 2 strings with coloured ANSI output.
|
||||
*
|
||||
* @description
|
||||
* The diff will be either inline or unified dependent on the value
|
||||
* of `Base.inlineDiff`.
|
||||
*
|
||||
* @param {string} actual
|
||||
* @param {string} expected
|
||||
* @return {string} Diff
|
||||
*/
|
||||
var generateDiff = (exports.generateDiff = function(actual, expected) {
|
||||
try {
|
||||
const diffSize = 2048;
|
||||
if (actual.length > diffSize) {
|
||||
actual = actual.substring(0, diffSize) + ' ... Lines skipped';
|
||||
}
|
||||
if (expected.length > diffSize) {
|
||||
expected = expected.substring(0, diffSize) + ' ... Lines skipped';
|
||||
}
|
||||
return exports.inlineDiffs
|
||||
? inlineDiff(actual, expected)
|
||||
: unifiedDiff(actual, expected);
|
||||
} catch (err) {
|
||||
var msg =
|
||||
'\n ' +
|
||||
color('diff added', '+ expected') +
|
||||
' ' +
|
||||
color('diff removed', '- actual: failed to generate Mocha diff') +
|
||||
'\n';
|
||||
return msg;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Outputs the given `failures` as a list.
|
||||
*
|
||||
* @public
|
||||
* @memberof Mocha.reporters.Base
|
||||
* @variation 1
|
||||
* @param {Object[]} failures - Each is Test instance with corresponding
|
||||
* Error property
|
||||
*/
|
||||
exports.list = function(failures) {
|
||||
var multipleErr, multipleTest;
|
||||
Base.consoleLog();
|
||||
failures.forEach(function(test, i) {
|
||||
// format
|
||||
var fmt =
|
||||
color('error title', ' %s) %s:\n') +
|
||||
color('error message', ' %s') +
|
||||
color('error stack', '\n%s\n');
|
||||
|
||||
// msg
|
||||
var msg;
|
||||
var err;
|
||||
if (test.err && test.err.multiple) {
|
||||
if (multipleTest !== test) {
|
||||
multipleTest = test;
|
||||
multipleErr = [test.err].concat(test.err.multiple);
|
||||
}
|
||||
err = multipleErr.shift();
|
||||
} else {
|
||||
err = test.err;
|
||||
}
|
||||
var message;
|
||||
if (typeof err.inspect === 'function') {
|
||||
message = err.inspect() + '';
|
||||
} else if (err.message && typeof err.message.toString === 'function') {
|
||||
message = err.message + '';
|
||||
} else {
|
||||
message = '';
|
||||
}
|
||||
var stack = err.stack || message;
|
||||
var index = message ? stack.indexOf(message) : -1;
|
||||
|
||||
if (index === -1) {
|
||||
msg = message;
|
||||
} else {
|
||||
index += message.length;
|
||||
msg = stack.slice(0, index);
|
||||
// remove msg from stack
|
||||
stack = stack.slice(index + 1);
|
||||
}
|
||||
|
||||
// uncaught
|
||||
if (err.uncaught) {
|
||||
msg = 'Uncaught ' + msg;
|
||||
}
|
||||
// explicitly show diff
|
||||
if (!exports.hideDiff && showDiff(err)) {
|
||||
stringifyDiffObjs(err);
|
||||
fmt =
|
||||
color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
|
||||
var match = message.match(/^([^:]+): expected/);
|
||||
msg = '\n ' + color('error message', match ? match[1] : msg);
|
||||
|
||||
msg += generateDiff(err.actual, err.expected);
|
||||
}
|
||||
|
||||
// indent stack trace
|
||||
stack = stack.replace(/^/gm, ' ');
|
||||
|
||||
// indented test title
|
||||
var testTitle = '';
|
||||
test.titlePath().forEach(function(str, index) {
|
||||
if (index !== 0) {
|
||||
testTitle += '\n ';
|
||||
}
|
||||
for (var i = 0; i < index; i++) {
|
||||
testTitle += ' ';
|
||||
}
|
||||
testTitle += str;
|
||||
});
|
||||
|
||||
Base.consoleLog(fmt, i + 1, testTitle, msg, stack);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructs a new `Base` reporter instance.
|
||||
*
|
||||
* @description
|
||||
* All other reporters generally inherit from this reporter.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @param {Runner} runner - Instance triggers reporter actions.
|
||||
* @param {Object} [options] - runner options
|
||||
*/
|
||||
function Base(runner, options) {
|
||||
var failures = (this.failures = []);
|
||||
|
||||
if (!runner) {
|
||||
throw new TypeError('Missing runner argument');
|
||||
}
|
||||
this.options = options || {};
|
||||
this.runner = runner;
|
||||
this.stats = runner.stats; // assigned so Reporters keep a closer reference
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function(test) {
|
||||
if (test.duration > test.slow()) {
|
||||
test.speed = 'slow';
|
||||
} else if (test.duration > test.slow() / 2) {
|
||||
test.speed = 'medium';
|
||||
} else {
|
||||
test.speed = 'fast';
|
||||
}
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function(test, err) {
|
||||
if (showDiff(err)) {
|
||||
stringifyDiffObjs(err);
|
||||
}
|
||||
// more than one error per test
|
||||
if (test.err && err instanceof Error) {
|
||||
test.err.multiple = (test.err.multiple || []).concat(err);
|
||||
} else {
|
||||
test.err = err;
|
||||
}
|
||||
failures.push(test);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs common epilogue used by many of the bundled reporters.
|
||||
*
|
||||
* @public
|
||||
* @memberof Mocha.reporters
|
||||
*/
|
||||
Base.prototype.epilogue = function() {
|
||||
var stats = this.stats;
|
||||
var fmt;
|
||||
|
||||
Base.consoleLog();
|
||||
|
||||
// passes
|
||||
fmt =
|
||||
color('bright pass', ' ') +
|
||||
color('green', ' %d passing') +
|
||||
color('light', ' (%s)');
|
||||
|
||||
Base.consoleLog(fmt, stats.passes || 0, milliseconds(stats.duration));
|
||||
|
||||
// pending
|
||||
if (stats.pending) {
|
||||
fmt = color('pending', ' ') + color('pending', ' %d pending');
|
||||
|
||||
Base.consoleLog(fmt, stats.pending);
|
||||
}
|
||||
|
||||
// failures
|
||||
if (stats.failures) {
|
||||
fmt = color('fail', ' %d failing');
|
||||
|
||||
Base.consoleLog(fmt, stats.failures);
|
||||
|
||||
Base.list(this.failures);
|
||||
Base.consoleLog();
|
||||
}
|
||||
|
||||
Base.consoleLog();
|
||||
};
|
||||
|
||||
/**
|
||||
* Pads the given `str` to `len`.
|
||||
*
|
||||
* @private
|
||||
* @param {string} str
|
||||
* @param {string} len
|
||||
* @return {string}
|
||||
*/
|
||||
function pad(str, len) {
|
||||
str = String(str);
|
||||
return Array(len - str.length + 1).join(' ') + str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns inline diff between 2 strings with coloured ANSI output.
|
||||
*
|
||||
* @private
|
||||
* @param {String} actual
|
||||
* @param {String} expected
|
||||
* @return {string} Diff
|
||||
*/
|
||||
function inlineDiff(actual, expected) {
|
||||
var msg = errorDiff(actual, expected);
|
||||
|
||||
// linenos
|
||||
var lines = msg.split('\n');
|
||||
if (lines.length > 4) {
|
||||
var width = String(lines.length).length;
|
||||
msg = lines
|
||||
.map(function(str, i) {
|
||||
return pad(++i, width) + ' |' + ' ' + str;
|
||||
})
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
// legend
|
||||
msg =
|
||||
'\n' +
|
||||
color('diff removed inline', 'actual') +
|
||||
' ' +
|
||||
color('diff added inline', 'expected') +
|
||||
'\n\n' +
|
||||
msg +
|
||||
'\n';
|
||||
|
||||
// indent
|
||||
msg = msg.replace(/^/gm, ' ');
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns unified diff between two strings with coloured ANSI output.
|
||||
*
|
||||
* @private
|
||||
* @param {String} actual
|
||||
* @param {String} expected
|
||||
* @return {string} The diff.
|
||||
*/
|
||||
function unifiedDiff(actual, expected) {
|
||||
var indent = ' ';
|
||||
function cleanUp(line) {
|
||||
if (line[0] === '+') {
|
||||
return indent + colorLines('diff added', line);
|
||||
}
|
||||
if (line[0] === '-') {
|
||||
return indent + colorLines('diff removed', line);
|
||||
}
|
||||
if (line.match(/@@/)) {
|
||||
return '--';
|
||||
}
|
||||
if (line.match(/\\ No newline/)) {
|
||||
return null;
|
||||
}
|
||||
return indent + line;
|
||||
}
|
||||
function notBlank(line) {
|
||||
return typeof line !== 'undefined' && line !== null;
|
||||
}
|
||||
var msg = diff.createPatch('string', actual, expected);
|
||||
var lines = msg.split('\n').splice(5);
|
||||
return (
|
||||
'\n ' +
|
||||
colorLines('diff added', '+ expected') +
|
||||
' ' +
|
||||
colorLines('diff removed', '- actual') +
|
||||
'\n\n' +
|
||||
lines
|
||||
.map(cleanUp)
|
||||
.filter(notBlank)
|
||||
.join('\n')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns character diff for `err`.
|
||||
*
|
||||
* @private
|
||||
* @param {String} actual
|
||||
* @param {String} expected
|
||||
* @return {string} the diff
|
||||
*/
|
||||
function errorDiff(actual, expected) {
|
||||
return diff
|
||||
.diffWordsWithSpace(actual, expected)
|
||||
.map(function(str) {
|
||||
if (str.added) {
|
||||
return colorLines('diff added inline', str.value);
|
||||
}
|
||||
if (str.removed) {
|
||||
return colorLines('diff removed inline', str.value);
|
||||
}
|
||||
return str.value;
|
||||
})
|
||||
.join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Colors lines for `str`, using the color `name`.
|
||||
*
|
||||
* @private
|
||||
* @param {string} name
|
||||
* @param {string} str
|
||||
* @return {string}
|
||||
*/
|
||||
function colorLines(name, str) {
|
||||
return str
|
||||
.split('\n')
|
||||
.map(function(str) {
|
||||
return color(name, str);
|
||||
})
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Object#toString reference.
|
||||
*/
|
||||
var objToString = Object.prototype.toString;
|
||||
|
||||
/**
|
||||
* Checks that a / b have the same type.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} a
|
||||
* @param {Object} b
|
||||
* @return {boolean}
|
||||
*/
|
||||
function sameType(a, b) {
|
||||
return objToString.call(a) === objToString.call(b);
|
||||
}
|
||||
|
||||
Base.consoleLog = consoleLog;
|
||||
|
||||
Base.abstract = true;
|
||||
95
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/doc.js
generated
vendored
Normal file
95
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/doc.js
generated
vendored
Normal file
@ -0,0 +1,95 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module Doc
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var utils = require('../utils');
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
var EVENT_SUITE_BEGIN = constants.EVENT_SUITE_BEGIN;
|
||||
var EVENT_SUITE_END = constants.EVENT_SUITE_END;
|
||||
|
||||
/**
|
||||
* Expose `Doc`.
|
||||
*/
|
||||
|
||||
exports = module.exports = Doc;
|
||||
|
||||
/**
|
||||
* Constructs a new `Doc` reporter instance.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner - Instance triggers reporter actions.
|
||||
* @param {Object} [options] - runner options
|
||||
*/
|
||||
function Doc(runner, options) {
|
||||
Base.call(this, runner, options);
|
||||
|
||||
var indents = 2;
|
||||
|
||||
function indent() {
|
||||
return Array(indents).join(' ');
|
||||
}
|
||||
|
||||
runner.on(EVENT_SUITE_BEGIN, function(suite) {
|
||||
if (suite.root) {
|
||||
return;
|
||||
}
|
||||
++indents;
|
||||
Base.consoleLog('%s<section class="suite">', indent());
|
||||
++indents;
|
||||
Base.consoleLog('%s<h1>%s</h1>', indent(), utils.escape(suite.title));
|
||||
Base.consoleLog('%s<dl>', indent());
|
||||
});
|
||||
|
||||
runner.on(EVENT_SUITE_END, function(suite) {
|
||||
if (suite.root) {
|
||||
return;
|
||||
}
|
||||
Base.consoleLog('%s</dl>', indent());
|
||||
--indents;
|
||||
Base.consoleLog('%s</section>', indent());
|
||||
--indents;
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function(test) {
|
||||
Base.consoleLog('%s <dt>%s</dt>', indent(), utils.escape(test.title));
|
||||
Base.consoleLog('%s <dt>%s</dt>', indent(), utils.escape(test.file));
|
||||
var code = utils.escape(utils.clean(test.body));
|
||||
Base.consoleLog('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function(test, err) {
|
||||
Base.consoleLog(
|
||||
'%s <dt class="error">%s</dt>',
|
||||
indent(),
|
||||
utils.escape(test.title)
|
||||
);
|
||||
Base.consoleLog(
|
||||
'%s <dt class="error">%s</dt>',
|
||||
indent(),
|
||||
utils.escape(test.file)
|
||||
);
|
||||
var code = utils.escape(utils.clean(test.body));
|
||||
Base.consoleLog(
|
||||
'%s <dd class="error"><pre><code>%s</code></pre></dd>',
|
||||
indent(),
|
||||
code
|
||||
);
|
||||
Base.consoleLog(
|
||||
'%s <dd class="error">%s</dd>',
|
||||
indent(),
|
||||
utils.escape(err)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Doc.description = 'HTML documentation';
|
||||
81
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/dot.js
generated
vendored
Normal file
81
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/dot.js
generated
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module Dot
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var inherits = require('../utils').inherits;
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
||||
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
|
||||
/**
|
||||
* Expose `Dot`.
|
||||
*/
|
||||
|
||||
exports = module.exports = Dot;
|
||||
|
||||
/**
|
||||
* Constructs a new `Dot` reporter instance.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner - Instance triggers reporter actions.
|
||||
* @param {Object} [options] - runner options
|
||||
*/
|
||||
function Dot(runner, options) {
|
||||
Base.call(this, runner, options);
|
||||
|
||||
var self = this;
|
||||
var width = (Base.window.width * 0.75) | 0;
|
||||
var n = -1;
|
||||
|
||||
runner.on(EVENT_RUN_BEGIN, function() {
|
||||
process.stdout.write('\n');
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PENDING, function() {
|
||||
if (++n % width === 0) {
|
||||
process.stdout.write('\n ');
|
||||
}
|
||||
process.stdout.write(Base.color('pending', Base.symbols.comma));
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function(test) {
|
||||
if (++n % width === 0) {
|
||||
process.stdout.write('\n ');
|
||||
}
|
||||
if (test.speed === 'slow') {
|
||||
process.stdout.write(Base.color('bright yellow', Base.symbols.dot));
|
||||
} else {
|
||||
process.stdout.write(Base.color(test.speed, Base.symbols.dot));
|
||||
}
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function() {
|
||||
if (++n % width === 0) {
|
||||
process.stdout.write('\n ');
|
||||
}
|
||||
process.stdout.write(Base.color('fail', Base.symbols.bang));
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_END, function() {
|
||||
process.stdout.write('\n');
|
||||
self.epilogue();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Base.prototype`.
|
||||
*/
|
||||
inherits(Dot, Base);
|
||||
|
||||
Dot.description = 'dot matrix representation';
|
||||
390
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/html.js
generated
vendored
Normal file
390
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/html.js
generated
vendored
Normal file
@ -0,0 +1,390 @@
|
||||
'use strict';
|
||||
|
||||
/* eslint-env browser */
|
||||
/**
|
||||
* @module HTML
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var utils = require('../utils');
|
||||
var Progress = require('../browser/progress');
|
||||
var escapeRe = require('escape-string-regexp');
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
var EVENT_SUITE_BEGIN = constants.EVENT_SUITE_BEGIN;
|
||||
var EVENT_SUITE_END = constants.EVENT_SUITE_END;
|
||||
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
||||
var escape = utils.escape;
|
||||
|
||||
/**
|
||||
* Save timer references to avoid Sinon interfering (see GH-237).
|
||||
*/
|
||||
|
||||
var Date = global.Date;
|
||||
|
||||
/**
|
||||
* Expose `HTML`.
|
||||
*/
|
||||
|
||||
exports = module.exports = HTML;
|
||||
|
||||
/**
|
||||
* Stats template.
|
||||
*/
|
||||
|
||||
var statsTemplate =
|
||||
'<ul id="mocha-stats">' +
|
||||
'<li class="progress"><canvas width="40" height="40"></canvas></li>' +
|
||||
'<li class="passes"><a href="javascript:void(0);">passes:</a> <em>0</em></li>' +
|
||||
'<li class="failures"><a href="javascript:void(0);">failures:</a> <em>0</em></li>' +
|
||||
'<li class="duration">duration: <em>0</em>s</li>' +
|
||||
'</ul>';
|
||||
|
||||
var playIcon = '‣';
|
||||
|
||||
/**
|
||||
* Constructs a new `HTML` reporter instance.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner - Instance triggers reporter actions.
|
||||
* @param {Object} [options] - runner options
|
||||
*/
|
||||
function HTML(runner, options) {
|
||||
Base.call(this, runner, options);
|
||||
|
||||
var self = this;
|
||||
var stats = this.stats;
|
||||
var stat = fragment(statsTemplate);
|
||||
var items = stat.getElementsByTagName('li');
|
||||
var passes = items[1].getElementsByTagName('em')[0];
|
||||
var passesLink = items[1].getElementsByTagName('a')[0];
|
||||
var failures = items[2].getElementsByTagName('em')[0];
|
||||
var failuresLink = items[2].getElementsByTagName('a')[0];
|
||||
var duration = items[3].getElementsByTagName('em')[0];
|
||||
var canvas = stat.getElementsByTagName('canvas')[0];
|
||||
var report = fragment('<ul id="mocha-report"></ul>');
|
||||
var stack = [report];
|
||||
var progress;
|
||||
var ctx;
|
||||
var root = document.getElementById('mocha');
|
||||
|
||||
if (canvas.getContext) {
|
||||
var ratio = window.devicePixelRatio || 1;
|
||||
canvas.style.width = canvas.width;
|
||||
canvas.style.height = canvas.height;
|
||||
canvas.width *= ratio;
|
||||
canvas.height *= ratio;
|
||||
ctx = canvas.getContext('2d');
|
||||
ctx.scale(ratio, ratio);
|
||||
progress = new Progress();
|
||||
}
|
||||
|
||||
if (!root) {
|
||||
return error('#mocha div missing, add it to your document');
|
||||
}
|
||||
|
||||
// pass toggle
|
||||
on(passesLink, 'click', function(evt) {
|
||||
evt.preventDefault();
|
||||
unhide();
|
||||
var name = /pass/.test(report.className) ? '' : ' pass';
|
||||
report.className = report.className.replace(/fail|pass/g, '') + name;
|
||||
if (report.className.trim()) {
|
||||
hideSuitesWithout('test pass');
|
||||
}
|
||||
});
|
||||
|
||||
// failure toggle
|
||||
on(failuresLink, 'click', function(evt) {
|
||||
evt.preventDefault();
|
||||
unhide();
|
||||
var name = /fail/.test(report.className) ? '' : ' fail';
|
||||
report.className = report.className.replace(/fail|pass/g, '') + name;
|
||||
if (report.className.trim()) {
|
||||
hideSuitesWithout('test fail');
|
||||
}
|
||||
});
|
||||
|
||||
root.appendChild(stat);
|
||||
root.appendChild(report);
|
||||
|
||||
if (progress) {
|
||||
progress.size(40);
|
||||
}
|
||||
|
||||
runner.on(EVENT_SUITE_BEGIN, function(suite) {
|
||||
if (suite.root) {
|
||||
return;
|
||||
}
|
||||
|
||||
// suite
|
||||
var url = self.suiteURL(suite);
|
||||
var el = fragment(
|
||||
'<li class="suite"><h1><a href="%s">%s</a></h1></li>',
|
||||
url,
|
||||
escape(suite.title)
|
||||
);
|
||||
|
||||
// container
|
||||
stack[0].appendChild(el);
|
||||
stack.unshift(document.createElement('ul'));
|
||||
el.appendChild(stack[0]);
|
||||
});
|
||||
|
||||
runner.on(EVENT_SUITE_END, function(suite) {
|
||||
if (suite.root) {
|
||||
updateStats();
|
||||
return;
|
||||
}
|
||||
stack.shift();
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function(test) {
|
||||
var url = self.testURL(test);
|
||||
var markup =
|
||||
'<li class="test pass %e"><h2>%e<span class="duration">%ems</span> ' +
|
||||
'<a href="%s" class="replay">' +
|
||||
playIcon +
|
||||
'</a></h2></li>';
|
||||
var el = fragment(markup, test.speed, test.title, test.duration, url);
|
||||
self.addCodeToggle(el, test.body);
|
||||
appendToStack(el);
|
||||
updateStats();
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function(test) {
|
||||
var el = fragment(
|
||||
'<li class="test fail"><h2>%e <a href="%e" class="replay">' +
|
||||
playIcon +
|
||||
'</a></h2></li>',
|
||||
test.title,
|
||||
self.testURL(test)
|
||||
);
|
||||
var stackString; // Note: Includes leading newline
|
||||
var message = test.err.toString();
|
||||
|
||||
// <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
|
||||
// check for the result of the stringifying.
|
||||
if (message === '[object Error]') {
|
||||
message = test.err.message;
|
||||
}
|
||||
|
||||
if (test.err.stack) {
|
||||
var indexOfMessage = test.err.stack.indexOf(test.err.message);
|
||||
if (indexOfMessage === -1) {
|
||||
stackString = test.err.stack;
|
||||
} else {
|
||||
stackString = test.err.stack.substr(
|
||||
test.err.message.length + indexOfMessage
|
||||
);
|
||||
}
|
||||
} else if (test.err.sourceURL && test.err.line !== undefined) {
|
||||
// Safari doesn't give you a stack. Let's at least provide a source line.
|
||||
stackString = '\n(' + test.err.sourceURL + ':' + test.err.line + ')';
|
||||
}
|
||||
|
||||
stackString = stackString || '';
|
||||
|
||||
if (test.err.htmlMessage && stackString) {
|
||||
el.appendChild(
|
||||
fragment(
|
||||
'<div class="html-error">%s\n<pre class="error">%e</pre></div>',
|
||||
test.err.htmlMessage,
|
||||
stackString
|
||||
)
|
||||
);
|
||||
} else if (test.err.htmlMessage) {
|
||||
el.appendChild(
|
||||
fragment('<div class="html-error">%s</div>', test.err.htmlMessage)
|
||||
);
|
||||
} else {
|
||||
el.appendChild(
|
||||
fragment('<pre class="error">%e%e</pre>', message, stackString)
|
||||
);
|
||||
}
|
||||
|
||||
self.addCodeToggle(el, test.body);
|
||||
appendToStack(el);
|
||||
updateStats();
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PENDING, function(test) {
|
||||
var el = fragment(
|
||||
'<li class="test pass pending"><h2>%e</h2></li>',
|
||||
test.title
|
||||
);
|
||||
appendToStack(el);
|
||||
updateStats();
|
||||
});
|
||||
|
||||
function appendToStack(el) {
|
||||
// Don't call .appendChild if #mocha-report was already .shift()'ed off the stack.
|
||||
if (stack[0]) {
|
||||
stack[0].appendChild(el);
|
||||
}
|
||||
}
|
||||
|
||||
function updateStats() {
|
||||
// TODO: add to stats
|
||||
var percent = ((stats.tests / runner.total) * 100) | 0;
|
||||
if (progress) {
|
||||
progress.update(percent).draw(ctx);
|
||||
}
|
||||
|
||||
// update stats
|
||||
var ms = new Date() - stats.start;
|
||||
text(passes, stats.passes);
|
||||
text(failures, stats.failures);
|
||||
text(duration, (ms / 1000).toFixed(2));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a URL, preserving querystring ("search") parameters.
|
||||
*
|
||||
* @param {string} s
|
||||
* @return {string} A new URL.
|
||||
*/
|
||||
function makeUrl(s) {
|
||||
var search = window.location.search;
|
||||
|
||||
// Remove previous grep query parameter if present
|
||||
if (search) {
|
||||
search = search.replace(/[?&]grep=[^&\s]*/g, '').replace(/^&/, '?');
|
||||
}
|
||||
|
||||
return (
|
||||
window.location.pathname +
|
||||
(search ? search + '&' : '?') +
|
||||
'grep=' +
|
||||
encodeURIComponent(escapeRe(s))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide suite URL.
|
||||
*
|
||||
* @param {Object} [suite]
|
||||
*/
|
||||
HTML.prototype.suiteURL = function(suite) {
|
||||
return makeUrl(suite.fullTitle());
|
||||
};
|
||||
|
||||
/**
|
||||
* Provide test URL.
|
||||
*
|
||||
* @param {Object} [test]
|
||||
*/
|
||||
HTML.prototype.testURL = function(test) {
|
||||
return makeUrl(test.fullTitle());
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds code toggle functionality for the provided test's list element.
|
||||
*
|
||||
* @param {HTMLLIElement} el
|
||||
* @param {string} contents
|
||||
*/
|
||||
HTML.prototype.addCodeToggle = function(el, contents) {
|
||||
var h2 = el.getElementsByTagName('h2')[0];
|
||||
|
||||
on(h2, 'click', function() {
|
||||
pre.style.display = pre.style.display === 'none' ? 'block' : 'none';
|
||||
});
|
||||
|
||||
var pre = fragment('<pre><code>%e</code></pre>', utils.clean(contents));
|
||||
el.appendChild(pre);
|
||||
pre.style.display = 'none';
|
||||
};
|
||||
|
||||
/**
|
||||
* Display error `msg`.
|
||||
*
|
||||
* @param {string} msg
|
||||
*/
|
||||
function error(msg) {
|
||||
document.body.appendChild(fragment('<div id="mocha-error">%s</div>', msg));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a DOM fragment from `html`.
|
||||
*
|
||||
* @param {string} html
|
||||
*/
|
||||
function fragment(html) {
|
||||
var args = arguments;
|
||||
var div = document.createElement('div');
|
||||
var i = 1;
|
||||
|
||||
div.innerHTML = html.replace(/%([se])/g, function(_, type) {
|
||||
switch (type) {
|
||||
case 's':
|
||||
return String(args[i++]);
|
||||
case 'e':
|
||||
return escape(args[i++]);
|
||||
// no default
|
||||
}
|
||||
});
|
||||
|
||||
return div.firstChild;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for suites that do not have elements
|
||||
* with `classname`, and hide them.
|
||||
*
|
||||
* @param {text} classname
|
||||
*/
|
||||
function hideSuitesWithout(classname) {
|
||||
var suites = document.getElementsByClassName('suite');
|
||||
for (var i = 0; i < suites.length; i++) {
|
||||
var els = suites[i].getElementsByClassName(classname);
|
||||
if (!els.length) {
|
||||
suites[i].className += ' hidden';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unhide .hidden suites.
|
||||
*/
|
||||
function unhide() {
|
||||
var els = document.getElementsByClassName('suite hidden');
|
||||
while (els.length > 0) {
|
||||
els[0].className = els[0].className.replace('suite hidden', 'suite');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an element's text contents.
|
||||
*
|
||||
* @param {HTMLElement} el
|
||||
* @param {string} contents
|
||||
*/
|
||||
function text(el, contents) {
|
||||
if (el.textContent) {
|
||||
el.textContent = contents;
|
||||
} else {
|
||||
el.innerText = contents;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen on `event` with callback `fn`.
|
||||
*/
|
||||
function on(el, event, fn) {
|
||||
if (el.addEventListener) {
|
||||
el.addEventListener(event, fn, false);
|
||||
} else {
|
||||
el.attachEvent('on' + event, fn);
|
||||
}
|
||||
}
|
||||
|
||||
HTML.browserOnly = true;
|
||||
19
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/index.js
generated
vendored
Normal file
19
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/index.js
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
// Alias exports to a their normalized format Mocha#reporter to prevent a need
|
||||
// for dynamic (try/catch) requires, which Browserify doesn't handle.
|
||||
exports.Base = exports.base = require('./base');
|
||||
exports.Dot = exports.dot = require('./dot');
|
||||
exports.Doc = exports.doc = require('./doc');
|
||||
exports.TAP = exports.tap = require('./tap');
|
||||
exports.JSON = exports.json = require('./json');
|
||||
exports.HTML = exports.html = require('./html');
|
||||
exports.List = exports.list = require('./list');
|
||||
exports.Min = exports.min = require('./min');
|
||||
exports.Spec = exports.spec = require('./spec');
|
||||
exports.Nyan = exports.nyan = require('./nyan');
|
||||
exports.XUnit = exports.xunit = require('./xunit');
|
||||
exports.Markdown = exports.markdown = require('./markdown');
|
||||
exports.Progress = exports.progress = require('./progress');
|
||||
exports.Landing = exports.landing = require('./landing');
|
||||
exports.JSONStream = exports['json-stream'] = require('./json-stream');
|
||||
92
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/json-stream.js
generated
vendored
Normal file
92
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/json-stream.js
generated
vendored
Normal file
@ -0,0 +1,92 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module JSONStream
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
|
||||
/**
|
||||
* Expose `JSONStream`.
|
||||
*/
|
||||
|
||||
exports = module.exports = JSONStream;
|
||||
|
||||
/**
|
||||
* Constructs a new `JSONStream` reporter instance.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner - Instance triggers reporter actions.
|
||||
* @param {Object} [options] - runner options
|
||||
*/
|
||||
function JSONStream(runner, options) {
|
||||
Base.call(this, runner, options);
|
||||
|
||||
var self = this;
|
||||
var total = runner.total;
|
||||
|
||||
runner.once(EVENT_RUN_BEGIN, function() {
|
||||
writeEvent(['start', {total: total}]);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function(test) {
|
||||
writeEvent(['pass', clean(test)]);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function(test, err) {
|
||||
test = clean(test);
|
||||
test.err = err.message;
|
||||
test.stack = err.stack || null;
|
||||
writeEvent(['fail', test]);
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_END, function() {
|
||||
writeEvent(['end', self.stats]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocha event to be written to the output stream.
|
||||
* @typedef {Array} JSONStream~MochaEvent
|
||||
*/
|
||||
|
||||
/**
|
||||
* Writes Mocha event to reporter output stream.
|
||||
*
|
||||
* @private
|
||||
* @param {JSONStream~MochaEvent} event - Mocha event to be output.
|
||||
*/
|
||||
function writeEvent(event) {
|
||||
process.stdout.write(JSON.stringify(event) + '\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object literal representation of `test`
|
||||
* free of cyclic properties, etc.
|
||||
*
|
||||
* @private
|
||||
* @param {Test} test - Instance used as data source.
|
||||
* @return {Object} object containing pared-down test instance data
|
||||
*/
|
||||
function clean(test) {
|
||||
return {
|
||||
title: test.title,
|
||||
fullTitle: test.fullTitle(),
|
||||
file: test.file,
|
||||
duration: test.duration,
|
||||
currentRetry: test.currentRetry(),
|
||||
speed: test.speed
|
||||
};
|
||||
}
|
||||
|
||||
JSONStream.description = 'newline delimited JSON events';
|
||||
137
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/json.js
generated
vendored
Normal file
137
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/json.js
generated
vendored
Normal file
@ -0,0 +1,137 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module JSON
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
var EVENT_TEST_END = constants.EVENT_TEST_END;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
||||
|
||||
/**
|
||||
* Expose `JSON`.
|
||||
*/
|
||||
|
||||
exports = module.exports = JSONReporter;
|
||||
|
||||
/**
|
||||
* Constructs a new `JSON` reporter instance.
|
||||
*
|
||||
* @public
|
||||
* @class JSON
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner - Instance triggers reporter actions.
|
||||
* @param {Object} [options] - runner options
|
||||
*/
|
||||
function JSONReporter(runner, options) {
|
||||
Base.call(this, runner, options);
|
||||
|
||||
var self = this;
|
||||
var tests = [];
|
||||
var pending = [];
|
||||
var failures = [];
|
||||
var passes = [];
|
||||
|
||||
runner.on(EVENT_TEST_END, function(test) {
|
||||
tests.push(test);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function(test) {
|
||||
passes.push(test);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function(test) {
|
||||
failures.push(test);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PENDING, function(test) {
|
||||
pending.push(test);
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_END, function() {
|
||||
var obj = {
|
||||
stats: self.stats,
|
||||
tests: tests.map(clean),
|
||||
pending: pending.map(clean),
|
||||
failures: failures.map(clean),
|
||||
passes: passes.map(clean)
|
||||
};
|
||||
|
||||
runner.testResults = obj;
|
||||
|
||||
process.stdout.write(JSON.stringify(obj, null, 2));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a plain-object representation of `test`
|
||||
* free of cyclic properties etc.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} test
|
||||
* @return {Object}
|
||||
*/
|
||||
function clean(test) {
|
||||
var err = test.err || {};
|
||||
if (err instanceof Error) {
|
||||
err = errorJSON(err);
|
||||
}
|
||||
|
||||
return {
|
||||
title: test.title,
|
||||
fullTitle: test.fullTitle(),
|
||||
file: test.file,
|
||||
duration: test.duration,
|
||||
currentRetry: test.currentRetry(),
|
||||
speed: test.speed,
|
||||
err: cleanCycles(err)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces any circular references inside `obj` with '[object Object]'
|
||||
*
|
||||
* @private
|
||||
* @param {Object} obj
|
||||
* @return {Object}
|
||||
*/
|
||||
function cleanCycles(obj) {
|
||||
var cache = [];
|
||||
return JSON.parse(
|
||||
JSON.stringify(obj, function(key, value) {
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
if (cache.indexOf(value) !== -1) {
|
||||
// Instead of going in a circle, we'll print [object Object]
|
||||
return '' + value;
|
||||
}
|
||||
cache.push(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform an Error object into a JSON object.
|
||||
*
|
||||
* @private
|
||||
* @param {Error} err
|
||||
* @return {Object}
|
||||
*/
|
||||
function errorJSON(err) {
|
||||
var res = {};
|
||||
Object.getOwnPropertyNames(err).forEach(function(key) {
|
||||
res[key] = err[key];
|
||||
}, err);
|
||||
return res;
|
||||
}
|
||||
|
||||
JSONReporter.description = 'single JSON object';
|
||||
116
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/landing.js
generated
vendored
Normal file
116
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/landing.js
generated
vendored
Normal file
@ -0,0 +1,116 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module Landing
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var inherits = require('../utils').inherits;
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
var EVENT_TEST_END = constants.EVENT_TEST_END;
|
||||
var STATE_FAILED = require('../runnable').constants.STATE_FAILED;
|
||||
|
||||
var cursor = Base.cursor;
|
||||
var color = Base.color;
|
||||
|
||||
/**
|
||||
* Expose `Landing`.
|
||||
*/
|
||||
|
||||
exports = module.exports = Landing;
|
||||
|
||||
/**
|
||||
* Airplane color.
|
||||
*/
|
||||
|
||||
Base.colors.plane = 0;
|
||||
|
||||
/**
|
||||
* Airplane crash color.
|
||||
*/
|
||||
|
||||
Base.colors['plane crash'] = 31;
|
||||
|
||||
/**
|
||||
* Runway color.
|
||||
*/
|
||||
|
||||
Base.colors.runway = 90;
|
||||
|
||||
/**
|
||||
* Constructs a new `Landing` reporter instance.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner - Instance triggers reporter actions.
|
||||
* @param {Object} [options] - runner options
|
||||
*/
|
||||
function Landing(runner, options) {
|
||||
Base.call(this, runner, options);
|
||||
|
||||
var self = this;
|
||||
var width = (Base.window.width * 0.75) | 0;
|
||||
var stream = process.stdout;
|
||||
|
||||
var plane = color('plane', '✈');
|
||||
var crashed = -1;
|
||||
var n = 0;
|
||||
var total = 0;
|
||||
|
||||
function runway() {
|
||||
var buf = Array(width).join('-');
|
||||
return ' ' + color('runway', buf);
|
||||
}
|
||||
|
||||
runner.on(EVENT_RUN_BEGIN, function() {
|
||||
stream.write('\n\n\n ');
|
||||
cursor.hide();
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_END, function(test) {
|
||||
// check if the plane crashed
|
||||
var col = crashed === -1 ? ((width * ++n) / ++total) | 0 : crashed;
|
||||
// show the crash
|
||||
if (test.state === STATE_FAILED) {
|
||||
plane = color('plane crash', '✈');
|
||||
crashed = col;
|
||||
}
|
||||
|
||||
// render landing strip
|
||||
stream.write('\u001b[' + (width + 1) + 'D\u001b[2A');
|
||||
stream.write(runway());
|
||||
stream.write('\n ');
|
||||
stream.write(color('runway', Array(col).join('⋅')));
|
||||
stream.write(plane);
|
||||
stream.write(color('runway', Array(width - col).join('⋅') + '\n'));
|
||||
stream.write(runway());
|
||||
stream.write('\u001b[0m');
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_END, function() {
|
||||
cursor.show();
|
||||
process.stdout.write('\n');
|
||||
self.epilogue();
|
||||
});
|
||||
|
||||
// if cursor is hidden when we ctrl-C, then it will remain hidden unless...
|
||||
process.once('SIGINT', function() {
|
||||
cursor.show();
|
||||
process.nextTick(function() {
|
||||
process.kill(process.pid, 'SIGINT');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Base.prototype`.
|
||||
*/
|
||||
inherits(Landing, Base);
|
||||
|
||||
Landing.description = 'Unicode landing strip';
|
||||
78
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/list.js
generated
vendored
Normal file
78
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/list.js
generated
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module List
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var inherits = require('../utils').inherits;
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
var EVENT_TEST_BEGIN = constants.EVENT_TEST_BEGIN;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
||||
var color = Base.color;
|
||||
var cursor = Base.cursor;
|
||||
|
||||
/**
|
||||
* Expose `List`.
|
||||
*/
|
||||
|
||||
exports = module.exports = List;
|
||||
|
||||
/**
|
||||
* Constructs a new `List` reporter instance.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner - Instance triggers reporter actions.
|
||||
* @param {Object} [options] - runner options
|
||||
*/
|
||||
function List(runner, options) {
|
||||
Base.call(this, runner, options);
|
||||
|
||||
var self = this;
|
||||
var n = 0;
|
||||
|
||||
runner.on(EVENT_RUN_BEGIN, function() {
|
||||
Base.consoleLog();
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_BEGIN, function(test) {
|
||||
process.stdout.write(color('pass', ' ' + test.fullTitle() + ': '));
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PENDING, function(test) {
|
||||
var fmt = color('checkmark', ' -') + color('pending', ' %s');
|
||||
Base.consoleLog(fmt, test.fullTitle());
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function(test) {
|
||||
var fmt =
|
||||
color('checkmark', ' ' + Base.symbols.ok) +
|
||||
color('pass', ' %s: ') +
|
||||
color(test.speed, '%dms');
|
||||
cursor.CR();
|
||||
Base.consoleLog(fmt, test.fullTitle(), test.duration);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function(test) {
|
||||
cursor.CR();
|
||||
Base.consoleLog(color('fail', ' %d) %s'), ++n, test.fullTitle());
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_END, self.epilogue.bind(self));
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Base.prototype`.
|
||||
*/
|
||||
inherits(List, Base);
|
||||
|
||||
List.description = 'like "spec" reporter but flat';
|
||||
112
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/markdown.js
generated
vendored
Normal file
112
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/markdown.js
generated
vendored
Normal file
@ -0,0 +1,112 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module Markdown
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var utils = require('../utils');
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
var EVENT_SUITE_BEGIN = constants.EVENT_SUITE_BEGIN;
|
||||
var EVENT_SUITE_END = constants.EVENT_SUITE_END;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
|
||||
var SUITE_PREFIX = '$';
|
||||
|
||||
/**
|
||||
* Expose `Markdown`.
|
||||
*/
|
||||
|
||||
exports = module.exports = Markdown;
|
||||
|
||||
/**
|
||||
* Constructs a new `Markdown` reporter instance.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner - Instance triggers reporter actions.
|
||||
* @param {Object} [options] - runner options
|
||||
*/
|
||||
function Markdown(runner, options) {
|
||||
Base.call(this, runner, options);
|
||||
|
||||
var level = 0;
|
||||
var buf = '';
|
||||
|
||||
function title(str) {
|
||||
return Array(level).join('#') + ' ' + str;
|
||||
}
|
||||
|
||||
function mapTOC(suite, obj) {
|
||||
var ret = obj;
|
||||
var key = SUITE_PREFIX + suite.title;
|
||||
|
||||
obj = obj[key] = obj[key] || {suite: suite};
|
||||
suite.suites.forEach(function(suite) {
|
||||
mapTOC(suite, obj);
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
function stringifyTOC(obj, level) {
|
||||
++level;
|
||||
var buf = '';
|
||||
var link;
|
||||
for (var key in obj) {
|
||||
if (key === 'suite') {
|
||||
continue;
|
||||
}
|
||||
if (key !== SUITE_PREFIX) {
|
||||
link = ' - [' + key.substring(1) + ']';
|
||||
link += '(#' + utils.slug(obj[key].suite.fullTitle()) + ')\n';
|
||||
buf += Array(level).join(' ') + link;
|
||||
}
|
||||
buf += stringifyTOC(obj[key], level);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
function generateTOC(suite) {
|
||||
var obj = mapTOC(suite, {});
|
||||
return stringifyTOC(obj, 0);
|
||||
}
|
||||
|
||||
generateTOC(runner.suite);
|
||||
|
||||
runner.on(EVENT_SUITE_BEGIN, function(suite) {
|
||||
++level;
|
||||
var slug = utils.slug(suite.fullTitle());
|
||||
buf += '<a name="' + slug + '"></a>' + '\n';
|
||||
buf += title(suite.title) + '\n';
|
||||
});
|
||||
|
||||
runner.on(EVENT_SUITE_END, function() {
|
||||
--level;
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function(test) {
|
||||
var code = utils.clean(test.body);
|
||||
buf += test.title + '.\n';
|
||||
buf += '\n```js\n';
|
||||
buf += code + '\n';
|
||||
buf += '```\n\n';
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_END, function() {
|
||||
process.stdout.write('# TOC\n');
|
||||
process.stdout.write(generateTOC(runner.suite));
|
||||
process.stdout.write(buf);
|
||||
});
|
||||
}
|
||||
|
||||
Markdown.description = 'GitHub Flavored Markdown';
|
||||
52
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/min.js
generated
vendored
Normal file
52
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/min.js
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module Min
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var inherits = require('../utils').inherits;
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
||||
|
||||
/**
|
||||
* Expose `Min`.
|
||||
*/
|
||||
|
||||
exports = module.exports = Min;
|
||||
|
||||
/**
|
||||
* Constructs a new `Min` reporter instance.
|
||||
*
|
||||
* @description
|
||||
* This minimal test reporter is best used with '--watch'.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner - Instance triggers reporter actions.
|
||||
* @param {Object} [options] - runner options
|
||||
*/
|
||||
function Min(runner, options) {
|
||||
Base.call(this, runner, options);
|
||||
|
||||
runner.on(EVENT_RUN_BEGIN, function() {
|
||||
// clear screen
|
||||
process.stdout.write('\u001b[2J');
|
||||
// set cursor position
|
||||
process.stdout.write('\u001b[1;3H');
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_END, this.epilogue.bind(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Base.prototype`.
|
||||
*/
|
||||
inherits(Min, Base);
|
||||
|
||||
Min.description = 'essentially just a summary';
|
||||
276
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/nyan.js
generated
vendored
Normal file
276
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/nyan.js
generated
vendored
Normal file
@ -0,0 +1,276 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module Nyan
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var constants = require('../runner').constants;
|
||||
var inherits = require('../utils').inherits;
|
||||
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
||||
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
|
||||
/**
|
||||
* Expose `Dot`.
|
||||
*/
|
||||
|
||||
exports = module.exports = NyanCat;
|
||||
|
||||
/**
|
||||
* Constructs a new `Nyan` reporter instance.
|
||||
*
|
||||
* @public
|
||||
* @class Nyan
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner - Instance triggers reporter actions.
|
||||
* @param {Object} [options] - runner options
|
||||
*/
|
||||
function NyanCat(runner, options) {
|
||||
Base.call(this, runner, options);
|
||||
|
||||
var self = this;
|
||||
var width = (Base.window.width * 0.75) | 0;
|
||||
var nyanCatWidth = (this.nyanCatWidth = 11);
|
||||
|
||||
this.colorIndex = 0;
|
||||
this.numberOfLines = 4;
|
||||
this.rainbowColors = self.generateColors();
|
||||
this.scoreboardWidth = 5;
|
||||
this.tick = 0;
|
||||
this.trajectories = [[], [], [], []];
|
||||
this.trajectoryWidthMax = width - nyanCatWidth;
|
||||
|
||||
runner.on(EVENT_RUN_BEGIN, function() {
|
||||
Base.cursor.hide();
|
||||
self.draw();
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PENDING, function() {
|
||||
self.draw();
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function() {
|
||||
self.draw();
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function() {
|
||||
self.draw();
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_END, function() {
|
||||
Base.cursor.show();
|
||||
for (var i = 0; i < self.numberOfLines; i++) {
|
||||
write('\n');
|
||||
}
|
||||
self.epilogue();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Base.prototype`.
|
||||
*/
|
||||
inherits(NyanCat, Base);
|
||||
|
||||
/**
|
||||
* Draw the nyan cat
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
|
||||
NyanCat.prototype.draw = function() {
|
||||
this.appendRainbow();
|
||||
this.drawScoreboard();
|
||||
this.drawRainbow();
|
||||
this.drawNyanCat();
|
||||
this.tick = !this.tick;
|
||||
};
|
||||
|
||||
/**
|
||||
* Draw the "scoreboard" showing the number
|
||||
* of passes, failures and pending tests.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
|
||||
NyanCat.prototype.drawScoreboard = function() {
|
||||
var stats = this.stats;
|
||||
|
||||
function draw(type, n) {
|
||||
write(' ');
|
||||
write(Base.color(type, n));
|
||||
write('\n');
|
||||
}
|
||||
|
||||
draw('green', stats.passes);
|
||||
draw('fail', stats.failures);
|
||||
draw('pending', stats.pending);
|
||||
write('\n');
|
||||
|
||||
this.cursorUp(this.numberOfLines);
|
||||
};
|
||||
|
||||
/**
|
||||
* Append the rainbow.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
|
||||
NyanCat.prototype.appendRainbow = function() {
|
||||
var segment = this.tick ? '_' : '-';
|
||||
var rainbowified = this.rainbowify(segment);
|
||||
|
||||
for (var index = 0; index < this.numberOfLines; index++) {
|
||||
var trajectory = this.trajectories[index];
|
||||
if (trajectory.length >= this.trajectoryWidthMax) {
|
||||
trajectory.shift();
|
||||
}
|
||||
trajectory.push(rainbowified);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Draw the rainbow.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
|
||||
NyanCat.prototype.drawRainbow = function() {
|
||||
var self = this;
|
||||
|
||||
this.trajectories.forEach(function(line) {
|
||||
write('\u001b[' + self.scoreboardWidth + 'C');
|
||||
write(line.join(''));
|
||||
write('\n');
|
||||
});
|
||||
|
||||
this.cursorUp(this.numberOfLines);
|
||||
};
|
||||
|
||||
/**
|
||||
* Draw the nyan cat
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
NyanCat.prototype.drawNyanCat = function() {
|
||||
var self = this;
|
||||
var startWidth = this.scoreboardWidth + this.trajectories[0].length;
|
||||
var dist = '\u001b[' + startWidth + 'C';
|
||||
var padding = '';
|
||||
|
||||
write(dist);
|
||||
write('_,------,');
|
||||
write('\n');
|
||||
|
||||
write(dist);
|
||||
padding = self.tick ? ' ' : ' ';
|
||||
write('_|' + padding + '/\\_/\\ ');
|
||||
write('\n');
|
||||
|
||||
write(dist);
|
||||
padding = self.tick ? '_' : '__';
|
||||
var tail = self.tick ? '~' : '^';
|
||||
write(tail + '|' + padding + this.face() + ' ');
|
||||
write('\n');
|
||||
|
||||
write(dist);
|
||||
padding = self.tick ? ' ' : ' ';
|
||||
write(padding + '"" "" ');
|
||||
write('\n');
|
||||
|
||||
this.cursorUp(this.numberOfLines);
|
||||
};
|
||||
|
||||
/**
|
||||
* Draw nyan cat face.
|
||||
*
|
||||
* @private
|
||||
* @return {string}
|
||||
*/
|
||||
|
||||
NyanCat.prototype.face = function() {
|
||||
var stats = this.stats;
|
||||
if (stats.failures) {
|
||||
return '( x .x)';
|
||||
} else if (stats.pending) {
|
||||
return '( o .o)';
|
||||
} else if (stats.passes) {
|
||||
return '( ^ .^)';
|
||||
}
|
||||
return '( - .-)';
|
||||
};
|
||||
|
||||
/**
|
||||
* Move cursor up `n`.
|
||||
*
|
||||
* @private
|
||||
* @param {number} n
|
||||
*/
|
||||
|
||||
NyanCat.prototype.cursorUp = function(n) {
|
||||
write('\u001b[' + n + 'A');
|
||||
};
|
||||
|
||||
/**
|
||||
* Move cursor down `n`.
|
||||
*
|
||||
* @private
|
||||
* @param {number} n
|
||||
*/
|
||||
|
||||
NyanCat.prototype.cursorDown = function(n) {
|
||||
write('\u001b[' + n + 'B');
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate rainbow colors.
|
||||
*
|
||||
* @private
|
||||
* @return {Array}
|
||||
*/
|
||||
NyanCat.prototype.generateColors = function() {
|
||||
var colors = [];
|
||||
|
||||
for (var i = 0; i < 6 * 7; i++) {
|
||||
var pi3 = Math.floor(Math.PI / 3);
|
||||
var n = i * (1.0 / 6);
|
||||
var r = Math.floor(3 * Math.sin(n) + 3);
|
||||
var g = Math.floor(3 * Math.sin(n + 2 * pi3) + 3);
|
||||
var b = Math.floor(3 * Math.sin(n + 4 * pi3) + 3);
|
||||
colors.push(36 * r + 6 * g + b + 16);
|
||||
}
|
||||
|
||||
return colors;
|
||||
};
|
||||
|
||||
/**
|
||||
* Apply rainbow to the given `str`.
|
||||
*
|
||||
* @private
|
||||
* @param {string} str
|
||||
* @return {string}
|
||||
*/
|
||||
NyanCat.prototype.rainbowify = function(str) {
|
||||
if (!Base.useColors) {
|
||||
return str;
|
||||
}
|
||||
var color = this.rainbowColors[this.colorIndex % this.rainbowColors.length];
|
||||
this.colorIndex += 1;
|
||||
return '\u001b[38;5;' + color + 'm' + str + '\u001b[0m';
|
||||
};
|
||||
|
||||
/**
|
||||
* Stdout helper.
|
||||
*
|
||||
* @param {string} string A message to write to stdout.
|
||||
*/
|
||||
function write(string) {
|
||||
process.stdout.write(string);
|
||||
}
|
||||
|
||||
NyanCat.description = '"nyan cat"';
|
||||
104
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/progress.js
generated
vendored
Normal file
104
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/progress.js
generated
vendored
Normal file
@ -0,0 +1,104 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module Progress
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
||||
var EVENT_TEST_END = constants.EVENT_TEST_END;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
var inherits = require('../utils').inherits;
|
||||
var color = Base.color;
|
||||
var cursor = Base.cursor;
|
||||
|
||||
/**
|
||||
* Expose `Progress`.
|
||||
*/
|
||||
|
||||
exports = module.exports = Progress;
|
||||
|
||||
/**
|
||||
* General progress bar color.
|
||||
*/
|
||||
|
||||
Base.colors.progress = 90;
|
||||
|
||||
/**
|
||||
* Constructs a new `Progress` reporter instance.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner - Instance triggers reporter actions.
|
||||
* @param {Object} [options] - runner options
|
||||
*/
|
||||
function Progress(runner, options) {
|
||||
Base.call(this, runner, options);
|
||||
|
||||
var self = this;
|
||||
var width = (Base.window.width * 0.5) | 0;
|
||||
var total = runner.total;
|
||||
var complete = 0;
|
||||
var lastN = -1;
|
||||
|
||||
// default chars
|
||||
options = options || {};
|
||||
var reporterOptions = options.reporterOptions || {};
|
||||
|
||||
options.open = reporterOptions.open || '[';
|
||||
options.complete = reporterOptions.complete || '▬';
|
||||
options.incomplete = reporterOptions.incomplete || Base.symbols.dot;
|
||||
options.close = reporterOptions.close || ']';
|
||||
options.verbose = reporterOptions.verbose || false;
|
||||
|
||||
// tests started
|
||||
runner.on(EVENT_RUN_BEGIN, function() {
|
||||
process.stdout.write('\n');
|
||||
cursor.hide();
|
||||
});
|
||||
|
||||
// tests complete
|
||||
runner.on(EVENT_TEST_END, function() {
|
||||
complete++;
|
||||
|
||||
var percent = complete / total;
|
||||
var n = (width * percent) | 0;
|
||||
var i = width - n;
|
||||
|
||||
if (n === lastN && !options.verbose) {
|
||||
// Don't re-render the line if it hasn't changed
|
||||
return;
|
||||
}
|
||||
lastN = n;
|
||||
|
||||
cursor.CR();
|
||||
process.stdout.write('\u001b[J');
|
||||
process.stdout.write(color('progress', ' ' + options.open));
|
||||
process.stdout.write(Array(n).join(options.complete));
|
||||
process.stdout.write(Array(i).join(options.incomplete));
|
||||
process.stdout.write(color('progress', options.close));
|
||||
if (options.verbose) {
|
||||
process.stdout.write(color('progress', ' ' + complete + ' of ' + total));
|
||||
}
|
||||
});
|
||||
|
||||
// tests are complete, output some stats
|
||||
// and the failures if any
|
||||
runner.once(EVENT_RUN_END, function() {
|
||||
cursor.show();
|
||||
process.stdout.write('\n');
|
||||
self.epilogue();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Base.prototype`.
|
||||
*/
|
||||
inherits(Progress, Base);
|
||||
|
||||
Progress.description = 'a progress bar';
|
||||
99
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/spec.js
generated
vendored
Normal file
99
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/spec.js
generated
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module Spec
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
var EVENT_SUITE_BEGIN = constants.EVENT_SUITE_BEGIN;
|
||||
var EVENT_SUITE_END = constants.EVENT_SUITE_END;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
||||
var inherits = require('../utils').inherits;
|
||||
var color = Base.color;
|
||||
|
||||
/**
|
||||
* Expose `Spec`.
|
||||
*/
|
||||
|
||||
exports = module.exports = Spec;
|
||||
|
||||
/**
|
||||
* Constructs a new `Spec` reporter instance.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner - Instance triggers reporter actions.
|
||||
* @param {Object} [options] - runner options
|
||||
*/
|
||||
function Spec(runner, options) {
|
||||
Base.call(this, runner, options);
|
||||
|
||||
var self = this;
|
||||
var indents = 0;
|
||||
var n = 0;
|
||||
|
||||
function indent() {
|
||||
return Array(indents).join(' ');
|
||||
}
|
||||
|
||||
runner.on(EVENT_RUN_BEGIN, function() {
|
||||
Base.consoleLog();
|
||||
});
|
||||
|
||||
runner.on(EVENT_SUITE_BEGIN, function(suite) {
|
||||
++indents;
|
||||
Base.consoleLog(color('suite', '%s%s'), indent(), suite.title);
|
||||
});
|
||||
|
||||
runner.on(EVENT_SUITE_END, function() {
|
||||
--indents;
|
||||
if (indents === 1) {
|
||||
Base.consoleLog();
|
||||
}
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PENDING, function(test) {
|
||||
var fmt = indent() + color('pending', ' - %s');
|
||||
Base.consoleLog(fmt, test.title);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function(test) {
|
||||
var fmt;
|
||||
if (test.speed === 'fast') {
|
||||
fmt =
|
||||
indent() +
|
||||
color('checkmark', ' ' + Base.symbols.ok) +
|
||||
color('pass', ' %s');
|
||||
Base.consoleLog(fmt, test.title);
|
||||
} else {
|
||||
fmt =
|
||||
indent() +
|
||||
color('checkmark', ' ' + Base.symbols.ok) +
|
||||
color('pass', ' %s') +
|
||||
color(test.speed, ' (%dms)');
|
||||
Base.consoleLog(fmt, test.title, test.duration);
|
||||
}
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function(test) {
|
||||
Base.consoleLog(indent() + color('fail', ' %d) %s'), ++n, test.title);
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_END, self.epilogue.bind(self));
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Base.prototype`.
|
||||
*/
|
||||
inherits(Spec, Base);
|
||||
|
||||
Spec.description = 'hierarchical & verbose [default]';
|
||||
293
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/tap.js
generated
vendored
Normal file
293
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/tap.js
generated
vendored
Normal file
@ -0,0 +1,293 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module TAP
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var util = require('util');
|
||||
var Base = require('./base');
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
||||
var EVENT_TEST_END = constants.EVENT_TEST_END;
|
||||
var inherits = require('../utils').inherits;
|
||||
var sprintf = util.format;
|
||||
|
||||
/**
|
||||
* Expose `TAP`.
|
||||
*/
|
||||
|
||||
exports = module.exports = TAP;
|
||||
|
||||
/**
|
||||
* Constructs a new `TAP` reporter instance.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner - Instance triggers reporter actions.
|
||||
* @param {Object} [options] - runner options
|
||||
*/
|
||||
function TAP(runner, options) {
|
||||
Base.call(this, runner, options);
|
||||
|
||||
var self = this;
|
||||
var n = 1;
|
||||
|
||||
var tapVersion = '12';
|
||||
if (options && options.reporterOptions) {
|
||||
if (options.reporterOptions.tapVersion) {
|
||||
tapVersion = options.reporterOptions.tapVersion.toString();
|
||||
}
|
||||
}
|
||||
|
||||
this._producer = createProducer(tapVersion);
|
||||
|
||||
runner.once(EVENT_RUN_BEGIN, function() {
|
||||
self._producer.writeVersion();
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_END, function() {
|
||||
++n;
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PENDING, function(test) {
|
||||
self._producer.writePending(n, test);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function(test) {
|
||||
self._producer.writePass(n, test);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function(test, err) {
|
||||
self._producer.writeFail(n, test, err);
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_END, function() {
|
||||
self._producer.writeEpilogue(runner.stats);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Base.prototype`.
|
||||
*/
|
||||
inherits(TAP, Base);
|
||||
|
||||
/**
|
||||
* Returns a TAP-safe title of `test`.
|
||||
*
|
||||
* @private
|
||||
* @param {Test} test - Test instance.
|
||||
* @return {String} title with any hash character removed
|
||||
*/
|
||||
function title(test) {
|
||||
return test.fullTitle().replace(/#/g, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes newline-terminated formatted string to reporter output stream.
|
||||
*
|
||||
* @private
|
||||
* @param {string} format - `printf`-like format string
|
||||
* @param {...*} [varArgs] - Format string arguments
|
||||
*/
|
||||
function println(format, varArgs) {
|
||||
var vargs = Array.from(arguments);
|
||||
vargs[0] += '\n';
|
||||
process.stdout.write(sprintf.apply(null, vargs));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a `tapVersion`-appropriate TAP producer instance, if possible.
|
||||
*
|
||||
* @private
|
||||
* @param {string} tapVersion - Version of TAP specification to produce.
|
||||
* @returns {TAPProducer} specification-appropriate instance
|
||||
* @throws {Error} if specification version has no associated producer.
|
||||
*/
|
||||
function createProducer(tapVersion) {
|
||||
var producers = {
|
||||
'12': new TAP12Producer(),
|
||||
'13': new TAP13Producer()
|
||||
};
|
||||
var producer = producers[tapVersion];
|
||||
|
||||
if (!producer) {
|
||||
throw new Error(
|
||||
'invalid or unsupported TAP version: ' + JSON.stringify(tapVersion)
|
||||
);
|
||||
}
|
||||
|
||||
return producer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @summary
|
||||
* Constructs a new TAPProducer.
|
||||
*
|
||||
* @description
|
||||
* <em>Only</em> to be used as an abstract base class.
|
||||
*
|
||||
* @private
|
||||
* @constructor
|
||||
*/
|
||||
function TAPProducer() {}
|
||||
|
||||
/**
|
||||
* Writes the TAP version to reporter output stream.
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
TAPProducer.prototype.writeVersion = function() {};
|
||||
|
||||
/**
|
||||
* Writes the plan to reporter output stream.
|
||||
*
|
||||
* @abstract
|
||||
* @param {number} ntests - Number of tests that are planned to run.
|
||||
*/
|
||||
TAPProducer.prototype.writePlan = function(ntests) {
|
||||
println('%d..%d', 1, ntests);
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes that test passed to reporter output stream.
|
||||
*
|
||||
* @abstract
|
||||
* @param {number} n - Index of test that passed.
|
||||
* @param {Test} test - Instance containing test information.
|
||||
*/
|
||||
TAPProducer.prototype.writePass = function(n, test) {
|
||||
println('ok %d %s', n, title(test));
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes that test was skipped to reporter output stream.
|
||||
*
|
||||
* @abstract
|
||||
* @param {number} n - Index of test that was skipped.
|
||||
* @param {Test} test - Instance containing test information.
|
||||
*/
|
||||
TAPProducer.prototype.writePending = function(n, test) {
|
||||
println('ok %d %s # SKIP -', n, title(test));
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes that test failed to reporter output stream.
|
||||
*
|
||||
* @abstract
|
||||
* @param {number} n - Index of test that failed.
|
||||
* @param {Test} test - Instance containing test information.
|
||||
* @param {Error} err - Reason the test failed.
|
||||
*/
|
||||
TAPProducer.prototype.writeFail = function(n, test, err) {
|
||||
println('not ok %d %s', n, title(test));
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes the summary epilogue to reporter output stream.
|
||||
*
|
||||
* @abstract
|
||||
* @param {Object} stats - Object containing run statistics.
|
||||
*/
|
||||
TAPProducer.prototype.writeEpilogue = function(stats) {
|
||||
// :TBD: Why is this not counting pending tests?
|
||||
println('# tests ' + (stats.passes + stats.failures));
|
||||
println('# pass ' + stats.passes);
|
||||
// :TBD: Why are we not showing pending results?
|
||||
println('# fail ' + stats.failures);
|
||||
this.writePlan(stats.passes + stats.failures + stats.pending);
|
||||
};
|
||||
|
||||
/**
|
||||
* @summary
|
||||
* Constructs a new TAP12Producer.
|
||||
*
|
||||
* @description
|
||||
* Produces output conforming to the TAP12 specification.
|
||||
*
|
||||
* @private
|
||||
* @constructor
|
||||
* @extends TAPProducer
|
||||
* @see {@link https://testanything.org/tap-specification.html|Specification}
|
||||
*/
|
||||
function TAP12Producer() {
|
||||
/**
|
||||
* Writes that test failed to reporter output stream, with error formatting.
|
||||
* @override
|
||||
*/
|
||||
this.writeFail = function(n, test, err) {
|
||||
TAPProducer.prototype.writeFail.call(this, n, test, err);
|
||||
if (err.message) {
|
||||
println(err.message.replace(/^/gm, ' '));
|
||||
}
|
||||
if (err.stack) {
|
||||
println(err.stack.replace(/^/gm, ' '));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `TAPProducer.prototype`.
|
||||
*/
|
||||
inherits(TAP12Producer, TAPProducer);
|
||||
|
||||
/**
|
||||
* @summary
|
||||
* Constructs a new TAP13Producer.
|
||||
*
|
||||
* @description
|
||||
* Produces output conforming to the TAP13 specification.
|
||||
*
|
||||
* @private
|
||||
* @constructor
|
||||
* @extends TAPProducer
|
||||
* @see {@link https://testanything.org/tap-version-13-specification.html|Specification}
|
||||
*/
|
||||
function TAP13Producer() {
|
||||
/**
|
||||
* Writes the TAP version to reporter output stream.
|
||||
* @override
|
||||
*/
|
||||
this.writeVersion = function() {
|
||||
println('TAP version 13');
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes that test failed to reporter output stream, with error formatting.
|
||||
* @override
|
||||
*/
|
||||
this.writeFail = function(n, test, err) {
|
||||
TAPProducer.prototype.writeFail.call(this, n, test, err);
|
||||
var emitYamlBlock = err.message != null || err.stack != null;
|
||||
if (emitYamlBlock) {
|
||||
println(indent(1) + '---');
|
||||
if (err.message) {
|
||||
println(indent(2) + 'message: |-');
|
||||
println(err.message.replace(/^/gm, indent(3)));
|
||||
}
|
||||
if (err.stack) {
|
||||
println(indent(2) + 'stack: |-');
|
||||
println(err.stack.replace(/^/gm, indent(3)));
|
||||
}
|
||||
println(indent(1) + '...');
|
||||
}
|
||||
};
|
||||
|
||||
function indent(level) {
|
||||
return Array(level + 1).join(' ');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `TAPProducer.prototype`.
|
||||
*/
|
||||
inherits(TAP13Producer, TAPProducer);
|
||||
|
||||
TAP.description = 'TAP-compatible output';
|
||||
217
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/xunit.js
generated
vendored
Normal file
217
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/reporters/xunit.js
generated
vendored
Normal file
@ -0,0 +1,217 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module XUnit
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var utils = require('../utils');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var errors = require('../errors');
|
||||
var createUnsupportedError = errors.createUnsupportedError;
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
||||
var STATE_FAILED = require('../runnable').constants.STATE_FAILED;
|
||||
var inherits = utils.inherits;
|
||||
var escape = utils.escape;
|
||||
|
||||
/**
|
||||
* Save timer references to avoid Sinon interfering (see GH-237).
|
||||
*/
|
||||
var Date = global.Date;
|
||||
|
||||
/**
|
||||
* Expose `XUnit`.
|
||||
*/
|
||||
|
||||
exports = module.exports = XUnit;
|
||||
|
||||
/**
|
||||
* Constructs a new `XUnit` reporter instance.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner - Instance triggers reporter actions.
|
||||
* @param {Object} [options] - runner options
|
||||
*/
|
||||
function XUnit(runner, options) {
|
||||
Base.call(this, runner, options);
|
||||
|
||||
var stats = this.stats;
|
||||
var tests = [];
|
||||
var self = this;
|
||||
|
||||
// the name of the test suite, as it will appear in the resulting XML file
|
||||
var suiteName;
|
||||
|
||||
// the default name of the test suite if none is provided
|
||||
var DEFAULT_SUITE_NAME = 'Mocha Tests';
|
||||
|
||||
if (options && options.reporterOptions) {
|
||||
if (options.reporterOptions.output) {
|
||||
if (!fs.createWriteStream) {
|
||||
throw createUnsupportedError('file output not supported in browser');
|
||||
}
|
||||
|
||||
fs.mkdirSync(path.dirname(options.reporterOptions.output), {
|
||||
recursive: true
|
||||
});
|
||||
self.fileStream = fs.createWriteStream(options.reporterOptions.output);
|
||||
}
|
||||
|
||||
// get the suite name from the reporter options (if provided)
|
||||
suiteName = options.reporterOptions.suiteName;
|
||||
}
|
||||
|
||||
// fall back to the default suite name
|
||||
suiteName = suiteName || DEFAULT_SUITE_NAME;
|
||||
|
||||
runner.on(EVENT_TEST_PENDING, function(test) {
|
||||
tests.push(test);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function(test) {
|
||||
tests.push(test);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function(test) {
|
||||
tests.push(test);
|
||||
});
|
||||
|
||||
runner.once(EVENT_RUN_END, function() {
|
||||
self.write(
|
||||
tag(
|
||||
'testsuite',
|
||||
{
|
||||
name: suiteName,
|
||||
tests: stats.tests,
|
||||
failures: 0,
|
||||
errors: stats.failures,
|
||||
skipped: stats.tests - stats.failures - stats.passes,
|
||||
timestamp: new Date().toUTCString(),
|
||||
time: stats.duration / 1000 || 0
|
||||
},
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
tests.forEach(function(t) {
|
||||
self.test(t);
|
||||
});
|
||||
|
||||
self.write('</testsuite>');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Base.prototype`.
|
||||
*/
|
||||
inherits(XUnit, Base);
|
||||
|
||||
/**
|
||||
* Override done to close the stream (if it's a file).
|
||||
*
|
||||
* @param failures
|
||||
* @param {Function} fn
|
||||
*/
|
||||
XUnit.prototype.done = function(failures, fn) {
|
||||
if (this.fileStream) {
|
||||
this.fileStream.end(function() {
|
||||
fn(failures);
|
||||
});
|
||||
} else {
|
||||
fn(failures);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Write out the given line.
|
||||
*
|
||||
* @param {string} line
|
||||
*/
|
||||
XUnit.prototype.write = function(line) {
|
||||
if (this.fileStream) {
|
||||
this.fileStream.write(line + '\n');
|
||||
} else if (typeof process === 'object' && process.stdout) {
|
||||
process.stdout.write(line + '\n');
|
||||
} else {
|
||||
Base.consoleLog(line);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Output tag for the given `test.`
|
||||
*
|
||||
* @param {Test} test
|
||||
*/
|
||||
XUnit.prototype.test = function(test) {
|
||||
Base.useColors = false;
|
||||
|
||||
var attrs = {
|
||||
classname: test.parent.fullTitle(),
|
||||
name: test.title,
|
||||
time: test.duration / 1000 || 0
|
||||
};
|
||||
|
||||
if (test.state === STATE_FAILED) {
|
||||
var err = test.err;
|
||||
var diff =
|
||||
!Base.hideDiff && Base.showDiff(err)
|
||||
? '\n' + Base.generateDiff(err.actual, err.expected)
|
||||
: '';
|
||||
this.write(
|
||||
tag(
|
||||
'testcase',
|
||||
attrs,
|
||||
false,
|
||||
tag(
|
||||
'failure',
|
||||
{},
|
||||
false,
|
||||
escape(err.message) + escape(diff) + '\n' + escape(err.stack)
|
||||
)
|
||||
)
|
||||
);
|
||||
} else if (test.isPending()) {
|
||||
this.write(tag('testcase', attrs, false, tag('skipped', {}, true)));
|
||||
} else {
|
||||
this.write(tag('testcase', attrs, true));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* HTML tag helper.
|
||||
*
|
||||
* @param name
|
||||
* @param attrs
|
||||
* @param close
|
||||
* @param content
|
||||
* @return {string}
|
||||
*/
|
||||
function tag(name, attrs, close, content) {
|
||||
var end = close ? '/>' : '>';
|
||||
var pairs = [];
|
||||
var tag;
|
||||
|
||||
for (var key in attrs) {
|
||||
if (Object.prototype.hasOwnProperty.call(attrs, key)) {
|
||||
pairs.push(key + '="' + escape(attrs[key]) + '"');
|
||||
}
|
||||
}
|
||||
|
||||
tag = '<' + name + (pairs.length ? ' ' + pairs.join(' ') : '') + end;
|
||||
if (content) {
|
||||
tag += content + '</' + name + end;
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
XUnit.description = 'XUnit-compatible XML output';
|
||||
476
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/runnable.js
generated
vendored
Normal file
476
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/runnable.js
generated
vendored
Normal file
@ -0,0 +1,476 @@
|
||||
'use strict';
|
||||
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var Pending = require('./pending');
|
||||
var debug = require('debug')('mocha:runnable');
|
||||
var milliseconds = require('ms');
|
||||
var utils = require('./utils');
|
||||
const {
|
||||
createInvalidExceptionError,
|
||||
createMultipleDoneError,
|
||||
createTimeoutError
|
||||
} = require('./errors');
|
||||
|
||||
/**
|
||||
* Save timer references to avoid Sinon interfering (see GH-237).
|
||||
* @private
|
||||
*/
|
||||
var Date = global.Date;
|
||||
var setTimeout = global.setTimeout;
|
||||
var clearTimeout = global.clearTimeout;
|
||||
var toString = Object.prototype.toString;
|
||||
|
||||
module.exports = Runnable;
|
||||
|
||||
/**
|
||||
* Initialize a new `Runnable` with the given `title` and callback `fn`.
|
||||
*
|
||||
* @class
|
||||
* @extends external:EventEmitter
|
||||
* @public
|
||||
* @param {String} title
|
||||
* @param {Function} fn
|
||||
*/
|
||||
function Runnable(title, fn) {
|
||||
this.title = title;
|
||||
this.fn = fn;
|
||||
this.body = (fn || '').toString();
|
||||
this.async = fn && fn.length;
|
||||
this.sync = !this.async;
|
||||
this._timeout = 2000;
|
||||
this._slow = 75;
|
||||
this._retries = -1;
|
||||
utils.assignNewMochaID(this);
|
||||
Object.defineProperty(this, 'id', {
|
||||
get() {
|
||||
return utils.getMochaID(this);
|
||||
}
|
||||
});
|
||||
this.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `EventEmitter.prototype`.
|
||||
*/
|
||||
utils.inherits(Runnable, EventEmitter);
|
||||
|
||||
/**
|
||||
* Resets the state initially or for a next run.
|
||||
*/
|
||||
Runnable.prototype.reset = function() {
|
||||
this.timedOut = false;
|
||||
this._currentRetry = 0;
|
||||
this.pending = false;
|
||||
delete this.state;
|
||||
delete this.err;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get current timeout value in msecs.
|
||||
*
|
||||
* @private
|
||||
* @returns {number} current timeout threshold value
|
||||
*/
|
||||
/**
|
||||
* @summary
|
||||
* Set timeout threshold value (msecs).
|
||||
*
|
||||
* @description
|
||||
* A string argument can use shorthand (e.g., "2s") and will be converted.
|
||||
* The value will be clamped to range [<code>0</code>, <code>2^<sup>31</sup>-1</code>].
|
||||
* If clamped value matches either range endpoint, timeouts will be disabled.
|
||||
*
|
||||
* @private
|
||||
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout#Maximum_delay_value}
|
||||
* @param {number|string} ms - Timeout threshold value.
|
||||
* @returns {Runnable} this
|
||||
* @chainable
|
||||
*/
|
||||
Runnable.prototype.timeout = function(ms) {
|
||||
if (!arguments.length) {
|
||||
return this._timeout;
|
||||
}
|
||||
if (typeof ms === 'string') {
|
||||
ms = milliseconds(ms);
|
||||
}
|
||||
|
||||
// Clamp to range
|
||||
var INT_MAX = Math.pow(2, 31) - 1;
|
||||
var range = [0, INT_MAX];
|
||||
ms = utils.clamp(ms, range);
|
||||
|
||||
// see #1652 for reasoning
|
||||
if (ms === range[0] || ms === range[1]) {
|
||||
this._timeout = 0;
|
||||
} else {
|
||||
this._timeout = ms;
|
||||
}
|
||||
debug('timeout %d', this._timeout);
|
||||
|
||||
if (this.timer) {
|
||||
this.resetTimeout();
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set or get slow `ms`.
|
||||
*
|
||||
* @private
|
||||
* @param {number|string} ms
|
||||
* @return {Runnable|number} ms or Runnable instance.
|
||||
*/
|
||||
Runnable.prototype.slow = function(ms) {
|
||||
if (!arguments.length || typeof ms === 'undefined') {
|
||||
return this._slow;
|
||||
}
|
||||
if (typeof ms === 'string') {
|
||||
ms = milliseconds(ms);
|
||||
}
|
||||
debug('slow %d', ms);
|
||||
this._slow = ms;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Halt and mark as pending.
|
||||
*
|
||||
* @memberof Mocha.Runnable
|
||||
* @public
|
||||
*/
|
||||
Runnable.prototype.skip = function() {
|
||||
this.pending = true;
|
||||
throw new Pending('sync skip; aborting execution');
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if this runnable or its parent suite is marked as pending.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
Runnable.prototype.isPending = function() {
|
||||
return this.pending || (this.parent && this.parent.isPending());
|
||||
};
|
||||
|
||||
/**
|
||||
* Return `true` if this Runnable has failed.
|
||||
* @return {boolean}
|
||||
* @private
|
||||
*/
|
||||
Runnable.prototype.isFailed = function() {
|
||||
return !this.isPending() && this.state === constants.STATE_FAILED;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return `true` if this Runnable has passed.
|
||||
* @return {boolean}
|
||||
* @private
|
||||
*/
|
||||
Runnable.prototype.isPassed = function() {
|
||||
return !this.isPending() && this.state === constants.STATE_PASSED;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set or get number of retries.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
Runnable.prototype.retries = function(n) {
|
||||
if (!arguments.length) {
|
||||
return this._retries;
|
||||
}
|
||||
this._retries = n;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set or get current retry
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
Runnable.prototype.currentRetry = function(n) {
|
||||
if (!arguments.length) {
|
||||
return this._currentRetry;
|
||||
}
|
||||
this._currentRetry = n;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the full title generated by recursively concatenating the parent's
|
||||
* full title.
|
||||
*
|
||||
* @memberof Mocha.Runnable
|
||||
* @public
|
||||
* @return {string}
|
||||
*/
|
||||
Runnable.prototype.fullTitle = function() {
|
||||
return this.titlePath().join(' ');
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the title path generated by concatenating the parent's title path with the title.
|
||||
*
|
||||
* @memberof Mocha.Runnable
|
||||
* @public
|
||||
* @return {string}
|
||||
*/
|
||||
Runnable.prototype.titlePath = function() {
|
||||
return this.parent.titlePath().concat([this.title]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear the timeout.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
Runnable.prototype.clearTimeout = function() {
|
||||
clearTimeout(this.timer);
|
||||
};
|
||||
|
||||
/**
|
||||
* Reset the timeout.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
Runnable.prototype.resetTimeout = function() {
|
||||
var self = this;
|
||||
var ms = this.timeout();
|
||||
|
||||
if (ms === 0) {
|
||||
return;
|
||||
}
|
||||
this.clearTimeout();
|
||||
this.timer = setTimeout(function() {
|
||||
if (self.timeout() === 0) {
|
||||
return;
|
||||
}
|
||||
self.callback(self._timeoutError(ms));
|
||||
self.timedOut = true;
|
||||
}, ms);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set or get a list of whitelisted globals for this test run.
|
||||
*
|
||||
* @private
|
||||
* @param {string[]} globals
|
||||
*/
|
||||
Runnable.prototype.globals = function(globals) {
|
||||
if (!arguments.length) {
|
||||
return this._allowedGlobals;
|
||||
}
|
||||
this._allowedGlobals = globals;
|
||||
};
|
||||
|
||||
/**
|
||||
* Run the test and invoke `fn(err)`.
|
||||
*
|
||||
* @param {Function} fn
|
||||
* @private
|
||||
*/
|
||||
Runnable.prototype.run = function(fn) {
|
||||
var self = this;
|
||||
var start = new Date();
|
||||
var ctx = this.ctx;
|
||||
var finished;
|
||||
var errorWasHandled = false;
|
||||
|
||||
if (this.isPending()) return fn();
|
||||
|
||||
// Sometimes the ctx exists, but it is not runnable
|
||||
if (ctx && ctx.runnable) {
|
||||
ctx.runnable(this);
|
||||
}
|
||||
|
||||
// called multiple times
|
||||
function multiple(err) {
|
||||
if (errorWasHandled) {
|
||||
return;
|
||||
}
|
||||
errorWasHandled = true;
|
||||
self.emit('error', createMultipleDoneError(self, err));
|
||||
}
|
||||
|
||||
// finished
|
||||
function done(err) {
|
||||
var ms = self.timeout();
|
||||
if (self.timedOut) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (finished) {
|
||||
return multiple(err);
|
||||
}
|
||||
|
||||
self.clearTimeout();
|
||||
self.duration = new Date() - start;
|
||||
finished = true;
|
||||
if (!err && self.duration > ms && ms > 0) {
|
||||
err = self._timeoutError(ms);
|
||||
}
|
||||
fn(err);
|
||||
}
|
||||
|
||||
// for .resetTimeout() and Runner#uncaught()
|
||||
this.callback = done;
|
||||
|
||||
if (this.fn && typeof this.fn.call !== 'function') {
|
||||
done(
|
||||
new TypeError(
|
||||
'A runnable must be passed a function as its second argument.'
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// explicit async with `done` argument
|
||||
if (this.async) {
|
||||
this.resetTimeout();
|
||||
|
||||
// allows skip() to be used in an explicit async context
|
||||
this.skip = function asyncSkip() {
|
||||
this.pending = true;
|
||||
done();
|
||||
// halt execution, the uncaught handler will ignore the failure.
|
||||
throw new Pending('async skip; aborting execution');
|
||||
};
|
||||
|
||||
try {
|
||||
callFnAsync(this.fn);
|
||||
} catch (err) {
|
||||
// handles async runnables which actually run synchronously
|
||||
errorWasHandled = true;
|
||||
if (err instanceof Pending) {
|
||||
return; // done() is already called in this.skip()
|
||||
} else if (this.allowUncaught) {
|
||||
throw err;
|
||||
}
|
||||
done(Runnable.toValueOrError(err));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// sync or promise-returning
|
||||
try {
|
||||
callFn(this.fn);
|
||||
} catch (err) {
|
||||
errorWasHandled = true;
|
||||
if (err instanceof Pending) {
|
||||
return done();
|
||||
} else if (this.allowUncaught) {
|
||||
throw err;
|
||||
}
|
||||
done(Runnable.toValueOrError(err));
|
||||
}
|
||||
|
||||
function callFn(fn) {
|
||||
var result = fn.call(ctx);
|
||||
if (result && typeof result.then === 'function') {
|
||||
self.resetTimeout();
|
||||
result.then(
|
||||
function() {
|
||||
done();
|
||||
// Return null so libraries like bluebird do not warn about
|
||||
// subsequently constructed Promises.
|
||||
return null;
|
||||
},
|
||||
function(reason) {
|
||||
done(reason || new Error('Promise rejected with no or falsy reason'));
|
||||
}
|
||||
);
|
||||
} else {
|
||||
if (self.asyncOnly) {
|
||||
return done(
|
||||
new Error(
|
||||
'--async-only option in use without declaring `done()` or returning a promise'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
done();
|
||||
}
|
||||
}
|
||||
|
||||
function callFnAsync(fn) {
|
||||
var result = fn.call(ctx, function(err) {
|
||||
if (err instanceof Error || toString.call(err) === '[object Error]') {
|
||||
return done(err);
|
||||
}
|
||||
if (err) {
|
||||
if (Object.prototype.toString.call(err) === '[object Object]') {
|
||||
return done(
|
||||
new Error('done() invoked with non-Error: ' + JSON.stringify(err))
|
||||
);
|
||||
}
|
||||
return done(new Error('done() invoked with non-Error: ' + err));
|
||||
}
|
||||
if (result && utils.isPromise(result)) {
|
||||
return done(
|
||||
new Error(
|
||||
'Resolution method is overspecified. Specify a callback *or* return a Promise; not both.'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Instantiates a "timeout" error
|
||||
*
|
||||
* @param {number} ms - Timeout (in milliseconds)
|
||||
* @returns {Error} a "timeout" error
|
||||
* @private
|
||||
*/
|
||||
Runnable.prototype._timeoutError = function(ms) {
|
||||
let msg = `Timeout of ${ms}ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.`;
|
||||
if (this.file) {
|
||||
msg += ' (' + this.file + ')';
|
||||
}
|
||||
return createTimeoutError(msg, ms, this.file);
|
||||
};
|
||||
|
||||
var constants = utils.defineConstants(
|
||||
/**
|
||||
* {@link Runnable}-related constants.
|
||||
* @public
|
||||
* @memberof Runnable
|
||||
* @readonly
|
||||
* @static
|
||||
* @alias constants
|
||||
* @enum {string}
|
||||
*/
|
||||
{
|
||||
/**
|
||||
* Value of `state` prop when a `Runnable` has failed
|
||||
*/
|
||||
STATE_FAILED: 'failed',
|
||||
/**
|
||||
* Value of `state` prop when a `Runnable` has passed
|
||||
*/
|
||||
STATE_PASSED: 'passed',
|
||||
/**
|
||||
* Value of `state` prop when a `Runnable` has been skipped by user
|
||||
*/
|
||||
STATE_PENDING: 'pending'
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Given `value`, return identity if truthy, otherwise create an "invalid exception" error and return that.
|
||||
* @param {*} [value] - Value to return, if present
|
||||
* @returns {*|Error} `value`, otherwise an `Error`
|
||||
* @private
|
||||
*/
|
||||
Runnable.toValueOrError = function(value) {
|
||||
return (
|
||||
value ||
|
||||
createInvalidExceptionError(
|
||||
'Runnable failed with falsy or undefined exception. Please throw an Error instead.',
|
||||
value
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
Runnable.constants = constants;
|
||||
1266
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/runner.js
generated
vendored
Normal file
1266
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/runner.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
83
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/stats-collector.js
generated
vendored
Normal file
83
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/stats-collector.js
generated
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Provides a factory function for a {@link StatsCollector} object.
|
||||
* @module
|
||||
*/
|
||||
|
||||
var constants = require('./runner').constants;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
var EVENT_SUITE_BEGIN = constants.EVENT_SUITE_BEGIN;
|
||||
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
||||
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
||||
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
||||
var EVENT_TEST_END = constants.EVENT_TEST_END;
|
||||
|
||||
/**
|
||||
* Test statistics collector.
|
||||
*
|
||||
* @public
|
||||
* @typedef {Object} StatsCollector
|
||||
* @property {number} suites - integer count of suites run.
|
||||
* @property {number} tests - integer count of tests run.
|
||||
* @property {number} passes - integer count of passing tests.
|
||||
* @property {number} pending - integer count of pending tests.
|
||||
* @property {number} failures - integer count of failed tests.
|
||||
* @property {Date} start - time when testing began.
|
||||
* @property {Date} end - time when testing concluded.
|
||||
* @property {number} duration - number of msecs that testing took.
|
||||
*/
|
||||
|
||||
var Date = global.Date;
|
||||
|
||||
/**
|
||||
* Provides stats such as test duration, number of tests passed / failed etc., by listening for events emitted by `runner`.
|
||||
*
|
||||
* @private
|
||||
* @param {Runner} runner - Runner instance
|
||||
* @throws {TypeError} If falsy `runner`
|
||||
*/
|
||||
function createStatsCollector(runner) {
|
||||
/**
|
||||
* @type StatsCollector
|
||||
*/
|
||||
var stats = {
|
||||
suites: 0,
|
||||
tests: 0,
|
||||
passes: 0,
|
||||
pending: 0,
|
||||
failures: 0
|
||||
};
|
||||
|
||||
if (!runner) {
|
||||
throw new TypeError('Missing runner argument');
|
||||
}
|
||||
|
||||
runner.stats = stats;
|
||||
|
||||
runner.once(EVENT_RUN_BEGIN, function() {
|
||||
stats.start = new Date();
|
||||
});
|
||||
runner.on(EVENT_SUITE_BEGIN, function(suite) {
|
||||
suite.root || stats.suites++;
|
||||
});
|
||||
runner.on(EVENT_TEST_PASS, function() {
|
||||
stats.passes++;
|
||||
});
|
||||
runner.on(EVENT_TEST_FAIL, function() {
|
||||
stats.failures++;
|
||||
});
|
||||
runner.on(EVENT_TEST_PENDING, function() {
|
||||
stats.pending++;
|
||||
});
|
||||
runner.on(EVENT_TEST_END, function() {
|
||||
stats.tests++;
|
||||
});
|
||||
runner.once(EVENT_RUN_END, function() {
|
||||
stats.end = new Date();
|
||||
stats.duration = stats.end - stats.start;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = createStatsCollector;
|
||||
695
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/suite.js
generated
vendored
Normal file
695
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/suite.js
generated
vendored
Normal file
@ -0,0 +1,695 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
* @private
|
||||
*/
|
||||
const {EventEmitter} = require('events');
|
||||
const Hook = require('./hook');
|
||||
var {
|
||||
assignNewMochaID,
|
||||
clamp,
|
||||
constants: utilsConstants,
|
||||
createMap,
|
||||
defineConstants,
|
||||
getMochaID,
|
||||
inherits,
|
||||
isString
|
||||
} = require('./utils');
|
||||
const debug = require('debug')('mocha:suite');
|
||||
const milliseconds = require('ms');
|
||||
const errors = require('./errors');
|
||||
|
||||
const {MOCHA_ID_PROP_NAME} = utilsConstants;
|
||||
|
||||
/**
|
||||
* Expose `Suite`.
|
||||
*/
|
||||
|
||||
exports = module.exports = Suite;
|
||||
|
||||
/**
|
||||
* Create a new `Suite` with the given `title` and parent `Suite`.
|
||||
*
|
||||
* @public
|
||||
* @param {Suite} parent - Parent suite (required!)
|
||||
* @param {string} title - Title
|
||||
* @return {Suite}
|
||||
*/
|
||||
Suite.create = function(parent, title) {
|
||||
var suite = new Suite(title, parent.ctx);
|
||||
suite.parent = parent;
|
||||
title = suite.fullTitle();
|
||||
parent.addSuite(suite);
|
||||
return suite;
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructs a new `Suite` instance with the given `title`, `ctx`, and `isRoot`.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @extends EventEmitter
|
||||
* @see {@link https://nodejs.org/api/events.html#events_class_eventemitter|EventEmitter}
|
||||
* @param {string} title - Suite title.
|
||||
* @param {Context} parentContext - Parent context instance.
|
||||
* @param {boolean} [isRoot=false] - Whether this is the root suite.
|
||||
*/
|
||||
function Suite(title, parentContext, isRoot) {
|
||||
if (!isString(title)) {
|
||||
throw errors.createInvalidArgumentTypeError(
|
||||
'Suite argument "title" must be a string. Received type "' +
|
||||
typeof title +
|
||||
'"',
|
||||
'title',
|
||||
'string'
|
||||
);
|
||||
}
|
||||
this.title = title;
|
||||
function Context() {}
|
||||
Context.prototype = parentContext;
|
||||
this.ctx = new Context();
|
||||
this.suites = [];
|
||||
this.tests = [];
|
||||
this.root = isRoot === true;
|
||||
this.pending = false;
|
||||
this._retries = -1;
|
||||
this._beforeEach = [];
|
||||
this._beforeAll = [];
|
||||
this._afterEach = [];
|
||||
this._afterAll = [];
|
||||
this._timeout = 2000;
|
||||
this._slow = 75;
|
||||
this._bail = false;
|
||||
this._onlyTests = [];
|
||||
this._onlySuites = [];
|
||||
assignNewMochaID(this);
|
||||
|
||||
Object.defineProperty(this, 'id', {
|
||||
get() {
|
||||
return getMochaID(this);
|
||||
}
|
||||
});
|
||||
|
||||
this.reset();
|
||||
|
||||
this.on('newListener', function(event) {
|
||||
if (deprecatedEvents[event]) {
|
||||
errors.deprecate(
|
||||
'Event "' +
|
||||
event +
|
||||
'" is deprecated. Please let the Mocha team know about your use case: https://git.io/v6Lwm'
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `EventEmitter.prototype`.
|
||||
*/
|
||||
inherits(Suite, EventEmitter);
|
||||
|
||||
/**
|
||||
* Resets the state initially or for a next run.
|
||||
*/
|
||||
Suite.prototype.reset = function() {
|
||||
this.delayed = false;
|
||||
function doReset(thingToReset) {
|
||||
thingToReset.reset();
|
||||
}
|
||||
this.suites.forEach(doReset);
|
||||
this.tests.forEach(doReset);
|
||||
this._beforeEach.forEach(doReset);
|
||||
this._afterEach.forEach(doReset);
|
||||
this._beforeAll.forEach(doReset);
|
||||
this._afterAll.forEach(doReset);
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a clone of this `Suite`.
|
||||
*
|
||||
* @private
|
||||
* @return {Suite}
|
||||
*/
|
||||
Suite.prototype.clone = function() {
|
||||
var suite = new Suite(this.title);
|
||||
debug('clone');
|
||||
suite.ctx = this.ctx;
|
||||
suite.root = this.root;
|
||||
suite.timeout(this.timeout());
|
||||
suite.retries(this.retries());
|
||||
suite.slow(this.slow());
|
||||
suite.bail(this.bail());
|
||||
return suite;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set or get timeout `ms` or short-hand such as "2s".
|
||||
*
|
||||
* @private
|
||||
* @todo Do not attempt to set value if `ms` is undefined
|
||||
* @param {number|string} ms
|
||||
* @return {Suite|number} for chaining
|
||||
*/
|
||||
Suite.prototype.timeout = function(ms) {
|
||||
if (!arguments.length) {
|
||||
return this._timeout;
|
||||
}
|
||||
if (typeof ms === 'string') {
|
||||
ms = milliseconds(ms);
|
||||
}
|
||||
|
||||
// Clamp to range
|
||||
var INT_MAX = Math.pow(2, 31) - 1;
|
||||
var range = [0, INT_MAX];
|
||||
ms = clamp(ms, range);
|
||||
|
||||
debug('timeout %d', ms);
|
||||
this._timeout = parseInt(ms, 10);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set or get number of times to retry a failed test.
|
||||
*
|
||||
* @private
|
||||
* @param {number|string} n
|
||||
* @return {Suite|number} for chaining
|
||||
*/
|
||||
Suite.prototype.retries = function(n) {
|
||||
if (!arguments.length) {
|
||||
return this._retries;
|
||||
}
|
||||
debug('retries %d', n);
|
||||
this._retries = parseInt(n, 10) || 0;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set or get slow `ms` or short-hand such as "2s".
|
||||
*
|
||||
* @private
|
||||
* @param {number|string} ms
|
||||
* @return {Suite|number} for chaining
|
||||
*/
|
||||
Suite.prototype.slow = function(ms) {
|
||||
if (!arguments.length) {
|
||||
return this._slow;
|
||||
}
|
||||
if (typeof ms === 'string') {
|
||||
ms = milliseconds(ms);
|
||||
}
|
||||
debug('slow %d', ms);
|
||||
this._slow = ms;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set or get whether to bail after first error.
|
||||
*
|
||||
* @private
|
||||
* @param {boolean} bail
|
||||
* @return {Suite|number} for chaining
|
||||
*/
|
||||
Suite.prototype.bail = function(bail) {
|
||||
if (!arguments.length) {
|
||||
return this._bail;
|
||||
}
|
||||
debug('bail %s', bail);
|
||||
this._bail = bail;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if this suite or its parent suite is marked as pending.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
Suite.prototype.isPending = function() {
|
||||
return this.pending || (this.parent && this.parent.isPending());
|
||||
};
|
||||
|
||||
/**
|
||||
* Generic hook-creator.
|
||||
* @private
|
||||
* @param {string} title - Title of hook
|
||||
* @param {Function} fn - Hook callback
|
||||
* @returns {Hook} A new hook
|
||||
*/
|
||||
Suite.prototype._createHook = function(title, fn) {
|
||||
var hook = new Hook(title, fn);
|
||||
hook.parent = this;
|
||||
hook.timeout(this.timeout());
|
||||
hook.retries(this.retries());
|
||||
hook.slow(this.slow());
|
||||
hook.ctx = this.ctx;
|
||||
hook.file = this.file;
|
||||
return hook;
|
||||
};
|
||||
|
||||
/**
|
||||
* Run `fn(test[, done])` before running tests.
|
||||
*
|
||||
* @private
|
||||
* @param {string} title
|
||||
* @param {Function} fn
|
||||
* @return {Suite} for chaining
|
||||
*/
|
||||
Suite.prototype.beforeAll = function(title, fn) {
|
||||
if (this.isPending()) {
|
||||
return this;
|
||||
}
|
||||
if (typeof title === 'function') {
|
||||
fn = title;
|
||||
title = fn.name;
|
||||
}
|
||||
title = '"before all" hook' + (title ? ': ' + title : '');
|
||||
|
||||
var hook = this._createHook(title, fn);
|
||||
this._beforeAll.push(hook);
|
||||
this.emit(constants.EVENT_SUITE_ADD_HOOK_BEFORE_ALL, hook);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Run `fn(test[, done])` after running tests.
|
||||
*
|
||||
* @private
|
||||
* @param {string} title
|
||||
* @param {Function} fn
|
||||
* @return {Suite} for chaining
|
||||
*/
|
||||
Suite.prototype.afterAll = function(title, fn) {
|
||||
if (this.isPending()) {
|
||||
return this;
|
||||
}
|
||||
if (typeof title === 'function') {
|
||||
fn = title;
|
||||
title = fn.name;
|
||||
}
|
||||
title = '"after all" hook' + (title ? ': ' + title : '');
|
||||
|
||||
var hook = this._createHook(title, fn);
|
||||
this._afterAll.push(hook);
|
||||
this.emit(constants.EVENT_SUITE_ADD_HOOK_AFTER_ALL, hook);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Run `fn(test[, done])` before each test case.
|
||||
*
|
||||
* @private
|
||||
* @param {string} title
|
||||
* @param {Function} fn
|
||||
* @return {Suite} for chaining
|
||||
*/
|
||||
Suite.prototype.beforeEach = function(title, fn) {
|
||||
if (this.isPending()) {
|
||||
return this;
|
||||
}
|
||||
if (typeof title === 'function') {
|
||||
fn = title;
|
||||
title = fn.name;
|
||||
}
|
||||
title = '"before each" hook' + (title ? ': ' + title : '');
|
||||
|
||||
var hook = this._createHook(title, fn);
|
||||
this._beforeEach.push(hook);
|
||||
this.emit(constants.EVENT_SUITE_ADD_HOOK_BEFORE_EACH, hook);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Run `fn(test[, done])` after each test case.
|
||||
*
|
||||
* @private
|
||||
* @param {string} title
|
||||
* @param {Function} fn
|
||||
* @return {Suite} for chaining
|
||||
*/
|
||||
Suite.prototype.afterEach = function(title, fn) {
|
||||
if (this.isPending()) {
|
||||
return this;
|
||||
}
|
||||
if (typeof title === 'function') {
|
||||
fn = title;
|
||||
title = fn.name;
|
||||
}
|
||||
title = '"after each" hook' + (title ? ': ' + title : '');
|
||||
|
||||
var hook = this._createHook(title, fn);
|
||||
this._afterEach.push(hook);
|
||||
this.emit(constants.EVENT_SUITE_ADD_HOOK_AFTER_EACH, hook);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a test `suite`.
|
||||
*
|
||||
* @private
|
||||
* @param {Suite} suite
|
||||
* @return {Suite} for chaining
|
||||
*/
|
||||
Suite.prototype.addSuite = function(suite) {
|
||||
suite.parent = this;
|
||||
suite.root = false;
|
||||
suite.timeout(this.timeout());
|
||||
suite.retries(this.retries());
|
||||
suite.slow(this.slow());
|
||||
suite.bail(this.bail());
|
||||
this.suites.push(suite);
|
||||
this.emit(constants.EVENT_SUITE_ADD_SUITE, suite);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a `test` to this suite.
|
||||
*
|
||||
* @private
|
||||
* @param {Test} test
|
||||
* @return {Suite} for chaining
|
||||
*/
|
||||
Suite.prototype.addTest = function(test) {
|
||||
test.parent = this;
|
||||
test.timeout(this.timeout());
|
||||
test.retries(this.retries());
|
||||
test.slow(this.slow());
|
||||
test.ctx = this.ctx;
|
||||
this.tests.push(test);
|
||||
this.emit(constants.EVENT_SUITE_ADD_TEST, test);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the full title generated by recursively concatenating the parent's
|
||||
* full title.
|
||||
*
|
||||
* @memberof Suite
|
||||
* @public
|
||||
* @return {string}
|
||||
*/
|
||||
Suite.prototype.fullTitle = function() {
|
||||
return this.titlePath().join(' ');
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the title path generated by recursively concatenating the parent's
|
||||
* title path.
|
||||
*
|
||||
* @memberof Suite
|
||||
* @public
|
||||
* @return {string}
|
||||
*/
|
||||
Suite.prototype.titlePath = function() {
|
||||
var result = [];
|
||||
if (this.parent) {
|
||||
result = result.concat(this.parent.titlePath());
|
||||
}
|
||||
if (!this.root) {
|
||||
result.push(this.title);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the total number of tests.
|
||||
*
|
||||
* @memberof Suite
|
||||
* @public
|
||||
* @return {number}
|
||||
*/
|
||||
Suite.prototype.total = function() {
|
||||
return (
|
||||
this.suites.reduce(function(sum, suite) {
|
||||
return sum + suite.total();
|
||||
}, 0) + this.tests.length
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Iterates through each suite recursively to find all tests. Applies a
|
||||
* function in the format `fn(test)`.
|
||||
*
|
||||
* @private
|
||||
* @param {Function} fn
|
||||
* @return {Suite}
|
||||
*/
|
||||
Suite.prototype.eachTest = function(fn) {
|
||||
this.tests.forEach(fn);
|
||||
this.suites.forEach(function(suite) {
|
||||
suite.eachTest(fn);
|
||||
});
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* This will run the root suite if we happen to be running in delayed mode.
|
||||
* @private
|
||||
*/
|
||||
Suite.prototype.run = function run() {
|
||||
if (this.root) {
|
||||
this.emit(constants.EVENT_ROOT_SUITE_RUN);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Determines whether a suite has an `only` test or suite as a descendant.
|
||||
*
|
||||
* @private
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
Suite.prototype.hasOnly = function hasOnly() {
|
||||
return (
|
||||
this._onlyTests.length > 0 ||
|
||||
this._onlySuites.length > 0 ||
|
||||
this.suites.some(function(suite) {
|
||||
return suite.hasOnly();
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Filter suites based on `isOnly` logic.
|
||||
*
|
||||
* @private
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
Suite.prototype.filterOnly = function filterOnly() {
|
||||
if (this._onlyTests.length) {
|
||||
// If the suite contains `only` tests, run those and ignore any nested suites.
|
||||
this.tests = this._onlyTests;
|
||||
this.suites = [];
|
||||
} else {
|
||||
// Otherwise, do not run any of the tests in this suite.
|
||||
this.tests = [];
|
||||
this._onlySuites.forEach(function(onlySuite) {
|
||||
// If there are other `only` tests/suites nested in the current `only` suite, then filter that `only` suite.
|
||||
// Otherwise, all of the tests on this `only` suite should be run, so don't filter it.
|
||||
if (onlySuite.hasOnly()) {
|
||||
onlySuite.filterOnly();
|
||||
}
|
||||
});
|
||||
// Run the `only` suites, as well as any other suites that have `only` tests/suites as descendants.
|
||||
var onlySuites = this._onlySuites;
|
||||
this.suites = this.suites.filter(function(childSuite) {
|
||||
return onlySuites.indexOf(childSuite) !== -1 || childSuite.filterOnly();
|
||||
});
|
||||
}
|
||||
// Keep the suite only if there is something to run
|
||||
return this.tests.length > 0 || this.suites.length > 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a suite to the list of subsuites marked `only`.
|
||||
*
|
||||
* @private
|
||||
* @param {Suite} suite
|
||||
*/
|
||||
Suite.prototype.appendOnlySuite = function(suite) {
|
||||
this._onlySuites.push(suite);
|
||||
};
|
||||
|
||||
/**
|
||||
* Marks a suite to be `only`.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
Suite.prototype.markOnly = function() {
|
||||
this.parent && this.parent.appendOnlySuite(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a test to the list of tests marked `only`.
|
||||
*
|
||||
* @private
|
||||
* @param {Test} test
|
||||
*/
|
||||
Suite.prototype.appendOnlyTest = function(test) {
|
||||
this._onlyTests.push(test);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the array of hooks by hook name; see `HOOK_TYPE_*` constants.
|
||||
* @private
|
||||
*/
|
||||
Suite.prototype.getHooks = function getHooks(name) {
|
||||
return this['_' + name];
|
||||
};
|
||||
|
||||
/**
|
||||
* cleans all references from this suite and all child suites.
|
||||
*/
|
||||
Suite.prototype.dispose = function() {
|
||||
this.suites.forEach(function(suite) {
|
||||
suite.dispose();
|
||||
});
|
||||
this.cleanReferences();
|
||||
};
|
||||
|
||||
/**
|
||||
* Cleans up the references to all the deferred functions
|
||||
* (before/after/beforeEach/afterEach) and tests of a Suite.
|
||||
* These must be deleted otherwise a memory leak can happen,
|
||||
* as those functions may reference variables from closures,
|
||||
* thus those variables can never be garbage collected as long
|
||||
* as the deferred functions exist.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
Suite.prototype.cleanReferences = function cleanReferences() {
|
||||
function cleanArrReferences(arr) {
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
delete arr[i].fn;
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(this._beforeAll)) {
|
||||
cleanArrReferences(this._beforeAll);
|
||||
}
|
||||
|
||||
if (Array.isArray(this._beforeEach)) {
|
||||
cleanArrReferences(this._beforeEach);
|
||||
}
|
||||
|
||||
if (Array.isArray(this._afterAll)) {
|
||||
cleanArrReferences(this._afterAll);
|
||||
}
|
||||
|
||||
if (Array.isArray(this._afterEach)) {
|
||||
cleanArrReferences(this._afterEach);
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.tests.length; i++) {
|
||||
delete this.tests[i].fn;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an object suitable for IPC.
|
||||
* Functions are represented by keys beginning with `$$`.
|
||||
* @private
|
||||
* @returns {Object}
|
||||
*/
|
||||
Suite.prototype.serialize = function serialize() {
|
||||
return {
|
||||
_bail: this._bail,
|
||||
$$fullTitle: this.fullTitle(),
|
||||
$$isPending: this.isPending(),
|
||||
root: this.root,
|
||||
title: this.title,
|
||||
id: this.id,
|
||||
parent: this.parent ? {[MOCHA_ID_PROP_NAME]: this.parent.id} : null
|
||||
};
|
||||
};
|
||||
|
||||
var constants = defineConstants(
|
||||
/**
|
||||
* {@link Suite}-related constants.
|
||||
* @public
|
||||
* @memberof Suite
|
||||
* @alias constants
|
||||
* @readonly
|
||||
* @static
|
||||
* @enum {string}
|
||||
*/
|
||||
{
|
||||
/**
|
||||
* Event emitted after a test file has been loaded Not emitted in browser.
|
||||
*/
|
||||
EVENT_FILE_POST_REQUIRE: 'post-require',
|
||||
/**
|
||||
* Event emitted before a test file has been loaded. In browser, this is emitted once an interface has been selected.
|
||||
*/
|
||||
EVENT_FILE_PRE_REQUIRE: 'pre-require',
|
||||
/**
|
||||
* Event emitted immediately after a test file has been loaded. Not emitted in browser.
|
||||
*/
|
||||
EVENT_FILE_REQUIRE: 'require',
|
||||
/**
|
||||
* Event emitted when `global.run()` is called (use with `delay` option)
|
||||
*/
|
||||
EVENT_ROOT_SUITE_RUN: 'run',
|
||||
|
||||
/**
|
||||
* Namespace for collection of a `Suite`'s "after all" hooks
|
||||
*/
|
||||
HOOK_TYPE_AFTER_ALL: 'afterAll',
|
||||
/**
|
||||
* Namespace for collection of a `Suite`'s "after each" hooks
|
||||
*/
|
||||
HOOK_TYPE_AFTER_EACH: 'afterEach',
|
||||
/**
|
||||
* Namespace for collection of a `Suite`'s "before all" hooks
|
||||
*/
|
||||
HOOK_TYPE_BEFORE_ALL: 'beforeAll',
|
||||
/**
|
||||
* Namespace for collection of a `Suite`'s "before all" hooks
|
||||
*/
|
||||
HOOK_TYPE_BEFORE_EACH: 'beforeEach',
|
||||
|
||||
// the following events are all deprecated
|
||||
|
||||
/**
|
||||
* Emitted after an "after all" `Hook` has been added to a `Suite`. Deprecated
|
||||
*/
|
||||
EVENT_SUITE_ADD_HOOK_AFTER_ALL: 'afterAll',
|
||||
/**
|
||||
* Emitted after an "after each" `Hook` has been added to a `Suite` Deprecated
|
||||
*/
|
||||
EVENT_SUITE_ADD_HOOK_AFTER_EACH: 'afterEach',
|
||||
/**
|
||||
* Emitted after an "before all" `Hook` has been added to a `Suite` Deprecated
|
||||
*/
|
||||
EVENT_SUITE_ADD_HOOK_BEFORE_ALL: 'beforeAll',
|
||||
/**
|
||||
* Emitted after an "before each" `Hook` has been added to a `Suite` Deprecated
|
||||
*/
|
||||
EVENT_SUITE_ADD_HOOK_BEFORE_EACH: 'beforeEach',
|
||||
/**
|
||||
* Emitted after a child `Suite` has been added to a `Suite`. Deprecated
|
||||
*/
|
||||
EVENT_SUITE_ADD_SUITE: 'suite',
|
||||
/**
|
||||
* Emitted after a `Test` has been added to a `Suite`. Deprecated
|
||||
*/
|
||||
EVENT_SUITE_ADD_TEST: 'test'
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* @summary There are no known use cases for these events.
|
||||
* @desc This is a `Set`-like object having all keys being the constant's string value and the value being `true`.
|
||||
* @todo Remove eventually
|
||||
* @type {Object<string,boolean>}
|
||||
* @ignore
|
||||
*/
|
||||
var deprecatedEvents = Object.keys(constants)
|
||||
.filter(function(constant) {
|
||||
return constant.substring(0, 15) === 'EVENT_SUITE_ADD';
|
||||
})
|
||||
.reduce(function(acc, constant) {
|
||||
acc[constants[constant]] = true;
|
||||
return acc;
|
||||
}, createMap());
|
||||
|
||||
Suite.constants = constants;
|
||||
113
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/test.js
generated
vendored
Normal file
113
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/test.js
generated
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
'use strict';
|
||||
var Runnable = require('./runnable');
|
||||
var utils = require('./utils');
|
||||
var errors = require('./errors');
|
||||
var createInvalidArgumentTypeError = errors.createInvalidArgumentTypeError;
|
||||
var isString = utils.isString;
|
||||
|
||||
const {MOCHA_ID_PROP_NAME} = utils.constants;
|
||||
|
||||
module.exports = Test;
|
||||
|
||||
/**
|
||||
* Initialize a new `Test` with the given `title` and callback `fn`.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @extends Runnable
|
||||
* @param {String} title - Test title (required)
|
||||
* @param {Function} [fn] - Test callback. If omitted, the Test is considered "pending"
|
||||
*/
|
||||
function Test(title, fn) {
|
||||
if (!isString(title)) {
|
||||
throw createInvalidArgumentTypeError(
|
||||
'Test argument "title" should be a string. Received type "' +
|
||||
typeof title +
|
||||
'"',
|
||||
'title',
|
||||
'string'
|
||||
);
|
||||
}
|
||||
this.type = 'test';
|
||||
Runnable.call(this, title, fn);
|
||||
this.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Runnable.prototype`.
|
||||
*/
|
||||
utils.inherits(Test, Runnable);
|
||||
|
||||
/**
|
||||
* Resets the state initially or for a next run.
|
||||
*/
|
||||
Test.prototype.reset = function() {
|
||||
Runnable.prototype.reset.call(this);
|
||||
this.pending = !this.fn;
|
||||
delete this.state;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set or get retried test
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
Test.prototype.retriedTest = function(n) {
|
||||
if (!arguments.length) {
|
||||
return this._retriedTest;
|
||||
}
|
||||
this._retriedTest = n;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add test to the list of tests marked `only`.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
Test.prototype.markOnly = function() {
|
||||
this.parent.appendOnlyTest(this);
|
||||
};
|
||||
|
||||
Test.prototype.clone = function() {
|
||||
var test = new Test(this.title, this.fn);
|
||||
test.timeout(this.timeout());
|
||||
test.slow(this.slow());
|
||||
test.retries(this.retries());
|
||||
test.currentRetry(this.currentRetry());
|
||||
test.retriedTest(this.retriedTest() || this);
|
||||
test.globals(this.globals());
|
||||
test.parent = this.parent;
|
||||
test.file = this.file;
|
||||
test.ctx = this.ctx;
|
||||
return test;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns an minimal object suitable for transmission over IPC.
|
||||
* Functions are represented by keys beginning with `$$`.
|
||||
* @private
|
||||
* @returns {Object}
|
||||
*/
|
||||
Test.prototype.serialize = function serialize() {
|
||||
return {
|
||||
$$currentRetry: this._currentRetry,
|
||||
$$fullTitle: this.fullTitle(),
|
||||
$$isPending: this.pending,
|
||||
$$retriedTest: this._retriedTest || null,
|
||||
$$slow: this._slow,
|
||||
$$titlePath: this.titlePath(),
|
||||
body: this.body,
|
||||
duration: this.duration,
|
||||
err: this.err,
|
||||
parent: {
|
||||
$$fullTitle: this.parent.fullTitle(),
|
||||
[MOCHA_ID_PROP_NAME]: this.parent.id
|
||||
},
|
||||
speed: this.speed,
|
||||
state: this.state,
|
||||
title: this.title,
|
||||
type: this.type,
|
||||
file: this.file,
|
||||
[MOCHA_ID_PROP_NAME]: this.id
|
||||
};
|
||||
};
|
||||
667
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/utils.js
generated
vendored
Normal file
667
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/lib/utils.js
generated
vendored
Normal file
@ -0,0 +1,667 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Various utility functions used throughout Mocha's codebase.
|
||||
* @module utils
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const {nanoid} = require('nanoid/non-secure');
|
||||
var path = require('path');
|
||||
var util = require('util');
|
||||
var he = require('he');
|
||||
|
||||
const MOCHA_ID_PROP_NAME = '__mocha_id__';
|
||||
|
||||
/**
|
||||
* Inherit the prototype methods from one constructor into another.
|
||||
*
|
||||
* @param {function} ctor - Constructor function which needs to inherit the
|
||||
* prototype.
|
||||
* @param {function} superCtor - Constructor function to inherit prototype from.
|
||||
* @throws {TypeError} if either constructor is null, or if super constructor
|
||||
* lacks a prototype.
|
||||
*/
|
||||
exports.inherits = util.inherits;
|
||||
|
||||
/**
|
||||
* Escape special characters in the given string of html.
|
||||
*
|
||||
* @private
|
||||
* @param {string} html
|
||||
* @return {string}
|
||||
*/
|
||||
exports.escape = function(html) {
|
||||
return he.encode(String(html), {useNamedReferences: false});
|
||||
};
|
||||
|
||||
/**
|
||||
* Test if the given obj is type of string.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} obj
|
||||
* @return {boolean}
|
||||
*/
|
||||
exports.isString = function(obj) {
|
||||
return typeof obj === 'string';
|
||||
};
|
||||
|
||||
/**
|
||||
* Compute a slug from the given `str`.
|
||||
*
|
||||
* @private
|
||||
* @param {string} str
|
||||
* @return {string}
|
||||
*/
|
||||
exports.slug = function(str) {
|
||||
return str
|
||||
.toLowerCase()
|
||||
.replace(/\s+/g, '-')
|
||||
.replace(/[^-\w]/g, '')
|
||||
.replace(/-{2,}/g, '-');
|
||||
};
|
||||
|
||||
/**
|
||||
* Strip the function definition from `str`, and re-indent for pre whitespace.
|
||||
*
|
||||
* @param {string} str
|
||||
* @return {string}
|
||||
*/
|
||||
exports.clean = function(str) {
|
||||
str = str
|
||||
.replace(/\r\n?|[\n\u2028\u2029]/g, '\n')
|
||||
.replace(/^\uFEFF/, '')
|
||||
// (traditional)-> space/name parameters body (lambda)-> parameters body multi-statement/single keep body content
|
||||
.replace(
|
||||
/^function(?:\s*|\s+[^(]*)\([^)]*\)\s*\{((?:.|\n)*?)\s*\}$|^\([^)]*\)\s*=>\s*(?:\{((?:.|\n)*?)\s*\}|((?:.|\n)*))$/,
|
||||
'$1$2$3'
|
||||
);
|
||||
|
||||
var spaces = str.match(/^\n?( *)/)[1].length;
|
||||
var tabs = str.match(/^\n?(\t*)/)[1].length;
|
||||
var re = new RegExp(
|
||||
'^\n?' + (tabs ? '\t' : ' ') + '{' + (tabs || spaces) + '}',
|
||||
'gm'
|
||||
);
|
||||
|
||||
str = str.replace(re, '');
|
||||
|
||||
return str.trim();
|
||||
};
|
||||
|
||||
/**
|
||||
* If a value could have properties, and has none, this function is called,
|
||||
* which returns a string representation of the empty value.
|
||||
*
|
||||
* Functions w/ no properties return `'[Function]'`
|
||||
* Arrays w/ length === 0 return `'[]'`
|
||||
* Objects w/ no properties return `'{}'`
|
||||
* All else: return result of `value.toString()`
|
||||
*
|
||||
* @private
|
||||
* @param {*} value The value to inspect.
|
||||
* @param {string} typeHint The type of the value
|
||||
* @returns {string}
|
||||
*/
|
||||
function emptyRepresentation(value, typeHint) {
|
||||
switch (typeHint) {
|
||||
case 'function':
|
||||
return '[Function]';
|
||||
case 'object':
|
||||
return '{}';
|
||||
case 'array':
|
||||
return '[]';
|
||||
default:
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes some variable and asks `Object.prototype.toString()` what it thinks it
|
||||
* is.
|
||||
*
|
||||
* @private
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
|
||||
* @param {*} value The value to test.
|
||||
* @returns {string} Computed type
|
||||
* @example
|
||||
* canonicalType({}) // 'object'
|
||||
* canonicalType([]) // 'array'
|
||||
* canonicalType(1) // 'number'
|
||||
* canonicalType(false) // 'boolean'
|
||||
* canonicalType(Infinity) // 'number'
|
||||
* canonicalType(null) // 'null'
|
||||
* canonicalType(new Date()) // 'date'
|
||||
* canonicalType(/foo/) // 'regexp'
|
||||
* canonicalType('type') // 'string'
|
||||
* canonicalType(global) // 'global'
|
||||
* canonicalType(new String('foo') // 'object'
|
||||
* canonicalType(async function() {}) // 'asyncfunction'
|
||||
* canonicalType(await import(name)) // 'module'
|
||||
*/
|
||||
var canonicalType = (exports.canonicalType = function canonicalType(value) {
|
||||
if (value === undefined) {
|
||||
return 'undefined';
|
||||
} else if (value === null) {
|
||||
return 'null';
|
||||
} else if (Buffer.isBuffer(value)) {
|
||||
return 'buffer';
|
||||
}
|
||||
return Object.prototype.toString
|
||||
.call(value)
|
||||
.replace(/^\[.+\s(.+?)]$/, '$1')
|
||||
.toLowerCase();
|
||||
});
|
||||
|
||||
/**
|
||||
*
|
||||
* Returns a general type or data structure of a variable
|
||||
* @private
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures
|
||||
* @param {*} value The value to test.
|
||||
* @returns {string} One of undefined, boolean, number, string, bigint, symbol, object
|
||||
* @example
|
||||
* type({}) // 'object'
|
||||
* type([]) // 'array'
|
||||
* type(1) // 'number'
|
||||
* type(false) // 'boolean'
|
||||
* type(Infinity) // 'number'
|
||||
* type(null) // 'null'
|
||||
* type(new Date()) // 'object'
|
||||
* type(/foo/) // 'object'
|
||||
* type('type') // 'string'
|
||||
* type(global) // 'object'
|
||||
* type(new String('foo') // 'string'
|
||||
*/
|
||||
exports.type = function type(value) {
|
||||
// Null is special
|
||||
if (value === null) return 'null';
|
||||
const primitives = new Set([
|
||||
'undefined',
|
||||
'boolean',
|
||||
'number',
|
||||
'string',
|
||||
'bigint',
|
||||
'symbol'
|
||||
]);
|
||||
const _type = typeof value;
|
||||
if (_type === 'function') return _type;
|
||||
if (primitives.has(_type)) return _type;
|
||||
if (value instanceof String) return 'string';
|
||||
if (value instanceof Error) return 'error';
|
||||
if (Array.isArray(value)) return 'array';
|
||||
|
||||
return _type;
|
||||
};
|
||||
|
||||
/**
|
||||
* Stringify `value`. Different behavior depending on type of value:
|
||||
*
|
||||
* - If `value` is undefined or null, return `'[undefined]'` or `'[null]'`, respectively.
|
||||
* - If `value` is not an object, function or array, return result of `value.toString()` wrapped in double-quotes.
|
||||
* - If `value` is an *empty* object, function, or array, return result of function
|
||||
* {@link emptyRepresentation}.
|
||||
* - If `value` has properties, call {@link exports.canonicalize} on it, then return result of
|
||||
* JSON.stringify().
|
||||
*
|
||||
* @private
|
||||
* @see exports.type
|
||||
* @param {*} value
|
||||
* @return {string}
|
||||
*/
|
||||
exports.stringify = function(value) {
|
||||
var typeHint = canonicalType(value);
|
||||
|
||||
if (!~['object', 'array', 'function'].indexOf(typeHint)) {
|
||||
if (typeHint === 'buffer') {
|
||||
var json = Buffer.prototype.toJSON.call(value);
|
||||
// Based on the toJSON result
|
||||
return jsonStringify(
|
||||
json.data && json.type ? json.data : json,
|
||||
2
|
||||
).replace(/,(\n|$)/g, '$1');
|
||||
}
|
||||
|
||||
// IE7/IE8 has a bizarre String constructor; needs to be coerced
|
||||
// into an array and back to obj.
|
||||
if (typeHint === 'string' && typeof value === 'object') {
|
||||
value = value.split('').reduce(function(acc, char, idx) {
|
||||
acc[idx] = char;
|
||||
return acc;
|
||||
}, {});
|
||||
typeHint = 'object';
|
||||
} else {
|
||||
return jsonStringify(value);
|
||||
}
|
||||
}
|
||||
|
||||
for (var prop in value) {
|
||||
if (Object.prototype.hasOwnProperty.call(value, prop)) {
|
||||
return jsonStringify(
|
||||
exports.canonicalize(value, null, typeHint),
|
||||
2
|
||||
).replace(/,(\n|$)/g, '$1');
|
||||
}
|
||||
}
|
||||
|
||||
return emptyRepresentation(value, typeHint);
|
||||
};
|
||||
|
||||
/**
|
||||
* like JSON.stringify but more sense.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object
|
||||
* @param {number=} spaces
|
||||
* @param {number=} depth
|
||||
* @returns {*}
|
||||
*/
|
||||
function jsonStringify(object, spaces, depth) {
|
||||
if (typeof spaces === 'undefined') {
|
||||
// primitive types
|
||||
return _stringify(object);
|
||||
}
|
||||
|
||||
depth = depth || 1;
|
||||
var space = spaces * depth;
|
||||
var str = Array.isArray(object) ? '[' : '{';
|
||||
var end = Array.isArray(object) ? ']' : '}';
|
||||
var length =
|
||||
typeof object.length === 'number'
|
||||
? object.length
|
||||
: Object.keys(object).length;
|
||||
// `.repeat()` polyfill
|
||||
function repeat(s, n) {
|
||||
return new Array(n).join(s);
|
||||
}
|
||||
|
||||
function _stringify(val) {
|
||||
switch (canonicalType(val)) {
|
||||
case 'null':
|
||||
case 'undefined':
|
||||
val = '[' + val + ']';
|
||||
break;
|
||||
case 'array':
|
||||
case 'object':
|
||||
val = jsonStringify(val, spaces, depth + 1);
|
||||
break;
|
||||
case 'boolean':
|
||||
case 'regexp':
|
||||
case 'symbol':
|
||||
case 'number':
|
||||
val =
|
||||
val === 0 && 1 / val === -Infinity // `-0`
|
||||
? '-0'
|
||||
: val.toString();
|
||||
break;
|
||||
case 'bigint':
|
||||
val = val.toString() + 'n';
|
||||
break;
|
||||
case 'date':
|
||||
var sDate = isNaN(val.getTime()) ? val.toString() : val.toISOString();
|
||||
val = '[Date: ' + sDate + ']';
|
||||
break;
|
||||
case 'buffer':
|
||||
var json = val.toJSON();
|
||||
// Based on the toJSON result
|
||||
json = json.data && json.type ? json.data : json;
|
||||
val = '[Buffer: ' + jsonStringify(json, 2, depth + 1) + ']';
|
||||
break;
|
||||
default:
|
||||
val =
|
||||
val === '[Function]' || val === '[Circular]'
|
||||
? val
|
||||
: JSON.stringify(val); // string
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
for (var i in object) {
|
||||
if (!Object.prototype.hasOwnProperty.call(object, i)) {
|
||||
continue; // not my business
|
||||
}
|
||||
--length;
|
||||
str +=
|
||||
'\n ' +
|
||||
repeat(' ', space) +
|
||||
(Array.isArray(object) ? '' : '"' + i + '": ') + // key
|
||||
_stringify(object[i]) + // value
|
||||
(length ? ',' : ''); // comma
|
||||
}
|
||||
|
||||
return (
|
||||
str +
|
||||
// [], {}
|
||||
(str.length !== 1 ? '\n' + repeat(' ', --space) + end : end)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new Thing that has the keys in sorted order. Recursive.
|
||||
*
|
||||
* If the Thing...
|
||||
* - has already been seen, return string `'[Circular]'`
|
||||
* - is `undefined`, return string `'[undefined]'`
|
||||
* - is `null`, return value `null`
|
||||
* - is some other primitive, return the value
|
||||
* - is not a primitive or an `Array`, `Object`, or `Function`, return the value of the Thing's `toString()` method
|
||||
* - is a non-empty `Array`, `Object`, or `Function`, return the result of calling this function again.
|
||||
* - is an empty `Array`, `Object`, or `Function`, return the result of calling `emptyRepresentation()`
|
||||
*
|
||||
* @private
|
||||
* @see {@link exports.stringify}
|
||||
* @param {*} value Thing to inspect. May or may not have properties.
|
||||
* @param {Array} [stack=[]] Stack of seen values
|
||||
* @param {string} [typeHint] Type hint
|
||||
* @return {(Object|Array|Function|string|undefined)}
|
||||
*/
|
||||
exports.canonicalize = function canonicalize(value, stack, typeHint) {
|
||||
var canonicalizedObj;
|
||||
/* eslint-disable no-unused-vars */
|
||||
var prop;
|
||||
/* eslint-enable no-unused-vars */
|
||||
typeHint = typeHint || canonicalType(value);
|
||||
function withStack(value, fn) {
|
||||
stack.push(value);
|
||||
fn();
|
||||
stack.pop();
|
||||
}
|
||||
|
||||
stack = stack || [];
|
||||
|
||||
if (stack.indexOf(value) !== -1) {
|
||||
return '[Circular]';
|
||||
}
|
||||
|
||||
switch (typeHint) {
|
||||
case 'undefined':
|
||||
case 'buffer':
|
||||
case 'null':
|
||||
canonicalizedObj = value;
|
||||
break;
|
||||
case 'array':
|
||||
withStack(value, function() {
|
||||
canonicalizedObj = value.map(function(item) {
|
||||
return exports.canonicalize(item, stack);
|
||||
});
|
||||
});
|
||||
break;
|
||||
case 'function':
|
||||
/* eslint-disable-next-line no-unused-vars */
|
||||
for (prop in value) {
|
||||
canonicalizedObj = {};
|
||||
break;
|
||||
}
|
||||
/* eslint-enable guard-for-in */
|
||||
if (!canonicalizedObj) {
|
||||
canonicalizedObj = emptyRepresentation(value, typeHint);
|
||||
break;
|
||||
}
|
||||
/* falls through */
|
||||
case 'object':
|
||||
canonicalizedObj = canonicalizedObj || {};
|
||||
withStack(value, function() {
|
||||
Object.keys(value)
|
||||
.sort()
|
||||
.forEach(function(key) {
|
||||
canonicalizedObj[key] = exports.canonicalize(value[key], stack);
|
||||
});
|
||||
});
|
||||
break;
|
||||
case 'date':
|
||||
case 'number':
|
||||
case 'regexp':
|
||||
case 'boolean':
|
||||
case 'symbol':
|
||||
canonicalizedObj = value;
|
||||
break;
|
||||
default:
|
||||
canonicalizedObj = value + '';
|
||||
}
|
||||
|
||||
return canonicalizedObj;
|
||||
};
|
||||
|
||||
/**
|
||||
* @summary
|
||||
* This Filter based on `mocha-clean` module.(see: `github.com/rstacruz/mocha-clean`)
|
||||
* @description
|
||||
* When invoking this function you get a filter function that get the Error.stack as an input,
|
||||
* and return a prettify output.
|
||||
* (i.e: strip Mocha and internal node functions from stack trace).
|
||||
* @returns {Function}
|
||||
*/
|
||||
exports.stackTraceFilter = function() {
|
||||
// TODO: Replace with `process.browser`
|
||||
var is = typeof document === 'undefined' ? {node: true} : {browser: true};
|
||||
var slash = path.sep;
|
||||
var cwd;
|
||||
if (is.node) {
|
||||
cwd = exports.cwd() + slash;
|
||||
} else {
|
||||
cwd = (typeof location === 'undefined'
|
||||
? window.location
|
||||
: location
|
||||
).href.replace(/\/[^/]*$/, '/');
|
||||
slash = '/';
|
||||
}
|
||||
|
||||
function isMochaInternal(line) {
|
||||
return (
|
||||
~line.indexOf('node_modules' + slash + 'mocha' + slash) ||
|
||||
~line.indexOf(slash + 'mocha.js') ||
|
||||
~line.indexOf(slash + 'mocha.min.js')
|
||||
);
|
||||
}
|
||||
|
||||
function isNodeInternal(line) {
|
||||
return (
|
||||
~line.indexOf('(timers.js:') ||
|
||||
~line.indexOf('(events.js:') ||
|
||||
~line.indexOf('(node.js:') ||
|
||||
~line.indexOf('(module.js:') ||
|
||||
~line.indexOf('GeneratorFunctionPrototype.next (native)') ||
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
return function(stack) {
|
||||
stack = stack.split('\n');
|
||||
|
||||
stack = stack.reduce(function(list, line) {
|
||||
if (isMochaInternal(line)) {
|
||||
return list;
|
||||
}
|
||||
|
||||
if (is.node && isNodeInternal(line)) {
|
||||
return list;
|
||||
}
|
||||
|
||||
// Clean up cwd(absolute)
|
||||
if (/:\d+:\d+\)?$/.test(line)) {
|
||||
line = line.replace('(' + cwd, '(');
|
||||
}
|
||||
|
||||
list.push(line);
|
||||
return list;
|
||||
}, []);
|
||||
|
||||
return stack.join('\n');
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Crude, but effective.
|
||||
* @public
|
||||
* @param {*} value
|
||||
* @returns {boolean} Whether or not `value` is a Promise
|
||||
*/
|
||||
exports.isPromise = function isPromise(value) {
|
||||
return (
|
||||
typeof value === 'object' &&
|
||||
value !== null &&
|
||||
typeof value.then === 'function'
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clamps a numeric value to an inclusive range.
|
||||
*
|
||||
* @param {number} value - Value to be clamped.
|
||||
* @param {number[]} range - Two element array specifying [min, max] range.
|
||||
* @returns {number} clamped value
|
||||
*/
|
||||
exports.clamp = function clamp(value, range) {
|
||||
return Math.min(Math.max(value, range[0]), range[1]);
|
||||
};
|
||||
|
||||
/**
|
||||
* It's a noop.
|
||||
* @public
|
||||
*/
|
||||
exports.noop = function() {};
|
||||
|
||||
/**
|
||||
* Creates a map-like object.
|
||||
*
|
||||
* @description
|
||||
* A "map" is an object with no prototype, for our purposes. In some cases
|
||||
* this would be more appropriate than a `Map`, especially if your environment
|
||||
* doesn't support it. Recommended for use in Mocha's public APIs.
|
||||
*
|
||||
* @public
|
||||
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Custom_and_Null_objects|MDN:Map}
|
||||
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create#Custom_and_Null_objects|MDN:Object.create - Custom objects}
|
||||
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Custom_and_Null_objects|MDN:Object.assign}
|
||||
* @param {...*} [obj] - Arguments to `Object.assign()`.
|
||||
* @returns {Object} An object with no prototype, having `...obj` properties
|
||||
*/
|
||||
exports.createMap = function(obj) {
|
||||
return Object.assign.apply(
|
||||
null,
|
||||
[Object.create(null)].concat(Array.prototype.slice.call(arguments))
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a read-only map-like object.
|
||||
*
|
||||
* @description
|
||||
* This differs from {@link module:utils.createMap createMap} only in that
|
||||
* the argument must be non-empty, because the result is frozen.
|
||||
*
|
||||
* @see {@link module:utils.createMap createMap}
|
||||
* @param {...*} [obj] - Arguments to `Object.assign()`.
|
||||
* @returns {Object} A frozen object with no prototype, having `...obj` properties
|
||||
* @throws {TypeError} if argument is not a non-empty object.
|
||||
*/
|
||||
exports.defineConstants = function(obj) {
|
||||
if (canonicalType(obj) !== 'object' || !Object.keys(obj).length) {
|
||||
throw new TypeError('Invalid argument; expected a non-empty object');
|
||||
}
|
||||
return Object.freeze(exports.createMap(obj));
|
||||
};
|
||||
|
||||
/**
|
||||
* Whether current version of Node support ES modules
|
||||
*
|
||||
* @description
|
||||
* Versions prior to 10 did not support ES Modules, and version 10 has an old incompatible version of ESM.
|
||||
* This function returns whether Node.JS has ES Module supports that is compatible with Mocha's needs,
|
||||
* which is version >=12.11.
|
||||
*
|
||||
* @param {partialSupport} whether the full Node.js ESM support is available (>= 12) or just something that supports the runtime (>= 10)
|
||||
*
|
||||
* @returns {Boolean} whether the current version of Node.JS supports ES Modules in a way that is compatible with Mocha
|
||||
*/
|
||||
exports.supportsEsModules = function(partialSupport) {
|
||||
if (!exports.isBrowser() && process.versions && process.versions.node) {
|
||||
var versionFields = process.versions.node.split('.');
|
||||
var major = +versionFields[0];
|
||||
var minor = +versionFields[1];
|
||||
|
||||
if (!partialSupport) {
|
||||
return major >= 13 || (major === 12 && minor >= 11);
|
||||
} else {
|
||||
return major >= 10;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns current working directory
|
||||
*
|
||||
* Wrapper around `process.cwd()` for isolation
|
||||
* @private
|
||||
*/
|
||||
exports.cwd = function cwd() {
|
||||
return process.cwd();
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns `true` if Mocha is running in a browser.
|
||||
* Checks for `process.browser`.
|
||||
* @returns {boolean}
|
||||
* @private
|
||||
*/
|
||||
exports.isBrowser = function isBrowser() {
|
||||
return Boolean(process.browser);
|
||||
};
|
||||
|
||||
/*
|
||||
* Casts `value` to an array; useful for optionally accepting array parameters
|
||||
*
|
||||
* It follows these rules, depending on `value`. If `value` is...
|
||||
* 1. `undefined`: return an empty Array
|
||||
* 2. `null`: return an array with a single `null` element
|
||||
* 3. Any other object: return the value of `Array.from()` _if_ the object is iterable
|
||||
* 4. otherwise: return an array with a single element, `value`
|
||||
* @param {*} value - Something to cast to an Array
|
||||
* @returns {Array<*>}
|
||||
*/
|
||||
exports.castArray = function castArray(value) {
|
||||
if (value === undefined) {
|
||||
return [];
|
||||
}
|
||||
if (value === null) {
|
||||
return [null];
|
||||
}
|
||||
if (
|
||||
typeof value === 'object' &&
|
||||
(typeof value[Symbol.iterator] === 'function' || value.length !== undefined)
|
||||
) {
|
||||
return Array.from(value);
|
||||
}
|
||||
return [value];
|
||||
};
|
||||
|
||||
exports.constants = exports.defineConstants({
|
||||
MOCHA_ID_PROP_NAME
|
||||
});
|
||||
|
||||
/**
|
||||
* Creates a new unique identifier
|
||||
* @returns {string} Unique identifier
|
||||
*/
|
||||
exports.uniqueID = () => nanoid();
|
||||
|
||||
exports.assignNewMochaID = obj => {
|
||||
const id = exports.uniqueID();
|
||||
Object.defineProperty(obj, MOCHA_ID_PROP_NAME, {
|
||||
get() {
|
||||
return id;
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves a Mocha ID from an object, if present.
|
||||
* @param {*} [obj] - Object
|
||||
* @returns {string|void}
|
||||
*/
|
||||
exports.getMochaID = obj =>
|
||||
obj && typeof obj === 'object' ? obj[MOCHA_ID_PROP_NAME] : undefined;
|
||||
325
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/mocha.css
generated
vendored
Normal file
325
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/mocha.css
generated
vendored
Normal file
@ -0,0 +1,325 @@
|
||||
@charset "utf-8";
|
||||
|
||||
body {
|
||||
margin:0;
|
||||
}
|
||||
|
||||
#mocha {
|
||||
font: 20px/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;
|
||||
margin: 60px 50px;
|
||||
}
|
||||
|
||||
#mocha ul,
|
||||
#mocha li {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#mocha ul {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
#mocha h1,
|
||||
#mocha h2 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#mocha h1 {
|
||||
margin-top: 15px;
|
||||
font-size: 1em;
|
||||
font-weight: 200;
|
||||
}
|
||||
|
||||
#mocha h1 a {
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
#mocha h1 a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
#mocha .suite .suite h1 {
|
||||
margin-top: 0;
|
||||
font-size: .8em;
|
||||
}
|
||||
|
||||
#mocha .hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#mocha h2 {
|
||||
font-size: 12px;
|
||||
font-weight: normal;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#mocha .suite {
|
||||
margin-left: 15px;
|
||||
}
|
||||
|
||||
#mocha .test {
|
||||
margin-left: 15px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#mocha .test.pending:hover h2::after {
|
||||
content: '(pending)';
|
||||
font-family: arial, sans-serif;
|
||||
}
|
||||
|
||||
#mocha .test.pass.medium .duration {
|
||||
background: #c09853;
|
||||
}
|
||||
|
||||
#mocha .test.pass.slow .duration {
|
||||
background: #b94a48;
|
||||
}
|
||||
|
||||
#mocha .test.pass::before {
|
||||
content: '✓';
|
||||
font-size: 12px;
|
||||
display: block;
|
||||
float: left;
|
||||
margin-right: 5px;
|
||||
color: #00d6b2;
|
||||
}
|
||||
|
||||
#mocha .test.pass .duration {
|
||||
font-size: 9px;
|
||||
margin-left: 5px;
|
||||
padding: 2px 5px;
|
||||
color: #fff;
|
||||
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
|
||||
-moz-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
|
||||
box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
|
||||
-webkit-border-radius: 5px;
|
||||
-moz-border-radius: 5px;
|
||||
-ms-border-radius: 5px;
|
||||
-o-border-radius: 5px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
#mocha .test.pass.fast .duration {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#mocha .test.pending {
|
||||
color: #0b97c4;
|
||||
}
|
||||
|
||||
#mocha .test.pending::before {
|
||||
content: '◦';
|
||||
color: #0b97c4;
|
||||
}
|
||||
|
||||
#mocha .test.fail {
|
||||
color: #c00;
|
||||
}
|
||||
|
||||
#mocha .test.fail pre {
|
||||
color: black;
|
||||
}
|
||||
|
||||
#mocha .test.fail::before {
|
||||
content: '✖';
|
||||
font-size: 12px;
|
||||
display: block;
|
||||
float: left;
|
||||
margin-right: 5px;
|
||||
color: #c00;
|
||||
}
|
||||
|
||||
#mocha .test pre.error {
|
||||
color: #c00;
|
||||
max-height: 300px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
#mocha .test .html-error {
|
||||
overflow: auto;
|
||||
color: black;
|
||||
display: block;
|
||||
float: left;
|
||||
clear: left;
|
||||
font: 12px/1.5 monaco, monospace;
|
||||
margin: 5px;
|
||||
padding: 15px;
|
||||
border: 1px solid #eee;
|
||||
max-width: 85%; /*(1)*/
|
||||
max-width: -webkit-calc(100% - 42px);
|
||||
max-width: -moz-calc(100% - 42px);
|
||||
max-width: calc(100% - 42px); /*(2)*/
|
||||
max-height: 300px;
|
||||
word-wrap: break-word;
|
||||
border-bottom-color: #ddd;
|
||||
-webkit-box-shadow: 0 1px 3px #eee;
|
||||
-moz-box-shadow: 0 1px 3px #eee;
|
||||
box-shadow: 0 1px 3px #eee;
|
||||
-webkit-border-radius: 3px;
|
||||
-moz-border-radius: 3px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
#mocha .test .html-error pre.error {
|
||||
border: none;
|
||||
-webkit-border-radius: 0;
|
||||
-moz-border-radius: 0;
|
||||
border-radius: 0;
|
||||
-webkit-box-shadow: 0;
|
||||
-moz-box-shadow: 0;
|
||||
box-shadow: 0;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
margin-top: 18px;
|
||||
max-height: none;
|
||||
}
|
||||
|
||||
/**
|
||||
* (1): approximate for browsers not supporting calc
|
||||
* (2): 42 = 2*15 + 2*10 + 2*1 (padding + margin + border)
|
||||
* ^^ seriously
|
||||
*/
|
||||
#mocha .test pre {
|
||||
display: block;
|
||||
float: left;
|
||||
clear: left;
|
||||
font: 12px/1.5 monaco, monospace;
|
||||
margin: 5px;
|
||||
padding: 15px;
|
||||
border: 1px solid #eee;
|
||||
max-width: 85%; /*(1)*/
|
||||
max-width: -webkit-calc(100% - 42px);
|
||||
max-width: -moz-calc(100% - 42px);
|
||||
max-width: calc(100% - 42px); /*(2)*/
|
||||
word-wrap: break-word;
|
||||
border-bottom-color: #ddd;
|
||||
-webkit-box-shadow: 0 1px 3px #eee;
|
||||
-moz-box-shadow: 0 1px 3px #eee;
|
||||
box-shadow: 0 1px 3px #eee;
|
||||
-webkit-border-radius: 3px;
|
||||
-moz-border-radius: 3px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
#mocha .test h2 {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#mocha .test a.replay {
|
||||
position: absolute;
|
||||
top: 3px;
|
||||
right: 0;
|
||||
text-decoration: none;
|
||||
vertical-align: middle;
|
||||
display: block;
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
line-height: 15px;
|
||||
text-align: center;
|
||||
background: #eee;
|
||||
font-size: 15px;
|
||||
-webkit-border-radius: 15px;
|
||||
-moz-border-radius: 15px;
|
||||
border-radius: 15px;
|
||||
-webkit-transition:opacity 200ms;
|
||||
-moz-transition:opacity 200ms;
|
||||
-o-transition:opacity 200ms;
|
||||
transition: opacity 200ms;
|
||||
opacity: 0.3;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
#mocha .test:hover a.replay {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
#mocha-report.pass .test.fail {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#mocha-report.fail .test.pass {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#mocha-report.pending .test.pass,
|
||||
#mocha-report.pending .test.fail {
|
||||
display: none;
|
||||
}
|
||||
#mocha-report.pending .test.pass.pending {
|
||||
display: block;
|
||||
}
|
||||
|
||||
#mocha-error {
|
||||
color: #c00;
|
||||
font-size: 1.5em;
|
||||
font-weight: 100;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
|
||||
#mocha-stats {
|
||||
position: fixed;
|
||||
top: 15px;
|
||||
right: 10px;
|
||||
font-size: 12px;
|
||||
margin: 0;
|
||||
color: #888;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
#mocha-stats .progress {
|
||||
float: right;
|
||||
padding-top: 0;
|
||||
|
||||
/**
|
||||
* Set safe initial values, so mochas .progress does not inherit these
|
||||
* properties from Bootstrap .progress (which causes .progress height to
|
||||
* equal line height set in Bootstrap).
|
||||
*/
|
||||
height: auto;
|
||||
-webkit-box-shadow: none;
|
||||
-moz-box-shadow: none;
|
||||
box-shadow: none;
|
||||
background-color: initial;
|
||||
}
|
||||
|
||||
#mocha-stats em {
|
||||
color: black;
|
||||
}
|
||||
|
||||
#mocha-stats a {
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
#mocha-stats a:hover {
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
|
||||
#mocha-stats li {
|
||||
display: inline-block;
|
||||
margin: 0 5px;
|
||||
list-style: none;
|
||||
padding-top: 11px;
|
||||
}
|
||||
|
||||
#mocha-stats canvas {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
#mocha code .comment { color: #ddd; }
|
||||
#mocha code .init { color: #2f6fad; }
|
||||
#mocha code .string { color: #5890ad; }
|
||||
#mocha code .keyword { color: #8a6343; }
|
||||
#mocha code .number { color: #2f6fad; }
|
||||
|
||||
@media screen and (max-device-width: 480px) {
|
||||
#mocha {
|
||||
margin: 60px 0px;
|
||||
}
|
||||
|
||||
#mocha #stats {
|
||||
position: absolute;
|
||||
}
|
||||
}
|
||||
30349
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/mocha.js
generated
vendored
Normal file
30349
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/mocha.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/mocha.js.map
generated
vendored
Normal file
1
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/mocha.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
19
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/LICENSE
generated
vendored
Normal file
19
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/LICENSE
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2014 TJ Holowaychuk <tj@vision-media.ca>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the 'Software'), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial
|
||||
portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
||||
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
455
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/README.md
generated
vendored
Normal file
455
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/README.md
generated
vendored
Normal file
@ -0,0 +1,455 @@
|
||||
# debug
|
||||
[](https://travis-ci.org/visionmedia/debug) [](https://coveralls.io/github/visionmedia/debug?branch=master) [](https://visionmedia-community-slackin.now.sh/) [](#backers)
|
||||
[](#sponsors)
|
||||
|
||||
<img width="647" src="https://user-images.githubusercontent.com/71256/29091486-fa38524c-7c37-11e7-895f-e7ec8e1039b6.png">
|
||||
|
||||
A tiny JavaScript debugging utility modelled after Node.js core's debugging
|
||||
technique. Works in Node.js and web browsers.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
$ npm install debug
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
`debug` exposes a function; simply pass this function the name of your module, and it will return a decorated version of `console.error` for you to pass debug statements to. This will allow you to toggle the debug output for different parts of your module as well as the module as a whole.
|
||||
|
||||
Example [_app.js_](./examples/node/app.js):
|
||||
|
||||
```js
|
||||
var debug = require('debug')('http')
|
||||
, http = require('http')
|
||||
, name = 'My App';
|
||||
|
||||
// fake app
|
||||
|
||||
debug('booting %o', name);
|
||||
|
||||
http.createServer(function(req, res){
|
||||
debug(req.method + ' ' + req.url);
|
||||
res.end('hello\n');
|
||||
}).listen(3000, function(){
|
||||
debug('listening');
|
||||
});
|
||||
|
||||
// fake worker of some kind
|
||||
|
||||
require('./worker');
|
||||
```
|
||||
|
||||
Example [_worker.js_](./examples/node/worker.js):
|
||||
|
||||
```js
|
||||
var a = require('debug')('worker:a')
|
||||
, b = require('debug')('worker:b');
|
||||
|
||||
function work() {
|
||||
a('doing lots of uninteresting work');
|
||||
setTimeout(work, Math.random() * 1000);
|
||||
}
|
||||
|
||||
work();
|
||||
|
||||
function workb() {
|
||||
b('doing some work');
|
||||
setTimeout(workb, Math.random() * 2000);
|
||||
}
|
||||
|
||||
workb();
|
||||
```
|
||||
|
||||
The `DEBUG` environment variable is then used to enable these based on space or
|
||||
comma-delimited names.
|
||||
|
||||
Here are some examples:
|
||||
|
||||
<img width="647" alt="screen shot 2017-08-08 at 12 53 04 pm" src="https://user-images.githubusercontent.com/71256/29091703-a6302cdc-7c38-11e7-8304-7c0b3bc600cd.png">
|
||||
<img width="647" alt="screen shot 2017-08-08 at 12 53 38 pm" src="https://user-images.githubusercontent.com/71256/29091700-a62a6888-7c38-11e7-800b-db911291ca2b.png">
|
||||
<img width="647" alt="screen shot 2017-08-08 at 12 53 25 pm" src="https://user-images.githubusercontent.com/71256/29091701-a62ea114-7c38-11e7-826a-2692bedca740.png">
|
||||
|
||||
#### Windows command prompt notes
|
||||
|
||||
##### CMD
|
||||
|
||||
On Windows the environment variable is set using the `set` command.
|
||||
|
||||
```cmd
|
||||
set DEBUG=*,-not_this
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```cmd
|
||||
set DEBUG=* & node app.js
|
||||
```
|
||||
|
||||
##### PowerShell (VS Code default)
|
||||
|
||||
PowerShell uses different syntax to set environment variables.
|
||||
|
||||
```cmd
|
||||
$env:DEBUG = "*,-not_this"
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```cmd
|
||||
$env:DEBUG='app';node app.js
|
||||
```
|
||||
|
||||
Then, run the program to be debugged as usual.
|
||||
|
||||
npm script example:
|
||||
```js
|
||||
"windowsDebug": "@powershell -Command $env:DEBUG='*';node app.js",
|
||||
```
|
||||
|
||||
## Namespace Colors
|
||||
|
||||
Every debug instance has a color generated for it based on its namespace name.
|
||||
This helps when visually parsing the debug output to identify which debug instance
|
||||
a debug line belongs to.
|
||||
|
||||
#### Node.js
|
||||
|
||||
In Node.js, colors are enabled when stderr is a TTY. You also _should_ install
|
||||
the [`supports-color`](https://npmjs.org/supports-color) module alongside debug,
|
||||
otherwise debug will only use a small handful of basic colors.
|
||||
|
||||
<img width="521" src="https://user-images.githubusercontent.com/71256/29092181-47f6a9e6-7c3a-11e7-9a14-1928d8a711cd.png">
|
||||
|
||||
#### Web Browser
|
||||
|
||||
Colors are also enabled on "Web Inspectors" that understand the `%c` formatting
|
||||
option. These are WebKit web inspectors, Firefox ([since version
|
||||
31](https://hacks.mozilla.org/2014/05/editable-box-model-multiple-selection-sublime-text-keys-much-more-firefox-developer-tools-episode-31/))
|
||||
and the Firebug plugin for Firefox (any version).
|
||||
|
||||
<img width="524" src="https://user-images.githubusercontent.com/71256/29092033-b65f9f2e-7c39-11e7-8e32-f6f0d8e865c1.png">
|
||||
|
||||
|
||||
## Millisecond diff
|
||||
|
||||
When actively developing an application it can be useful to see when the time spent between one `debug()` call and the next. Suppose for example you invoke `debug()` before requesting a resource, and after as well, the "+NNNms" will show you how much time was spent between calls.
|
||||
|
||||
<img width="647" src="https://user-images.githubusercontent.com/71256/29091486-fa38524c-7c37-11e7-895f-e7ec8e1039b6.png">
|
||||
|
||||
When stdout is not a TTY, `Date#toISOString()` is used, making it more useful for logging the debug information as shown below:
|
||||
|
||||
<img width="647" src="https://user-images.githubusercontent.com/71256/29091956-6bd78372-7c39-11e7-8c55-c948396d6edd.png">
|
||||
|
||||
|
||||
## Conventions
|
||||
|
||||
If you're using this in one or more of your libraries, you _should_ use the name of your library so that developers may toggle debugging as desired without guessing names. If you have more than one debuggers you _should_ prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser". If you append a "*" to the end of your name, it will always be enabled regardless of the setting of the DEBUG environment variable. You can then use it for normal output as well as debug output.
|
||||
|
||||
## Wildcards
|
||||
|
||||
The `*` character may be used as a wildcard. Suppose for example your library has
|
||||
debuggers named "connect:bodyParser", "connect:compress", "connect:session",
|
||||
instead of listing all three with
|
||||
`DEBUG=connect:bodyParser,connect:compress,connect:session`, you may simply do
|
||||
`DEBUG=connect:*`, or to run everything using this module simply use `DEBUG=*`.
|
||||
|
||||
You can also exclude specific debuggers by prefixing them with a "-" character.
|
||||
For example, `DEBUG=*,-connect:*` would include all debuggers except those
|
||||
starting with "connect:".
|
||||
|
||||
## Environment Variables
|
||||
|
||||
When running through Node.js, you can set a few environment variables that will
|
||||
change the behavior of the debug logging:
|
||||
|
||||
| Name | Purpose |
|
||||
|-----------|-------------------------------------------------|
|
||||
| `DEBUG` | Enables/disables specific debugging namespaces. |
|
||||
| `DEBUG_HIDE_DATE` | Hide date from debug output (non-TTY). |
|
||||
| `DEBUG_COLORS`| Whether or not to use colors in the debug output. |
|
||||
| `DEBUG_DEPTH` | Object inspection depth. |
|
||||
| `DEBUG_SHOW_HIDDEN` | Shows hidden properties on inspected objects. |
|
||||
|
||||
|
||||
__Note:__ The environment variables beginning with `DEBUG_` end up being
|
||||
converted into an Options object that gets used with `%o`/`%O` formatters.
|
||||
See the Node.js documentation for
|
||||
[`util.inspect()`](https://nodejs.org/api/util.html#util_util_inspect_object_options)
|
||||
for the complete list.
|
||||
|
||||
## Formatters
|
||||
|
||||
Debug uses [printf-style](https://wikipedia.org/wiki/Printf_format_string) formatting.
|
||||
Below are the officially supported formatters:
|
||||
|
||||
| Formatter | Representation |
|
||||
|-----------|----------------|
|
||||
| `%O` | Pretty-print an Object on multiple lines. |
|
||||
| `%o` | Pretty-print an Object all on a single line. |
|
||||
| `%s` | String. |
|
||||
| `%d` | Number (both integer and float). |
|
||||
| `%j` | JSON. Replaced with the string '[Circular]' if the argument contains circular references. |
|
||||
| `%%` | Single percent sign ('%'). This does not consume an argument. |
|
||||
|
||||
|
||||
### Custom formatters
|
||||
|
||||
You can add custom formatters by extending the `debug.formatters` object.
|
||||
For example, if you wanted to add support for rendering a Buffer as hex with
|
||||
`%h`, you could do something like:
|
||||
|
||||
```js
|
||||
const createDebug = require('debug')
|
||||
createDebug.formatters.h = (v) => {
|
||||
return v.toString('hex')
|
||||
}
|
||||
|
||||
// …elsewhere
|
||||
const debug = createDebug('foo')
|
||||
debug('this is hex: %h', new Buffer('hello world'))
|
||||
// foo this is hex: 68656c6c6f20776f726c6421 +0ms
|
||||
```
|
||||
|
||||
|
||||
## Browser Support
|
||||
|
||||
You can build a browser-ready script using [browserify](https://github.com/substack/node-browserify),
|
||||
or just use the [browserify-as-a-service](https://wzrd.in/) [build](https://wzrd.in/standalone/debug@latest),
|
||||
if you don't want to build it yourself.
|
||||
|
||||
Debug's enable state is currently persisted by `localStorage`.
|
||||
Consider the situation shown below where you have `worker:a` and `worker:b`,
|
||||
and wish to debug both. You can enable this using `localStorage.debug`:
|
||||
|
||||
```js
|
||||
localStorage.debug = 'worker:*'
|
||||
```
|
||||
|
||||
And then refresh the page.
|
||||
|
||||
```js
|
||||
a = debug('worker:a');
|
||||
b = debug('worker:b');
|
||||
|
||||
setInterval(function(){
|
||||
a('doing some work');
|
||||
}, 1000);
|
||||
|
||||
setInterval(function(){
|
||||
b('doing some work');
|
||||
}, 1200);
|
||||
```
|
||||
|
||||
|
||||
## Output streams
|
||||
|
||||
By default `debug` will log to stderr, however this can be configured per-namespace by overriding the `log` method:
|
||||
|
||||
Example [_stdout.js_](./examples/node/stdout.js):
|
||||
|
||||
```js
|
||||
var debug = require('debug');
|
||||
var error = debug('app:error');
|
||||
|
||||
// by default stderr is used
|
||||
error('goes to stderr!');
|
||||
|
||||
var log = debug('app:log');
|
||||
// set this namespace to log via console.log
|
||||
log.log = console.log.bind(console); // don't forget to bind to console!
|
||||
log('goes to stdout');
|
||||
error('still goes to stderr!');
|
||||
|
||||
// set all output to go via console.info
|
||||
// overrides all per-namespace log settings
|
||||
debug.log = console.info.bind(console);
|
||||
error('now goes to stdout via console.info');
|
||||
log('still goes to stdout, but via console.info now');
|
||||
```
|
||||
|
||||
## Extend
|
||||
You can simply extend debugger
|
||||
```js
|
||||
const log = require('debug')('auth');
|
||||
|
||||
//creates new debug instance with extended namespace
|
||||
const logSign = log.extend('sign');
|
||||
const logLogin = log.extend('login');
|
||||
|
||||
log('hello'); // auth hello
|
||||
logSign('hello'); //auth:sign hello
|
||||
logLogin('hello'); //auth:login hello
|
||||
```
|
||||
|
||||
## Set dynamically
|
||||
|
||||
You can also enable debug dynamically by calling the `enable()` method :
|
||||
|
||||
```js
|
||||
let debug = require('debug');
|
||||
|
||||
console.log(1, debug.enabled('test'));
|
||||
|
||||
debug.enable('test');
|
||||
console.log(2, debug.enabled('test'));
|
||||
|
||||
debug.disable();
|
||||
console.log(3, debug.enabled('test'));
|
||||
|
||||
```
|
||||
|
||||
print :
|
||||
```
|
||||
1 false
|
||||
2 true
|
||||
3 false
|
||||
```
|
||||
|
||||
Usage :
|
||||
`enable(namespaces)`
|
||||
`namespaces` can include modes separated by a colon and wildcards.
|
||||
|
||||
Note that calling `enable()` completely overrides previously set DEBUG variable :
|
||||
|
||||
```
|
||||
$ DEBUG=foo node -e 'var dbg = require("debug"); dbg.enable("bar"); console.log(dbg.enabled("foo"))'
|
||||
=> false
|
||||
```
|
||||
|
||||
`disable()`
|
||||
|
||||
Will disable all namespaces. The functions returns the namespaces currently
|
||||
enabled (and skipped). This can be useful if you want to disable debugging
|
||||
temporarily without knowing what was enabled to begin with.
|
||||
|
||||
For example:
|
||||
|
||||
```js
|
||||
let debug = require('debug');
|
||||
debug.enable('foo:*,-foo:bar');
|
||||
let namespaces = debug.disable();
|
||||
debug.enable(namespaces);
|
||||
```
|
||||
|
||||
Note: There is no guarantee that the string will be identical to the initial
|
||||
enable string, but semantically they will be identical.
|
||||
|
||||
## Checking whether a debug target is enabled
|
||||
|
||||
After you've created a debug instance, you can determine whether or not it is
|
||||
enabled by checking the `enabled` property:
|
||||
|
||||
```javascript
|
||||
const debug = require('debug')('http');
|
||||
|
||||
if (debug.enabled) {
|
||||
// do stuff...
|
||||
}
|
||||
```
|
||||
|
||||
You can also manually toggle this property to force the debug instance to be
|
||||
enabled or disabled.
|
||||
|
||||
|
||||
## Authors
|
||||
|
||||
- TJ Holowaychuk
|
||||
- Nathan Rajlich
|
||||
- Andrew Rhyne
|
||||
|
||||
## Backers
|
||||
|
||||
Support us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/debug#backer)]
|
||||
|
||||
<a href="https://opencollective.com/debug/backer/0/website" target="_blank"><img src="https://opencollective.com/debug/backer/0/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/1/website" target="_blank"><img src="https://opencollective.com/debug/backer/1/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/2/website" target="_blank"><img src="https://opencollective.com/debug/backer/2/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/3/website" target="_blank"><img src="https://opencollective.com/debug/backer/3/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/4/website" target="_blank"><img src="https://opencollective.com/debug/backer/4/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/5/website" target="_blank"><img src="https://opencollective.com/debug/backer/5/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/6/website" target="_blank"><img src="https://opencollective.com/debug/backer/6/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/7/website" target="_blank"><img src="https://opencollective.com/debug/backer/7/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/8/website" target="_blank"><img src="https://opencollective.com/debug/backer/8/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/9/website" target="_blank"><img src="https://opencollective.com/debug/backer/9/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/10/website" target="_blank"><img src="https://opencollective.com/debug/backer/10/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/11/website" target="_blank"><img src="https://opencollective.com/debug/backer/11/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/12/website" target="_blank"><img src="https://opencollective.com/debug/backer/12/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/13/website" target="_blank"><img src="https://opencollective.com/debug/backer/13/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/14/website" target="_blank"><img src="https://opencollective.com/debug/backer/14/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/15/website" target="_blank"><img src="https://opencollective.com/debug/backer/15/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/16/website" target="_blank"><img src="https://opencollective.com/debug/backer/16/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/17/website" target="_blank"><img src="https://opencollective.com/debug/backer/17/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/18/website" target="_blank"><img src="https://opencollective.com/debug/backer/18/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/19/website" target="_blank"><img src="https://opencollective.com/debug/backer/19/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/20/website" target="_blank"><img src="https://opencollective.com/debug/backer/20/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/21/website" target="_blank"><img src="https://opencollective.com/debug/backer/21/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/22/website" target="_blank"><img src="https://opencollective.com/debug/backer/22/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/23/website" target="_blank"><img src="https://opencollective.com/debug/backer/23/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/24/website" target="_blank"><img src="https://opencollective.com/debug/backer/24/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/25/website" target="_blank"><img src="https://opencollective.com/debug/backer/25/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/26/website" target="_blank"><img src="https://opencollective.com/debug/backer/26/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/27/website" target="_blank"><img src="https://opencollective.com/debug/backer/27/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/28/website" target="_blank"><img src="https://opencollective.com/debug/backer/28/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/backer/29/website" target="_blank"><img src="https://opencollective.com/debug/backer/29/avatar.svg"></a>
|
||||
|
||||
|
||||
## Sponsors
|
||||
|
||||
Become a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://opencollective.com/debug#sponsor)]
|
||||
|
||||
<a href="https://opencollective.com/debug/sponsor/0/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/0/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/1/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/1/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/2/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/2/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/3/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/3/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/4/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/4/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/5/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/5/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/6/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/6/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/7/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/7/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/8/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/8/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/9/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/9/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/10/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/10/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/11/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/11/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/12/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/12/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/13/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/13/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/14/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/14/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/15/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/15/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/16/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/16/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/17/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/17/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/18/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/18/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/19/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/19/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/20/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/20/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/21/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/21/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/22/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/22/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/23/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/23/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/24/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/24/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/25/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/25/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/26/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/26/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/27/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/27/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/28/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/28/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/debug/sponsor/29/website" target="_blank"><img src="https://opencollective.com/debug/sponsor/29/avatar.svg"></a>
|
||||
|
||||
## License
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2014-2017 TJ Holowaychuk <tj@vision-media.ca>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
162
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/node_modules/ms/index.js
generated
vendored
Normal file
162
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/node_modules/ms/index.js
generated
vendored
Normal file
@ -0,0 +1,162 @@
|
||||
/**
|
||||
* Helpers.
|
||||
*/
|
||||
|
||||
var s = 1000;
|
||||
var m = s * 60;
|
||||
var h = m * 60;
|
||||
var d = h * 24;
|
||||
var w = d * 7;
|
||||
var y = d * 365.25;
|
||||
|
||||
/**
|
||||
* Parse or format the given `val`.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - `long` verbose formatting [false]
|
||||
*
|
||||
* @param {String|Number} val
|
||||
* @param {Object} [options]
|
||||
* @throws {Error} throw an error if val is not a non-empty string or a number
|
||||
* @return {String|Number}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
module.exports = function(val, options) {
|
||||
options = options || {};
|
||||
var type = typeof val;
|
||||
if (type === 'string' && val.length > 0) {
|
||||
return parse(val);
|
||||
} else if (type === 'number' && isFinite(val)) {
|
||||
return options.long ? fmtLong(val) : fmtShort(val);
|
||||
}
|
||||
throw new Error(
|
||||
'val is not a non-empty string or a valid number. val=' +
|
||||
JSON.stringify(val)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse the given `str` and return milliseconds.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Number}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function parse(str) {
|
||||
str = String(str);
|
||||
if (str.length > 100) {
|
||||
return;
|
||||
}
|
||||
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
||||
str
|
||||
);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
var n = parseFloat(match[1]);
|
||||
var type = (match[2] || 'ms').toLowerCase();
|
||||
switch (type) {
|
||||
case 'years':
|
||||
case 'year':
|
||||
case 'yrs':
|
||||
case 'yr':
|
||||
case 'y':
|
||||
return n * y;
|
||||
case 'weeks':
|
||||
case 'week':
|
||||
case 'w':
|
||||
return n * w;
|
||||
case 'days':
|
||||
case 'day':
|
||||
case 'd':
|
||||
return n * d;
|
||||
case 'hours':
|
||||
case 'hour':
|
||||
case 'hrs':
|
||||
case 'hr':
|
||||
case 'h':
|
||||
return n * h;
|
||||
case 'minutes':
|
||||
case 'minute':
|
||||
case 'mins':
|
||||
case 'min':
|
||||
case 'm':
|
||||
return n * m;
|
||||
case 'seconds':
|
||||
case 'second':
|
||||
case 'secs':
|
||||
case 'sec':
|
||||
case 's':
|
||||
return n * s;
|
||||
case 'milliseconds':
|
||||
case 'millisecond':
|
||||
case 'msecs':
|
||||
case 'msec':
|
||||
case 'ms':
|
||||
return n;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Short format for `ms`.
|
||||
*
|
||||
* @param {Number} ms
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function fmtShort(ms) {
|
||||
var msAbs = Math.abs(ms);
|
||||
if (msAbs >= d) {
|
||||
return Math.round(ms / d) + 'd';
|
||||
}
|
||||
if (msAbs >= h) {
|
||||
return Math.round(ms / h) + 'h';
|
||||
}
|
||||
if (msAbs >= m) {
|
||||
return Math.round(ms / m) + 'm';
|
||||
}
|
||||
if (msAbs >= s) {
|
||||
return Math.round(ms / s) + 's';
|
||||
}
|
||||
return ms + 'ms';
|
||||
}
|
||||
|
||||
/**
|
||||
* Long format for `ms`.
|
||||
*
|
||||
* @param {Number} ms
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function fmtLong(ms) {
|
||||
var msAbs = Math.abs(ms);
|
||||
if (msAbs >= d) {
|
||||
return plural(ms, msAbs, d, 'day');
|
||||
}
|
||||
if (msAbs >= h) {
|
||||
return plural(ms, msAbs, h, 'hour');
|
||||
}
|
||||
if (msAbs >= m) {
|
||||
return plural(ms, msAbs, m, 'minute');
|
||||
}
|
||||
if (msAbs >= s) {
|
||||
return plural(ms, msAbs, s, 'second');
|
||||
}
|
||||
return ms + ' ms';
|
||||
}
|
||||
|
||||
/**
|
||||
* Pluralization helper.
|
||||
*/
|
||||
|
||||
function plural(ms, msAbs, n, name) {
|
||||
var isPlural = msAbs >= n * 1.5;
|
||||
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
||||
}
|
||||
21
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/node_modules/ms/license.md
generated
vendored
Normal file
21
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/node_modules/ms/license.md
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Zeit, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
69
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/node_modules/ms/package.json
generated
vendored
Normal file
69
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/node_modules/ms/package.json
generated
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
{
|
||||
"_from": "ms@2.1.2",
|
||||
"_id": "ms@2.1.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
|
||||
"_location": "/mocha/debug/ms",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "ms@2.1.2",
|
||||
"name": "ms",
|
||||
"escapedName": "ms",
|
||||
"rawSpec": "2.1.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "2.1.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/mocha/debug"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"_shasum": "d09d1f357b443f493382a8eb3ccd183872ae6009",
|
||||
"_spec": "ms@2.1.2",
|
||||
"_where": "C:\\Files\\Repositories\\UoL\\CM2010 Software Design and Development\\Topic 4\\8.3.1\\node_modules\\mocha\\node_modules\\debug",
|
||||
"bugs": {
|
||||
"url": "https://github.com/zeit/ms/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "Tiny millisecond conversion utility",
|
||||
"devDependencies": {
|
||||
"eslint": "4.12.1",
|
||||
"expect.js": "0.3.1",
|
||||
"husky": "0.14.3",
|
||||
"lint-staged": "5.0.0",
|
||||
"mocha": "4.0.1"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "eslint:recommended",
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/zeit/ms#readme",
|
||||
"license": "MIT",
|
||||
"lint-staged": {
|
||||
"*.js": [
|
||||
"npm run lint",
|
||||
"prettier --single-quote --write",
|
||||
"git add"
|
||||
]
|
||||
},
|
||||
"main": "./index",
|
||||
"name": "ms",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/zeit/ms.git"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint lib/* bin/*",
|
||||
"precommit": "lint-staged",
|
||||
"test": "mocha tests.js"
|
||||
},
|
||||
"version": "2.1.2"
|
||||
}
|
||||
60
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/node_modules/ms/readme.md
generated
vendored
Normal file
60
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/node_modules/ms/readme.md
generated
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
# ms
|
||||
|
||||
[](https://travis-ci.org/zeit/ms)
|
||||
[](https://spectrum.chat/zeit)
|
||||
|
||||
Use this package to easily convert various time formats to milliseconds.
|
||||
|
||||
## Examples
|
||||
|
||||
```js
|
||||
ms('2 days') // 172800000
|
||||
ms('1d') // 86400000
|
||||
ms('10h') // 36000000
|
||||
ms('2.5 hrs') // 9000000
|
||||
ms('2h') // 7200000
|
||||
ms('1m') // 60000
|
||||
ms('5s') // 5000
|
||||
ms('1y') // 31557600000
|
||||
ms('100') // 100
|
||||
ms('-3 days') // -259200000
|
||||
ms('-1h') // -3600000
|
||||
ms('-200') // -200
|
||||
```
|
||||
|
||||
### Convert from Milliseconds
|
||||
|
||||
```js
|
||||
ms(60000) // "1m"
|
||||
ms(2 * 60000) // "2m"
|
||||
ms(-3 * 60000) // "-3m"
|
||||
ms(ms('10 hours')) // "10h"
|
||||
```
|
||||
|
||||
### Time Format Written-Out
|
||||
|
||||
```js
|
||||
ms(60000, { long: true }) // "1 minute"
|
||||
ms(2 * 60000, { long: true }) // "2 minutes"
|
||||
ms(-3 * 60000, { long: true }) // "-3 minutes"
|
||||
ms(ms('10 hours'), { long: true }) // "10 hours"
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- Works both in [Node.js](https://nodejs.org) and in the browser
|
||||
- If a number is supplied to `ms`, a string with a unit is returned
|
||||
- If a string that contains the number is supplied, it returns it as a number (e.g.: it returns `100` for `'100'`)
|
||||
- If you pass a string with a number and a valid unit, the number of equivalent milliseconds is returned
|
||||
|
||||
## Related Packages
|
||||
|
||||
- [ms.macro](https://github.com/knpwrs/ms.macro) - Run `ms` as a macro at build-time.
|
||||
|
||||
## Caught a Bug?
|
||||
|
||||
1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device
|
||||
2. Link the package to the global module directory: `npm link`
|
||||
3. Within the module you want to test your local development instance of ms, just link it to the dependencies: `npm link ms`. Instead of the default one from npm, Node.js will now use your clone of ms!
|
||||
|
||||
As always, you can run the tests using: `npm test`
|
||||
101
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/package.json
generated
vendored
Normal file
101
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/package.json
generated
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
{
|
||||
"_from": "debug@4.3.1",
|
||||
"_id": "debug@4.3.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==",
|
||||
"_location": "/mocha/debug",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "debug@4.3.1",
|
||||
"name": "debug",
|
||||
"escapedName": "debug",
|
||||
"rawSpec": "4.3.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "4.3.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/mocha"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz",
|
||||
"_shasum": "f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee",
|
||||
"_spec": "debug@4.3.1",
|
||||
"_where": "C:\\Files\\Repositories\\UoL\\CM2010 Software Design and Development\\Topic 4\\8.3.1\\node_modules\\mocha",
|
||||
"author": {
|
||||
"name": "TJ Holowaychuk",
|
||||
"email": "tj@vision-media.ca"
|
||||
},
|
||||
"browser": "./src/browser.js",
|
||||
"bugs": {
|
||||
"url": "https://github.com/visionmedia/debug/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Nathan Rajlich",
|
||||
"email": "nathan@tootallnate.net",
|
||||
"url": "http://n8.io"
|
||||
},
|
||||
{
|
||||
"name": "Andrew Rhyne",
|
||||
"email": "rhyneandrew@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Josh Junon",
|
||||
"email": "josh@junon.me"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"ms": "2.1.2"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "small debugging utility",
|
||||
"devDependencies": {
|
||||
"brfs": "^2.0.1",
|
||||
"browserify": "^16.2.3",
|
||||
"coveralls": "^3.0.2",
|
||||
"istanbul": "^0.4.5",
|
||||
"karma": "^3.1.4",
|
||||
"karma-browserify": "^6.0.0",
|
||||
"karma-chrome-launcher": "^2.2.0",
|
||||
"karma-mocha": "^1.3.0",
|
||||
"mocha": "^5.2.0",
|
||||
"mocha-lcov-reporter": "^1.2.0",
|
||||
"xo": "^0.23.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.0"
|
||||
},
|
||||
"files": [
|
||||
"src",
|
||||
"LICENSE",
|
||||
"README.md"
|
||||
],
|
||||
"homepage": "https://github.com/visionmedia/debug#readme",
|
||||
"keywords": [
|
||||
"debug",
|
||||
"log",
|
||||
"debugger"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./src/index.js",
|
||||
"name": "debug",
|
||||
"peerDependenciesMeta": {
|
||||
"supports-color": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/visionmedia/debug.git"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "xo",
|
||||
"test": "npm run test:node && npm run test:browser && npm run lint",
|
||||
"test:browser": "karma start --single-run",
|
||||
"test:coverage": "cat ./coverage/lcov.info | coveralls",
|
||||
"test:node": "istanbul cover _mocha -- test.js"
|
||||
},
|
||||
"version": "4.3.1"
|
||||
}
|
||||
269
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/src/browser.js
generated
vendored
Normal file
269
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/src/browser.js
generated
vendored
Normal file
@ -0,0 +1,269 @@
|
||||
/* eslint-env browser */
|
||||
|
||||
/**
|
||||
* This is the web browser implementation of `debug()`.
|
||||
*/
|
||||
|
||||
exports.formatArgs = formatArgs;
|
||||
exports.save = save;
|
||||
exports.load = load;
|
||||
exports.useColors = useColors;
|
||||
exports.storage = localstorage();
|
||||
exports.destroy = (() => {
|
||||
let warned = false;
|
||||
|
||||
return () => {
|
||||
if (!warned) {
|
||||
warned = true;
|
||||
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
/**
|
||||
* Colors.
|
||||
*/
|
||||
|
||||
exports.colors = [
|
||||
'#0000CC',
|
||||
'#0000FF',
|
||||
'#0033CC',
|
||||
'#0033FF',
|
||||
'#0066CC',
|
||||
'#0066FF',
|
||||
'#0099CC',
|
||||
'#0099FF',
|
||||
'#00CC00',
|
||||
'#00CC33',
|
||||
'#00CC66',
|
||||
'#00CC99',
|
||||
'#00CCCC',
|
||||
'#00CCFF',
|
||||
'#3300CC',
|
||||
'#3300FF',
|
||||
'#3333CC',
|
||||
'#3333FF',
|
||||
'#3366CC',
|
||||
'#3366FF',
|
||||
'#3399CC',
|
||||
'#3399FF',
|
||||
'#33CC00',
|
||||
'#33CC33',
|
||||
'#33CC66',
|
||||
'#33CC99',
|
||||
'#33CCCC',
|
||||
'#33CCFF',
|
||||
'#6600CC',
|
||||
'#6600FF',
|
||||
'#6633CC',
|
||||
'#6633FF',
|
||||
'#66CC00',
|
||||
'#66CC33',
|
||||
'#9900CC',
|
||||
'#9900FF',
|
||||
'#9933CC',
|
||||
'#9933FF',
|
||||
'#99CC00',
|
||||
'#99CC33',
|
||||
'#CC0000',
|
||||
'#CC0033',
|
||||
'#CC0066',
|
||||
'#CC0099',
|
||||
'#CC00CC',
|
||||
'#CC00FF',
|
||||
'#CC3300',
|
||||
'#CC3333',
|
||||
'#CC3366',
|
||||
'#CC3399',
|
||||
'#CC33CC',
|
||||
'#CC33FF',
|
||||
'#CC6600',
|
||||
'#CC6633',
|
||||
'#CC9900',
|
||||
'#CC9933',
|
||||
'#CCCC00',
|
||||
'#CCCC33',
|
||||
'#FF0000',
|
||||
'#FF0033',
|
||||
'#FF0066',
|
||||
'#FF0099',
|
||||
'#FF00CC',
|
||||
'#FF00FF',
|
||||
'#FF3300',
|
||||
'#FF3333',
|
||||
'#FF3366',
|
||||
'#FF3399',
|
||||
'#FF33CC',
|
||||
'#FF33FF',
|
||||
'#FF6600',
|
||||
'#FF6633',
|
||||
'#FF9900',
|
||||
'#FF9933',
|
||||
'#FFCC00',
|
||||
'#FFCC33'
|
||||
];
|
||||
|
||||
/**
|
||||
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
||||
* and the Firebug extension (any Firefox version) are known
|
||||
* to support "%c" CSS customizations.
|
||||
*
|
||||
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
function useColors() {
|
||||
// NB: In an Electron preload script, document will be defined but not fully
|
||||
// initialized. Since we know we're in Chrome, we'll just detect this case
|
||||
// explicitly
|
||||
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Internet Explorer and Edge do not support colors.
|
||||
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is webkit? http://stackoverflow.com/a/16459606/376773
|
||||
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
||||
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
||||
// Is firebug? http://stackoverflow.com/a/398120/376773
|
||||
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
||||
// Is firefox >= v31?
|
||||
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
||||
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
|
||||
// Double check webkit in userAgent just in case we are in a worker
|
||||
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
|
||||
}
|
||||
|
||||
/**
|
||||
* Colorize log arguments if enabled.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function formatArgs(args) {
|
||||
args[0] = (this.useColors ? '%c' : '') +
|
||||
this.namespace +
|
||||
(this.useColors ? ' %c' : ' ') +
|
||||
args[0] +
|
||||
(this.useColors ? '%c ' : ' ') +
|
||||
'+' + module.exports.humanize(this.diff);
|
||||
|
||||
if (!this.useColors) {
|
||||
return;
|
||||
}
|
||||
|
||||
const c = 'color: ' + this.color;
|
||||
args.splice(1, 0, c, 'color: inherit');
|
||||
|
||||
// The final "%c" is somewhat tricky, because there could be other
|
||||
// arguments passed either before or after the %c, so we need to
|
||||
// figure out the correct index to insert the CSS into
|
||||
let index = 0;
|
||||
let lastC = 0;
|
||||
args[0].replace(/%[a-zA-Z%]/g, match => {
|
||||
if (match === '%%') {
|
||||
return;
|
||||
}
|
||||
index++;
|
||||
if (match === '%c') {
|
||||
// We only are interested in the *last* %c
|
||||
// (the user may have provided their own)
|
||||
lastC = index;
|
||||
}
|
||||
});
|
||||
|
||||
args.splice(lastC, 0, c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes `console.debug()` when available.
|
||||
* No-op when `console.debug` is not a "function".
|
||||
* If `console.debug` is not available, falls back
|
||||
* to `console.log`.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
exports.log = console.debug || console.log || (() => {});
|
||||
|
||||
/**
|
||||
* Save `namespaces`.
|
||||
*
|
||||
* @param {String} namespaces
|
||||
* @api private
|
||||
*/
|
||||
function save(namespaces) {
|
||||
try {
|
||||
if (namespaces) {
|
||||
exports.storage.setItem('debug', namespaces);
|
||||
} else {
|
||||
exports.storage.removeItem('debug');
|
||||
}
|
||||
} catch (error) {
|
||||
// Swallow
|
||||
// XXX (@Qix-) should we be logging these?
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load `namespaces`.
|
||||
*
|
||||
* @return {String} returns the previously persisted debug modes
|
||||
* @api private
|
||||
*/
|
||||
function load() {
|
||||
let r;
|
||||
try {
|
||||
r = exports.storage.getItem('debug');
|
||||
} catch (error) {
|
||||
// Swallow
|
||||
// XXX (@Qix-) should we be logging these?
|
||||
}
|
||||
|
||||
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
||||
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
||||
r = process.env.DEBUG;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Localstorage attempts to return the localstorage.
|
||||
*
|
||||
* This is necessary because safari throws
|
||||
* when a user disables cookies/localstorage
|
||||
* and you attempt to access it.
|
||||
*
|
||||
* @return {LocalStorage}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function localstorage() {
|
||||
try {
|
||||
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
|
||||
// The Browser also has localStorage in the global context.
|
||||
return localStorage;
|
||||
} catch (error) {
|
||||
// Swallow
|
||||
// XXX (@Qix-) should we be logging these?
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = require('./common')(exports);
|
||||
|
||||
const {formatters} = module.exports;
|
||||
|
||||
/**
|
||||
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
||||
*/
|
||||
|
||||
formatters.j = function (v) {
|
||||
try {
|
||||
return JSON.stringify(v);
|
||||
} catch (error) {
|
||||
return '[UnexpectedJSONParseError]: ' + error.message;
|
||||
}
|
||||
};
|
||||
261
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/src/common.js
generated
vendored
Normal file
261
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/src/common.js
generated
vendored
Normal file
@ -0,0 +1,261 @@
|
||||
|
||||
/**
|
||||
* This is the common logic for both the Node.js and web browser
|
||||
* implementations of `debug()`.
|
||||
*/
|
||||
|
||||
function setup(env) {
|
||||
createDebug.debug = createDebug;
|
||||
createDebug.default = createDebug;
|
||||
createDebug.coerce = coerce;
|
||||
createDebug.disable = disable;
|
||||
createDebug.enable = enable;
|
||||
createDebug.enabled = enabled;
|
||||
createDebug.humanize = require('ms');
|
||||
createDebug.destroy = destroy;
|
||||
|
||||
Object.keys(env).forEach(key => {
|
||||
createDebug[key] = env[key];
|
||||
});
|
||||
|
||||
/**
|
||||
* The currently active debug mode names, and names to skip.
|
||||
*/
|
||||
|
||||
createDebug.names = [];
|
||||
createDebug.skips = [];
|
||||
|
||||
/**
|
||||
* Map of special "%n" handling functions, for the debug "format" argument.
|
||||
*
|
||||
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
||||
*/
|
||||
createDebug.formatters = {};
|
||||
|
||||
/**
|
||||
* Selects a color for a debug namespace
|
||||
* @param {String} namespace The namespace string for the for the debug instance to be colored
|
||||
* @return {Number|String} An ANSI color code for the given namespace
|
||||
* @api private
|
||||
*/
|
||||
function selectColor(namespace) {
|
||||
let hash = 0;
|
||||
|
||||
for (let i = 0; i < namespace.length; i++) {
|
||||
hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
|
||||
hash |= 0; // Convert to 32bit integer
|
||||
}
|
||||
|
||||
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
||||
}
|
||||
createDebug.selectColor = selectColor;
|
||||
|
||||
/**
|
||||
* Create a debugger with the given `namespace`.
|
||||
*
|
||||
* @param {String} namespace
|
||||
* @return {Function}
|
||||
* @api public
|
||||
*/
|
||||
function createDebug(namespace) {
|
||||
let prevTime;
|
||||
let enableOverride = null;
|
||||
|
||||
function debug(...args) {
|
||||
// Disabled?
|
||||
if (!debug.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
const self = debug;
|
||||
|
||||
// Set `diff` timestamp
|
||||
const curr = Number(new Date());
|
||||
const ms = curr - (prevTime || curr);
|
||||
self.diff = ms;
|
||||
self.prev = prevTime;
|
||||
self.curr = curr;
|
||||
prevTime = curr;
|
||||
|
||||
args[0] = createDebug.coerce(args[0]);
|
||||
|
||||
if (typeof args[0] !== 'string') {
|
||||
// Anything else let's inspect with %O
|
||||
args.unshift('%O');
|
||||
}
|
||||
|
||||
// Apply any `formatters` transformations
|
||||
let index = 0;
|
||||
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
||||
// If we encounter an escaped % then don't increase the array index
|
||||
if (match === '%%') {
|
||||
return '%';
|
||||
}
|
||||
index++;
|
||||
const formatter = createDebug.formatters[format];
|
||||
if (typeof formatter === 'function') {
|
||||
const val = args[index];
|
||||
match = formatter.call(self, val);
|
||||
|
||||
// Now we need to remove `args[index]` since it's inlined in the `format`
|
||||
args.splice(index, 1);
|
||||
index--;
|
||||
}
|
||||
return match;
|
||||
});
|
||||
|
||||
// Apply env-specific formatting (colors, etc.)
|
||||
createDebug.formatArgs.call(self, args);
|
||||
|
||||
const logFn = self.log || createDebug.log;
|
||||
logFn.apply(self, args);
|
||||
}
|
||||
|
||||
debug.namespace = namespace;
|
||||
debug.useColors = createDebug.useColors();
|
||||
debug.color = createDebug.selectColor(namespace);
|
||||
debug.extend = extend;
|
||||
debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
|
||||
|
||||
Object.defineProperty(debug, 'enabled', {
|
||||
enumerable: true,
|
||||
configurable: false,
|
||||
get: () => enableOverride === null ? createDebug.enabled(namespace) : enableOverride,
|
||||
set: v => {
|
||||
enableOverride = v;
|
||||
}
|
||||
});
|
||||
|
||||
// Env-specific initialization logic for debug instances
|
||||
if (typeof createDebug.init === 'function') {
|
||||
createDebug.init(debug);
|
||||
}
|
||||
|
||||
return debug;
|
||||
}
|
||||
|
||||
function extend(namespace, delimiter) {
|
||||
const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
||||
newDebug.log = this.log;
|
||||
return newDebug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables a debug mode by namespaces. This can include modes
|
||||
* separated by a colon and wildcards.
|
||||
*
|
||||
* @param {String} namespaces
|
||||
* @api public
|
||||
*/
|
||||
function enable(namespaces) {
|
||||
createDebug.save(namespaces);
|
||||
|
||||
createDebug.names = [];
|
||||
createDebug.skips = [];
|
||||
|
||||
let i;
|
||||
const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
||||
const len = split.length;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if (!split[i]) {
|
||||
// ignore empty strings
|
||||
continue;
|
||||
}
|
||||
|
||||
namespaces = split[i].replace(/\*/g, '.*?');
|
||||
|
||||
if (namespaces[0] === '-') {
|
||||
createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
||||
} else {
|
||||
createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable debug output.
|
||||
*
|
||||
* @return {String} namespaces
|
||||
* @api public
|
||||
*/
|
||||
function disable() {
|
||||
const namespaces = [
|
||||
...createDebug.names.map(toNamespace),
|
||||
...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
|
||||
].join(',');
|
||||
createDebug.enable('');
|
||||
return namespaces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given mode name is enabled, false otherwise.
|
||||
*
|
||||
* @param {String} name
|
||||
* @return {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
function enabled(name) {
|
||||
if (name[name.length - 1] === '*') {
|
||||
return true;
|
||||
}
|
||||
|
||||
let i;
|
||||
let len;
|
||||
|
||||
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
||||
if (createDebug.skips[i].test(name)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0, len = createDebug.names.length; i < len; i++) {
|
||||
if (createDebug.names[i].test(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert regexp to namespace
|
||||
*
|
||||
* @param {RegExp} regxep
|
||||
* @return {String} namespace
|
||||
* @api private
|
||||
*/
|
||||
function toNamespace(regexp) {
|
||||
return regexp.toString()
|
||||
.substring(2, regexp.toString().length - 2)
|
||||
.replace(/\.\*\?$/, '*');
|
||||
}
|
||||
|
||||
/**
|
||||
* Coerce `val`.
|
||||
*
|
||||
* @param {Mixed} val
|
||||
* @return {Mixed}
|
||||
* @api private
|
||||
*/
|
||||
function coerce(val) {
|
||||
if (val instanceof Error) {
|
||||
return val.stack || val.message;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* XXX DO NOT USE. This is a temporary stub function.
|
||||
* XXX It WILL be removed in the next major release.
|
||||
*/
|
||||
function destroy() {
|
||||
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
||||
}
|
||||
|
||||
createDebug.enable(createDebug.load());
|
||||
|
||||
return createDebug;
|
||||
}
|
||||
|
||||
module.exports = setup;
|
||||
10
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/src/index.js
generated
vendored
Normal file
10
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/src/index.js
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Detect Electron renderer / nwjs process, which is node, but we should
|
||||
* treat as a browser.
|
||||
*/
|
||||
|
||||
if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
|
||||
module.exports = require('./browser.js');
|
||||
} else {
|
||||
module.exports = require('./node.js');
|
||||
}
|
||||
263
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/src/node.js
generated
vendored
Normal file
263
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/debug/src/node.js
generated
vendored
Normal file
@ -0,0 +1,263 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
const tty = require('tty');
|
||||
const util = require('util');
|
||||
|
||||
/**
|
||||
* This is the Node.js implementation of `debug()`.
|
||||
*/
|
||||
|
||||
exports.init = init;
|
||||
exports.log = log;
|
||||
exports.formatArgs = formatArgs;
|
||||
exports.save = save;
|
||||
exports.load = load;
|
||||
exports.useColors = useColors;
|
||||
exports.destroy = util.deprecate(
|
||||
() => {},
|
||||
'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'
|
||||
);
|
||||
|
||||
/**
|
||||
* Colors.
|
||||
*/
|
||||
|
||||
exports.colors = [6, 2, 3, 4, 5, 1];
|
||||
|
||||
try {
|
||||
// Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
const supportsColor = require('supports-color');
|
||||
|
||||
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
|
||||
exports.colors = [
|
||||
20,
|
||||
21,
|
||||
26,
|
||||
27,
|
||||
32,
|
||||
33,
|
||||
38,
|
||||
39,
|
||||
40,
|
||||
41,
|
||||
42,
|
||||
43,
|
||||
44,
|
||||
45,
|
||||
56,
|
||||
57,
|
||||
62,
|
||||
63,
|
||||
68,
|
||||
69,
|
||||
74,
|
||||
75,
|
||||
76,
|
||||
77,
|
||||
78,
|
||||
79,
|
||||
80,
|
||||
81,
|
||||
92,
|
||||
93,
|
||||
98,
|
||||
99,
|
||||
112,
|
||||
113,
|
||||
128,
|
||||
129,
|
||||
134,
|
||||
135,
|
||||
148,
|
||||
149,
|
||||
160,
|
||||
161,
|
||||
162,
|
||||
163,
|
||||
164,
|
||||
165,
|
||||
166,
|
||||
167,
|
||||
168,
|
||||
169,
|
||||
170,
|
||||
171,
|
||||
172,
|
||||
173,
|
||||
178,
|
||||
179,
|
||||
184,
|
||||
185,
|
||||
196,
|
||||
197,
|
||||
198,
|
||||
199,
|
||||
200,
|
||||
201,
|
||||
202,
|
||||
203,
|
||||
204,
|
||||
205,
|
||||
206,
|
||||
207,
|
||||
208,
|
||||
209,
|
||||
214,
|
||||
215,
|
||||
220,
|
||||
221
|
||||
];
|
||||
}
|
||||
} catch (error) {
|
||||
// Swallow - we only care if `supports-color` is available; it doesn't have to be.
|
||||
}
|
||||
|
||||
/**
|
||||
* Build up the default `inspectOpts` object from the environment variables.
|
||||
*
|
||||
* $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
|
||||
*/
|
||||
|
||||
exports.inspectOpts = Object.keys(process.env).filter(key => {
|
||||
return /^debug_/i.test(key);
|
||||
}).reduce((obj, key) => {
|
||||
// Camel-case
|
||||
const prop = key
|
||||
.substring(6)
|
||||
.toLowerCase()
|
||||
.replace(/_([a-z])/g, (_, k) => {
|
||||
return k.toUpperCase();
|
||||
});
|
||||
|
||||
// Coerce string value into JS value
|
||||
let val = process.env[key];
|
||||
if (/^(yes|on|true|enabled)$/i.test(val)) {
|
||||
val = true;
|
||||
} else if (/^(no|off|false|disabled)$/i.test(val)) {
|
||||
val = false;
|
||||
} else if (val === 'null') {
|
||||
val = null;
|
||||
} else {
|
||||
val = Number(val);
|
||||
}
|
||||
|
||||
obj[prop] = val;
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
/**
|
||||
* Is stdout a TTY? Colored output is enabled when `true`.
|
||||
*/
|
||||
|
||||
function useColors() {
|
||||
return 'colors' in exports.inspectOpts ?
|
||||
Boolean(exports.inspectOpts.colors) :
|
||||
tty.isatty(process.stderr.fd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds ANSI color escape codes if enabled.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function formatArgs(args) {
|
||||
const {namespace: name, useColors} = this;
|
||||
|
||||
if (useColors) {
|
||||
const c = this.color;
|
||||
const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
|
||||
const prefix = ` ${colorCode};1m${name} \u001B[0m`;
|
||||
|
||||
args[0] = prefix + args[0].split('\n').join('\n' + prefix);
|
||||
args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
|
||||
} else {
|
||||
args[0] = getDate() + name + ' ' + args[0];
|
||||
}
|
||||
}
|
||||
|
||||
function getDate() {
|
||||
if (exports.inspectOpts.hideDate) {
|
||||
return '';
|
||||
}
|
||||
return new Date().toISOString() + ' ';
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes `util.format()` with the specified arguments and writes to stderr.
|
||||
*/
|
||||
|
||||
function log(...args) {
|
||||
return process.stderr.write(util.format(...args) + '\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save `namespaces`.
|
||||
*
|
||||
* @param {String} namespaces
|
||||
* @api private
|
||||
*/
|
||||
function save(namespaces) {
|
||||
if (namespaces) {
|
||||
process.env.DEBUG = namespaces;
|
||||
} else {
|
||||
// If you set a process.env field to null or undefined, it gets cast to the
|
||||
// string 'null' or 'undefined'. Just delete instead.
|
||||
delete process.env.DEBUG;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load `namespaces`.
|
||||
*
|
||||
* @return {String} returns the previously persisted debug modes
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function load() {
|
||||
return process.env.DEBUG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init logic for `debug` instances.
|
||||
*
|
||||
* Create a new `inspectOpts` object in case `useColors` is set
|
||||
* differently for a particular `debug` instance.
|
||||
*/
|
||||
|
||||
function init(debug) {
|
||||
debug.inspectOpts = {};
|
||||
|
||||
const keys = Object.keys(exports.inspectOpts);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = require('./common')(exports);
|
||||
|
||||
const {formatters} = module.exports;
|
||||
|
||||
/**
|
||||
* Map %o to `util.inspect()`, all on a single line.
|
||||
*/
|
||||
|
||||
formatters.o = function (v) {
|
||||
this.inspectOpts.colors = this.useColors;
|
||||
return util.inspect(v, this.inspectOpts)
|
||||
.split('\n')
|
||||
.map(str => str.trim())
|
||||
.join(' ');
|
||||
};
|
||||
|
||||
/**
|
||||
* Map %O to `util.inspect()`, allowing multiple lines if needed.
|
||||
*/
|
||||
|
||||
formatters.O = function (v) {
|
||||
this.inspectOpts.colors = this.useColors;
|
||||
return util.inspect(v, this.inspectOpts);
|
||||
};
|
||||
162
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/ms/index.js
generated
vendored
Normal file
162
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/ms/index.js
generated
vendored
Normal file
@ -0,0 +1,162 @@
|
||||
/**
|
||||
* Helpers.
|
||||
*/
|
||||
|
||||
var s = 1000;
|
||||
var m = s * 60;
|
||||
var h = m * 60;
|
||||
var d = h * 24;
|
||||
var w = d * 7;
|
||||
var y = d * 365.25;
|
||||
|
||||
/**
|
||||
* Parse or format the given `val`.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - `long` verbose formatting [false]
|
||||
*
|
||||
* @param {String|Number} val
|
||||
* @param {Object} [options]
|
||||
* @throws {Error} throw an error if val is not a non-empty string or a number
|
||||
* @return {String|Number}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
module.exports = function (val, options) {
|
||||
options = options || {};
|
||||
var type = typeof val;
|
||||
if (type === 'string' && val.length > 0) {
|
||||
return parse(val);
|
||||
} else if (type === 'number' && isFinite(val)) {
|
||||
return options.long ? fmtLong(val) : fmtShort(val);
|
||||
}
|
||||
throw new Error(
|
||||
'val is not a non-empty string or a valid number. val=' +
|
||||
JSON.stringify(val)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse the given `str` and return milliseconds.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {Number}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function parse(str) {
|
||||
str = String(str);
|
||||
if (str.length > 100) {
|
||||
return;
|
||||
}
|
||||
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
||||
str
|
||||
);
|
||||
if (!match) {
|
||||
return;
|
||||
}
|
||||
var n = parseFloat(match[1]);
|
||||
var type = (match[2] || 'ms').toLowerCase();
|
||||
switch (type) {
|
||||
case 'years':
|
||||
case 'year':
|
||||
case 'yrs':
|
||||
case 'yr':
|
||||
case 'y':
|
||||
return n * y;
|
||||
case 'weeks':
|
||||
case 'week':
|
||||
case 'w':
|
||||
return n * w;
|
||||
case 'days':
|
||||
case 'day':
|
||||
case 'd':
|
||||
return n * d;
|
||||
case 'hours':
|
||||
case 'hour':
|
||||
case 'hrs':
|
||||
case 'hr':
|
||||
case 'h':
|
||||
return n * h;
|
||||
case 'minutes':
|
||||
case 'minute':
|
||||
case 'mins':
|
||||
case 'min':
|
||||
case 'm':
|
||||
return n * m;
|
||||
case 'seconds':
|
||||
case 'second':
|
||||
case 'secs':
|
||||
case 'sec':
|
||||
case 's':
|
||||
return n * s;
|
||||
case 'milliseconds':
|
||||
case 'millisecond':
|
||||
case 'msecs':
|
||||
case 'msec':
|
||||
case 'ms':
|
||||
return n;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Short format for `ms`.
|
||||
*
|
||||
* @param {Number} ms
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function fmtShort(ms) {
|
||||
var msAbs = Math.abs(ms);
|
||||
if (msAbs >= d) {
|
||||
return Math.round(ms / d) + 'd';
|
||||
}
|
||||
if (msAbs >= h) {
|
||||
return Math.round(ms / h) + 'h';
|
||||
}
|
||||
if (msAbs >= m) {
|
||||
return Math.round(ms / m) + 'm';
|
||||
}
|
||||
if (msAbs >= s) {
|
||||
return Math.round(ms / s) + 's';
|
||||
}
|
||||
return ms + 'ms';
|
||||
}
|
||||
|
||||
/**
|
||||
* Long format for `ms`.
|
||||
*
|
||||
* @param {Number} ms
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function fmtLong(ms) {
|
||||
var msAbs = Math.abs(ms);
|
||||
if (msAbs >= d) {
|
||||
return plural(ms, msAbs, d, 'day');
|
||||
}
|
||||
if (msAbs >= h) {
|
||||
return plural(ms, msAbs, h, 'hour');
|
||||
}
|
||||
if (msAbs >= m) {
|
||||
return plural(ms, msAbs, m, 'minute');
|
||||
}
|
||||
if (msAbs >= s) {
|
||||
return plural(ms, msAbs, s, 'second');
|
||||
}
|
||||
return ms + ' ms';
|
||||
}
|
||||
|
||||
/**
|
||||
* Pluralization helper.
|
||||
*/
|
||||
|
||||
function plural(ms, msAbs, n, name) {
|
||||
var isPlural = msAbs >= n * 1.5;
|
||||
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
||||
}
|
||||
21
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/ms/license.md
generated
vendored
Normal file
21
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/ms/license.md
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020 Vercel, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
70
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/ms/package.json
generated
vendored
Normal file
70
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/ms/package.json
generated
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
{
|
||||
"_from": "ms@2.1.3",
|
||||
"_id": "ms@2.1.3",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||
"_location": "/mocha/ms",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "ms@2.1.3",
|
||||
"name": "ms",
|
||||
"escapedName": "ms",
|
||||
"rawSpec": "2.1.3",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "2.1.3"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/mocha"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
||||
"_shasum": "574c8138ce1d2b5861f0b44579dbadd60c6615b2",
|
||||
"_spec": "ms@2.1.3",
|
||||
"_where": "C:\\Files\\Repositories\\UoL\\CM2010 Software Design and Development\\Topic 4\\8.3.1\\node_modules\\mocha",
|
||||
"bugs": {
|
||||
"url": "https://github.com/vercel/ms/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "Tiny millisecond conversion utility",
|
||||
"devDependencies": {
|
||||
"eslint": "4.18.2",
|
||||
"expect.js": "0.3.1",
|
||||
"husky": "0.14.3",
|
||||
"lint-staged": "5.0.0",
|
||||
"mocha": "4.0.1",
|
||||
"prettier": "2.0.5"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "eslint:recommended",
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/vercel/ms#readme",
|
||||
"license": "MIT",
|
||||
"lint-staged": {
|
||||
"*.js": [
|
||||
"npm run lint",
|
||||
"prettier --single-quote --write",
|
||||
"git add"
|
||||
]
|
||||
},
|
||||
"main": "./index",
|
||||
"name": "ms",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vercel/ms.git"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint lib/* bin/*",
|
||||
"precommit": "lint-staged",
|
||||
"test": "mocha tests.js"
|
||||
},
|
||||
"version": "2.1.3"
|
||||
}
|
||||
59
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/ms/readme.md
generated
vendored
Normal file
59
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/node_modules/ms/readme.md
generated
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
# ms
|
||||
|
||||

|
||||
|
||||
Use this package to easily convert various time formats to milliseconds.
|
||||
|
||||
## Examples
|
||||
|
||||
```js
|
||||
ms('2 days') // 172800000
|
||||
ms('1d') // 86400000
|
||||
ms('10h') // 36000000
|
||||
ms('2.5 hrs') // 9000000
|
||||
ms('2h') // 7200000
|
||||
ms('1m') // 60000
|
||||
ms('5s') // 5000
|
||||
ms('1y') // 31557600000
|
||||
ms('100') // 100
|
||||
ms('-3 days') // -259200000
|
||||
ms('-1h') // -3600000
|
||||
ms('-200') // -200
|
||||
```
|
||||
|
||||
### Convert from Milliseconds
|
||||
|
||||
```js
|
||||
ms(60000) // "1m"
|
||||
ms(2 * 60000) // "2m"
|
||||
ms(-3 * 60000) // "-3m"
|
||||
ms(ms('10 hours')) // "10h"
|
||||
```
|
||||
|
||||
### Time Format Written-Out
|
||||
|
||||
```js
|
||||
ms(60000, { long: true }) // "1 minute"
|
||||
ms(2 * 60000, { long: true }) // "2 minutes"
|
||||
ms(-3 * 60000, { long: true }) // "-3 minutes"
|
||||
ms(ms('10 hours'), { long: true }) // "10 hours"
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- Works both in [Node.js](https://nodejs.org) and in the browser
|
||||
- If a number is supplied to `ms`, a string with a unit is returned
|
||||
- If a string that contains the number is supplied, it returns it as a number (e.g.: it returns `100` for `'100'`)
|
||||
- If you pass a string with a number and a valid unit, the number of equivalent milliseconds is returned
|
||||
|
||||
## Related Packages
|
||||
|
||||
- [ms.macro](https://github.com/knpwrs/ms.macro) - Run `ms` as a macro at build-time.
|
||||
|
||||
## Caught a Bug?
|
||||
|
||||
1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device
|
||||
2. Link the package to the global module directory: `npm link`
|
||||
3. Within the module you want to test your local development instance of ms, just link it to the dependencies: `npm link ms`. Instead of the default one from npm, Node.js will now use your clone of ms!
|
||||
|
||||
As always, you can run the tests using: `npm test`
|
||||
233
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/package.json
generated
vendored
Normal file
233
CM2010 Software Design and Development/Topic 2/8.3.1/node_modules/mocha/package.json
generated
vendored
Normal file
@ -0,0 +1,233 @@
|
||||
{
|
||||
"_from": "mocha",
|
||||
"_id": "mocha@9.0.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-GRGG/q9bIaUkHJB9NL+KZNjDhMBHB30zW3bZW9qOiYr+QChyLjPzswaxFWkI1q6lGlSL28EQYzAi2vKWNkPx+g==",
|
||||
"_location": "/mocha",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "mocha",
|
||||
"name": "mocha",
|
||||
"escapedName": "mocha",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/mocha/-/mocha-9.0.0.tgz",
|
||||
"_shasum": "67ce848170cb6426f9e84c57e38376dc9017bab4",
|
||||
"_spec": "mocha",
|
||||
"_where": "C:\\Files\\Repositories\\UoL\\CM2010 Software Design and Development\\Topic 4\\8.3.1",
|
||||
"author": {
|
||||
"name": "TJ Holowaychuk",
|
||||
"email": "tj@vision-media.ca"
|
||||
},
|
||||
"bin": {
|
||||
"mocha": "bin/mocha",
|
||||
"_mocha": "bin/_mocha"
|
||||
},
|
||||
"browser": {
|
||||
"./index.js": "./browser-entry.js",
|
||||
"./lib/nodejs/growl.js": "./lib/browser/growl.js",
|
||||
"./lib/esm-utils.js": false,
|
||||
"fs": false,
|
||||
"path": false,
|
||||
"supports-color": false,
|
||||
"./lib/nodejs/serializer.js": false,
|
||||
"./lib/nodejs/worker.js": false,
|
||||
"./lib/nodejs/buffered-worker-pool.js": false,
|
||||
"./lib/nodejs/parallel-buffered-runner.js": false,
|
||||
"./lib/nodejs/reporters/parallel-buffered.js": false,
|
||||
"./lib/nodejs/file-unloader.js": false,
|
||||
"./lib/cli/index.js": false
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/mochajs/mocha/issues/"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"@ungap/promise-all-settled": "1.1.2",
|
||||
"ansi-colors": "4.1.1",
|
||||
"browser-stdout": "1.3.1",
|
||||
"chokidar": "3.5.1",
|
||||
"debug": "4.3.1",
|
||||
"diff": "5.0.0",
|
||||
"escape-string-regexp": "4.0.0",
|
||||
"find-up": "5.0.0",
|
||||
"glob": "7.1.7",
|
||||
"growl": "1.10.5",
|
||||
"he": "1.2.0",
|
||||
"js-yaml": "4.1.0",
|
||||
"log-symbols": "4.1.0",
|
||||
"minimatch": "3.0.4",
|
||||
"ms": "2.1.3",
|
||||
"nanoid": "3.1.23",
|
||||
"serialize-javascript": "5.0.1",
|
||||
"strip-json-comments": "3.1.1",
|
||||
"supports-color": "8.1.1",
|
||||
"which": "2.0.2",
|
||||
"wide-align": "1.1.3",
|
||||
"workerpool": "6.1.4",
|
||||
"yargs": "16.2.0",
|
||||
"yargs-parser": "20.2.4",
|
||||
"yargs-unparser": "2.0.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "simple, flexible, fun test framework",
|
||||
"devDependencies": {
|
||||
"@11ty/eleventy": "^0.11.0",
|
||||
"@11ty/eleventy-plugin-inclusive-language": "^1.0.0",
|
||||
"@babel/plugin-transform-regenerator": "7.12.1",
|
||||
"@babel/preset-env": "7.12.17",
|
||||
"@babel/runtime": "7.12.5",
|
||||
"@mocha/docdash": "^3.0.1",
|
||||
"@rollup/plugin-babel": "^5.1.0",
|
||||
"@rollup/plugin-commonjs": "^14.0.0",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
"@rollup/plugin-multi-entry": "^3.0.1",
|
||||
"@rollup/plugin-node-resolve": "^8.4.0",
|
||||
"assetgraph-builder": "^8.1.0",
|
||||
"autoprefixer": "^9.8.6",
|
||||
"babel-eslint": "^10.1.0",
|
||||
"canvas": "^2.6.1",
|
||||
"chai": "^4.2.0",
|
||||
"coffee-script": "^1.12.7",
|
||||
"configstore": "^5.0.1",
|
||||
"core-js": "^3.6.5",
|
||||
"coveralls": "^3.1.0",
|
||||
"cross-env": "^7.0.2",
|
||||
"cross-spawn": "^7.0.3",
|
||||
"eslint": "^7.8.1",
|
||||
"eslint-config-prettier": "^6.11.0",
|
||||
"eslint-config-semistandard": "^15.0.1",
|
||||
"eslint-config-standard": "^14.1.1",
|
||||
"eslint-plugin-import": "^2.22.0",
|
||||
"eslint-plugin-node": "^11.0.0",
|
||||
"eslint-plugin-prettier": "^3.1.4",
|
||||
"eslint-plugin-promise": "^4.2.1",
|
||||
"eslint-plugin-standard": "^4.0.1",
|
||||
"fail-on-errors-webpack-plugin": "^3.0.0",
|
||||
"fs-extra": "^9.0.1",
|
||||
"husky": "^4.2.5",
|
||||
"hyperlink": "^4.5.2",
|
||||
"jsdoc": "^3.6.5",
|
||||
"jsdoc-ts-utils": "^1.1.2",
|
||||
"karma": "^5.1.1",
|
||||
"karma-chrome-launcher": "^3.1.0",
|
||||
"karma-mocha": "^2.0.1",
|
||||
"karma-mocha-reporter": "^2.2.5",
|
||||
"karma-requirejs": "^1.1.0",
|
||||
"karma-sauce-launcher": "^4.3.4",
|
||||
"lint-staged": "^10.2.11",
|
||||
"markdown-it": "^11.0.0",
|
||||
"markdown-it-anchor": "^5.3.0",
|
||||
"markdown-it-attrs": "^3.0.3",
|
||||
"markdown-it-emoji": "^1.4.0",
|
||||
"markdown-it-prism": "^2.1.1",
|
||||
"markdown-toc": "^1.2.0",
|
||||
"markdownlint-cli": "^0.23.2",
|
||||
"needle": "^2.5.0",
|
||||
"nps": "^5.10.0",
|
||||
"nyc": "^15.1.0",
|
||||
"pidtree": "^0.5.0",
|
||||
"prettier": "^1.19.1",
|
||||
"regenerator-runtime": "0.13.7",
|
||||
"regenerator-transform": "0.14.5",
|
||||
"remark": "^12.0.1",
|
||||
"remark-github": "^9.0.1",
|
||||
"remark-inline-links": "^4.0.0",
|
||||
"requirejs": "^2.3.6",
|
||||
"rewiremock": "^3.14.3",
|
||||
"rimraf": "^3.0.2",
|
||||
"rollup": "^2.23.1",
|
||||
"rollup-plugin-node-globals": "^1.4.0",
|
||||
"rollup-plugin-node-polyfills": "^0.2.1",
|
||||
"rollup-plugin-visualizer": "^4.1.0",
|
||||
"sinon": "^9.0.3",
|
||||
"strip-ansi": "^6.0.0",
|
||||
"svgo": "^1.3.2",
|
||||
"through2": "^4.0.2",
|
||||
"to-vfile": "^6.1.0",
|
||||
"touch": "^3.1.0",
|
||||
"unexpected": "^11.14.0",
|
||||
"unexpected-eventemitter": "^2.2.0",
|
||||
"unexpected-map": "^2.0.0",
|
||||
"unexpected-set": "^3.0.0",
|
||||
"unexpected-sinon": "^10.11.2",
|
||||
"update-notifier": "^4.1.0",
|
||||
"uslug": "^1.0.4",
|
||||
"uuid": "^8.3.0",
|
||||
"watchify": "^3.11.1",
|
||||
"webpack": "^4.44.1",
|
||||
"webpack-cli": "^3.3.12"
|
||||
},
|
||||
"directories": {
|
||||
"lib": "./lib",
|
||||
"test": "./test"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 12.0.0"
|
||||
},
|
||||
"files": [
|
||||
"bin/*mocha",
|
||||
"assets/growl/*.png",
|
||||
"lib/**/*.{js,html,json}",
|
||||
"index.js",
|
||||
"mocha.css",
|
||||
"mocha.js",
|
||||
"mocha.js.map",
|
||||
"browser-entry.js"
|
||||
],
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/mochajs"
|
||||
},
|
||||
"gitter": "https://gitter.im/mochajs/mocha",
|
||||
"homepage": "https://mochajs.org/",
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "lint-staged"
|
||||
}
|
||||
},
|
||||
"keywords": [
|
||||
"mocha",
|
||||
"test",
|
||||
"bdd",
|
||||
"tdd",
|
||||
"tap",
|
||||
"testing",
|
||||
"chai",
|
||||
"assertion",
|
||||
"ava",
|
||||
"jest",
|
||||
"tape",
|
||||
"jasmine",
|
||||
"karma"
|
||||
],
|
||||
"license": "MIT",
|
||||
"logo": "https://cldup.com/S9uQ-cOLYz.svg",
|
||||
"name": "mocha",
|
||||
"notifyLogo": "https://ibin.co/4QuRuGjXvl36.png",
|
||||
"prettier": {
|
||||
"singleQuote": true,
|
||||
"bracketSpacing": false,
|
||||
"endOfLine": "auto"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/mochajs/mocha.git"
|
||||
},
|
||||
"scripts": {
|
||||
"prepublishOnly": "nps test clean build",
|
||||
"start": "nps",
|
||||
"test": "nps test",
|
||||
"test:smoke": "node ./bin/mocha --no-config test/smoke/smoke.spec.js",
|
||||
"version": "nps version"
|
||||
},
|
||||
"version": "9.0.0"
|
||||
}
|
||||
Reference in New Issue
Block a user