added unit testing, and started implementing unit tests...phew
This commit is contained in:
1708
node_modules/mocha/CHANGELOG.md
generated
vendored
Normal file
1708
node_modules/mocha/CHANGELOG.md
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
22
node_modules/mocha/LICENSE
generated
vendored
Normal file
22
node_modules/mocha/LICENSE
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2011-2018 JS Foundation and contributors, https://js.foundation
|
||||
|
||||
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.
|
105
node_modules/mocha/README.md
generated
vendored
Normal file
105
node_modules/mocha/README.md
generated
vendored
Normal file
@ -0,0 +1,105 @@
|
||||
<p align="center">
|
||||
<img src="https://cldup.com/xFVFxOioAU.svg" alt="Mocha test framework"/>
|
||||
</p>
|
||||
|
||||
<p align="center">:coffee: Simple, flexible, fun JavaScript test framework for Node.js & The Browser :coffee:</p>
|
||||
|
||||
<p align="center"><a href="http://travis-ci.org/mochajs/mocha"><img src="https://api.travis-ci.org/mochajs/mocha.svg?branch=master" alt="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#backers"><img src="https://opencollective.com/mochajs/backers/badge.svg" alt="OpenCollective"></a> <a href="https://github.com/mochajs/mocha#sponsors"><img src="https://opencollective.com/mochajs/sponsors/badge.svg" alt="OpenCollective"></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!)
|
||||
- [Google Group](https://groups.google.com/group/mochajs)
|
||||
- [Issue Tracker](https://github.com/mochajs/mocha/issues)
|
||||
|
||||
## Backers
|
||||
|
||||
[Become a backer](https://opencollective.com/mochajs#backer) and show your support to our open source project.
|
||||
|
||||
[](https://opencollective.com/mochajs/backer/0/website)
|
||||
[](https://opencollective.com/mochajs/backer/1/website)
|
||||
[](https://opencollective.com/mochajs/backer/2/website)
|
||||
[](https://opencollective.com/mochajs/backer/3/website)
|
||||
[](https://opencollective.com/mochajs/backer/4/website)
|
||||
[](https://opencollective.com/mochajs/backer/5/website)
|
||||
[](https://opencollective.com/mochajs/backer/6/website)
|
||||
[](https://opencollective.com/mochajs/backer/7/website)
|
||||
[](https://opencollective.com/mochajs/backer/8/website)
|
||||
[](https://opencollective.com/mochajs/backer/9/website)
|
||||
[](https://opencollective.com/mochajs/backer/10/website)
|
||||
[](https://opencollective.com/mochajs/backer/11/website)
|
||||
[](https://opencollective.com/mochajs/backer/12/website)
|
||||
[](https://opencollective.com/mochajs/backer/13/website)
|
||||
[](https://opencollective.com/mochajs/backer/14/website)
|
||||
[](https://opencollective.com/mochajs/backer/15/website)
|
||||
[](https://opencollective.com/mochajs/backer/16/website)
|
||||
[](https://opencollective.com/mochajs/backer/17/website)
|
||||
[](https://opencollective.com/mochajs/backer/18/website)
|
||||
[](https://opencollective.com/mochajs/backer/19/website)
|
||||
[](https://opencollective.com/mochajs/backer/20/website)
|
||||
[](https://opencollective.com/mochajs/backer/21/website)
|
||||
[](https://opencollective.com/mochajs/backer/22/website)
|
||||
[](https://opencollective.com/mochajs/backer/23/website)
|
||||
[](https://opencollective.com/mochajs/backer/24/website)
|
||||
[](https://opencollective.com/mochajs/backer/25/website)
|
||||
[](https://opencollective.com/mochajs/backer/26/website)
|
||||
[](https://opencollective.com/mochajs/backer/27/website)
|
||||
[](https://opencollective.com/mochajs/backer/28/website)
|
||||
[](https://opencollective.com/mochajs/backer/29/website)
|
||||
|
||||
## 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) - who doesn't want a little extra exposure? [Here's the info](https://opencollective.com/mochajs#sponsor).
|
||||
|
||||
[](https://opencollective.com/mochajs/sponsor/0/website)
|
||||
[](https://opencollective.com/mochajs/sponsor/1/website)
|
||||
[](https://opencollective.com/mochajs/sponsor/2/website)
|
||||
[](https://opencollective.com/mochajs/sponsor/3/website)
|
||||
[](https://opencollective.com/mochajs/sponsor/4/website)
|
||||
[](https://opencollective.com/mochajs/sponsor/5/website)
|
||||
[](https://opencollective.com/mochajs/sponsor/6/website)
|
||||
[](https://opencollective.com/mochajs/sponsor/7/website)
|
||||
[](https://opencollective.com/mochajs/sponsor/8/website)
|
||||
[](https://opencollective.com/mochajs/sponsor/9/website)
|
||||
[](https://opencollective.com/mochajs/sponsor/10/website)
|
||||
[](https://opencollective.com/mochajs/sponsor/11/website)
|
||||
[](https://opencollective.com/mochajs/sponsor/12/website)
|
||||
[](https://opencollective.com/mochajs/sponsor/13/website)
|
||||
[](https://opencollective.com/mochajs/sponsor/14/website)
|
||||
[](https://opencollective.com/mochajs/sponsor/15/website)
|
||||
[](https://opencollective.com/mochajs/sponsor/16/website)
|
||||
[](https://opencollective.com/mochajs/sponsor/17/website)
|
||||
[](https://opencollective.com/mochajs/sponsor/18/website)
|
||||
[](https://opencollective.com/mochajs/sponsor/19/website)
|
||||
|
||||
## Development
|
||||
|
||||
You might want to know that:
|
||||
|
||||
- Mocha is the *most-depended-upon* module 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
|
||||
|
||||
[MIT](LICENSE)
|
||||
|
||||
[](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmochajs%2Fmocha?ref=badge_large)
|
BIN
node_modules/mocha/assets/growl/error.png
generated
vendored
Normal file
BIN
node_modules/mocha/assets/growl/error.png
generated
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 412 B |
BIN
node_modules/mocha/assets/growl/ok.png
generated
vendored
Normal file
BIN
node_modules/mocha/assets/growl/ok.png
generated
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 388 B |
10
node_modules/mocha/bin/_mocha
generated
vendored
Executable file
10
node_modules/mocha/bin/_mocha
generated
vendored
Executable 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();
|
149
node_modules/mocha/bin/mocha
generated
vendored
Executable file
149
node_modules/mocha/bin/mocha
generated
vendored
Executable file
@ -0,0 +1,149 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* This wrapper executable checks for known node flags and appends them when found, before invoking the "real" _mocha(1) executable.
|
||||
*
|
||||
* @module bin/mocha
|
||||
* @private
|
||||
*/
|
||||
|
||||
const {deprecate, warn} = require('../lib/utils');
|
||||
const {spawn} = require('child_process');
|
||||
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 nodeEnv = require('node-environment-flags');
|
||||
|
||||
const mochaPath = require.resolve('./_mocha');
|
||||
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 "${value}" disabled timeouts`);
|
||||
mochaArgs.timeout = 0;
|
||||
delete mochaArgs.timeouts;
|
||||
delete mochaArgs.t;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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];
|
||||
disableTimeouts(opt);
|
||||
} else {
|
||||
mochaArgs[opt] = opts[opt];
|
||||
}
|
||||
});
|
||||
|
||||
// Native debugger handling
|
||||
// see https://nodejs.org/api/debugger.html#debugger_debugger
|
||||
// look for 'debug' or 'inspect' that would launch this debugger,
|
||||
// remove it from Mocha's opts and prepend it to Node's opts.
|
||||
// also coerce depending on Node.js version.
|
||||
// A deprecation warning will be printed by node, if applicable.
|
||||
// (mochaArgs._ are "positional" arguments, not prefixed with - or --)
|
||||
if (/^(debug|inspect)$/.test(mochaArgs._[0])) {
|
||||
const command = mochaArgs._.shift();
|
||||
disableTimeouts(command);
|
||||
// don't conflict with inspector
|
||||
['debug', 'inspect', 'debug-brk', 'inspect-brk']
|
||||
.filter(opt => opt in nodeArgs || opt in mochaArgs)
|
||||
.forEach(opt => {
|
||||
warn(`command "${command}" provided; --${opt} ignored`);
|
||||
delete nodeArgs[opt];
|
||||
delete mochaArgs[opt];
|
||||
});
|
||||
nodeArgs._ = [
|
||||
parseInt(
|
||||
process.version
|
||||
.slice(1)
|
||||
.split('.')
|
||||
.shift(),
|
||||
10
|
||||
) >= 8
|
||||
? 'inspect'
|
||||
: 'debug'
|
||||
];
|
||||
}
|
||||
|
||||
// allow --debug to invoke --inspect on Node.js v8 or newer.
|
||||
['debug', 'debug-brk']
|
||||
.filter(opt => opt in nodeArgs && !nodeEnv.has(opt))
|
||||
.forEach(opt => {
|
||||
const newOpt = opt === 'debug' ? 'inspect' : 'inspect-brk';
|
||||
warn(
|
||||
`"--${opt}" is not available in Node.js ${
|
||||
process.version
|
||||
}; use "--${newOpt}" instead.`
|
||||
);
|
||||
nodeArgs[newOpt] = nodeArgs[opt];
|
||||
mochaArgs.timeout = false;
|
||||
debug(`--${opt} -> ${newOpt}`);
|
||||
delete nodeArgs[opt];
|
||||
});
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
debug('final node args', nodeArgs);
|
||||
|
||||
const args = [].concat(
|
||||
unparseNodeFlags(nodeArgs),
|
||||
mochaPath,
|
||||
unparse(mochaArgs, {alias: aliases})
|
||||
);
|
||||
|
||||
debug(`exec ${process.execPath} w/ args:`, args);
|
||||
|
||||
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', () => {
|
||||
proc.kill('SIGINT'); // calls runner.abort()
|
||||
proc.kill('SIGTERM'); // if that didn't work, we're probably in an infinite loop, so make it die.
|
||||
});
|
10
node_modules/mocha/bin/options.js
generated
vendored
Normal file
10
node_modules/mocha/bin/options.js
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
/*
|
||||
* This module is deprecated and will be removed in a future version of Mocha.
|
||||
* @deprecated Deprecated in v6.0.0; source moved into {@link module:lib/cli/options lib/cli/options module}.
|
||||
* @module
|
||||
* @exports module:lib/cli/options
|
||||
*/
|
||||
|
||||
module.exports = require('../lib/cli/options');
|
191
node_modules/mocha/browser-entry.js
generated
vendored
Normal file
191
node_modules/mocha/browser-entry.js
generated
vendored
Normal file
@ -0,0 +1,191 @@
|
||||
'use strict';
|
||||
|
||||
/* eslint no-unused-vars: off */
|
||||
/* eslint-env commonjs */
|
||||
|
||||
/**
|
||||
* Shim process.stdout.
|
||||
*/
|
||||
|
||||
process.stdout = require('browser-stdout')({label: false});
|
||||
|
||||
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 uncaughtException listener.
|
||||
*/
|
||||
|
||||
process.on = function(e, fn) {
|
||||
if (e === 'uncaughtException') {
|
||||
global.onerror = function(err, url, line) {
|
||||
fn(new Error(err + ' (' + url + ':' + line + ')'));
|
||||
return !mocha.allowUncaught;
|
||||
};
|
||||
uncaughtExceptionHandlers.push(fn);
|
||||
}
|
||||
};
|
||||
|
||||
// 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};
|
||||
}
|
||||
for (var opt in opts) {
|
||||
if (opts.hasOwnProperty(opt)) {
|
||||
this[opt](opts[opt]);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Run mocha, returning the Runner.
|
||||
*/
|
||||
|
||||
mocha.run = function(fn) {
|
||||
var options = mocha.options;
|
||||
mocha.globals('location');
|
||||
|
||||
var query = Mocha.utils.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
|
||||
) {
|
||||
Mocha.utils.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 = global;
|
3
node_modules/mocha/index.js
generated
vendored
Normal file
3
node_modules/mocha/index.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./lib/mocha');
|
168
node_modules/mocha/lib/browser/growl.js
generated
vendored
Normal file
168
node_modules/mocha/lib/browser/growl.js
generated
vendored
Normal file
@ -0,0 +1,168 @@
|
||||
'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;
|
||||
|
||||
/**
|
||||
* 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 process.browser && 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').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);
|
||||
}
|
119
node_modules/mocha/lib/browser/progress.js
generated
vendored
Normal file
119
node_modules/mocha/lib/browser/progress.js
generated
vendored
Normal file
@ -0,0 +1,119 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* 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;
|
||||
};
|
18
node_modules/mocha/lib/browser/template.html
generated
vendored
Normal file
18
node_modules/mocha/lib/browser/template.html
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Mocha</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<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.js"></script>
|
||||
<script>
|
||||
mocha.run();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
13
node_modules/mocha/lib/browser/tty.js
generated
vendored
Normal file
13
node_modules/mocha/lib/browser/tty.js
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
exports.isatty = function isatty() {
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.getWindowSize = function getWindowSize() {
|
||||
if ('innerHeight' in global) {
|
||||
return [global.innerHeight, global.innerWidth];
|
||||
}
|
||||
// In a Web Worker, the DOM Window is not available.
|
||||
return [640, 480];
|
||||
};
|
68
node_modules/mocha/lib/cli/cli.js
generated
vendored
Executable file
68
node_modules/mocha/lib/cli/cli.js
generated
vendored
Executable file
@ -0,0 +1,68 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* This is where we finally parse and handle arguments passed to the `mocha` executable.
|
||||
* Option parsing is handled by {@link https://npm.im/yargs yargs}.
|
||||
* If executed via `node`, this module will run {@linkcode module:lib/cli/cli.main main()}.
|
||||
*
|
||||
* @private
|
||||
* @module
|
||||
*/
|
||||
|
||||
const debug = require('debug')('mocha:cli:cli');
|
||||
const symbols = require('log-symbols');
|
||||
const yargs = require('yargs');
|
||||
const path = require('path');
|
||||
const {loadOptions} = require('./options');
|
||||
const commands = require('./commands');
|
||||
const ansi = require('ansi-colors');
|
||||
const {repository, homepage, version, gitter} = require('../../package.json');
|
||||
|
||||
/**
|
||||
* - 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`
|
||||
* @summary Mocha's main entry point from the command-line.
|
||||
* @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
|
||||
module.paths.push(process.cwd(), path.resolve('node_modules'));
|
||||
|
||||
Error.stackTraceLimit = Infinity; // configurable via --stack-trace-limit?
|
||||
|
||||
yargs
|
||||
.scriptName('mocha')
|
||||
.command(commands.run)
|
||||
.command(commands.init)
|
||||
.updateStrings({
|
||||
'Positionals:': 'Positional Arguments',
|
||||
'Options:': 'Other Options',
|
||||
'Commands:': 'Commands'
|
||||
})
|
||||
.fail((msg, err, yargs) => {
|
||||
debug(err);
|
||||
yargs.showHelp();
|
||||
console.error(`\n${symbols.error} ${ansi.red('ERROR:')} ${msg}`);
|
||||
process.exit(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)}
|
||||
`
|
||||
)
|
||||
.parse(argv, loadOptions(argv));
|
||||
};
|
||||
|
||||
// allow direct execution
|
||||
if (require.main === module) {
|
||||
exports.main();
|
||||
}
|
13
node_modules/mocha/lib/cli/commands.js
generated
vendored
Normal file
13
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');
|
79
node_modules/mocha/lib/cli/config.js
generated
vendored
Normal file
79
node_modules/mocha/lib/cli/config.js
generated
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Responsible for loading / finding Mocha's "rc" files.
|
||||
* This doesn't have anything to do with `mocha.opts`.
|
||||
*
|
||||
* @private
|
||||
* @module
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const findUp = require('findup-sync');
|
||||
const path = require('path');
|
||||
const debug = require('debug')('mocha:cli:config');
|
||||
|
||||
/**
|
||||
* 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.js',
|
||||
'.mocharc.yaml',
|
||||
'.mocharc.yml',
|
||||
'.mocharc.json'
|
||||
];
|
||||
|
||||
/**
|
||||
* 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').safeLoad(fs.readFileSync(filepath, 'utf8')),
|
||||
js: filepath => require(filepath),
|
||||
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.
|
||||
* @param {string} filepath - Config file path to load
|
||||
* @returns {Object} Parsed config object
|
||||
* @private
|
||||
*/
|
||||
exports.loadConfig = filepath => {
|
||||
let config = {};
|
||||
const ext = path.extname(filepath);
|
||||
try {
|
||||
if (/\.ya?ml/.test(ext)) {
|
||||
config = parsers.yaml(filepath);
|
||||
} else if (ext === '.js') {
|
||||
config = parsers.js(filepath);
|
||||
} else {
|
||||
config = parsers.json(filepath);
|
||||
}
|
||||
} catch (err) {
|
||||
throw new Error(`failed to parse ${filepath}: ${err}`);
|
||||
}
|
||||
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 = process.cwd()) => {
|
||||
const filepath = findUp(exports.CONFIG_FILES, {cwd});
|
||||
if (filepath) {
|
||||
debug(`found config at ${filepath}`);
|
||||
}
|
||||
return filepath;
|
||||
};
|
9
node_modules/mocha/lib/cli/index.js
generated
vendored
Normal file
9
node_modules/mocha/lib/cli/index.js
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Just exports {@link module:lib/cli/cli} for convenience.
|
||||
* @private
|
||||
* @module lib/cli
|
||||
* @exports module:lib/cli/cli
|
||||
*/
|
||||
module.exports = require('./cli');
|
37
node_modules/mocha/lib/cli/init.js
generated
vendored
Normal file
37
node_modules/mocha/lib/cli/init.js
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Command module for "init" command
|
||||
*
|
||||
* @private
|
||||
* @module
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const mkdirp = require('mkdirp');
|
||||
|
||||
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, '..', '..');
|
||||
mkdirp.sync(destdir);
|
||||
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);
|
||||
};
|
85
node_modules/mocha/lib/cli/node-flags.js
generated
vendored
Normal file
85
node_modules/mocha/lib/cli/node-flags.js
generated
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Some settings and code related to Mocha's handling of Node.js/V8 flags.
|
||||
* @private
|
||||
* @module
|
||||
*/
|
||||
|
||||
const nodeFlags = require('node-environment-flags');
|
||||
const unparse = require('yargs-unparser');
|
||||
|
||||
/**
|
||||
* These flags are considered "debug" flags.
|
||||
* @see {@link impliesNoTimeouts}
|
||||
* @private
|
||||
*/
|
||||
const debugFlags = new Set(['debug', 'debug-brk', '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 (
|
||||
// treat --require/-r as Mocha flag even though it's also a node flag
|
||||
!(flag === 'require' || flag === 'r') &&
|
||||
// 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
|
||||
(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.
|
||||
* 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 => (arg === ' ' ? '=' : arg))
|
||||
.join('')
|
||||
: [];
|
||||
};
|
70
node_modules/mocha/lib/cli/one-and-dones.js
generated
vendored
Normal file
70
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
|
||||
*/
|
||||
interfaces: () => {
|
||||
showKeys(Mocha.interfaces);
|
||||
},
|
||||
/**
|
||||
* Dump list of built-in reporters
|
||||
* @private
|
||||
*/
|
||||
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))
|
||||
);
|
337
node_modules/mocha/lib/cli/options.js
generated
vendored
Normal file
337
node_modules/mocha/lib/cli/options.js
generated
vendored
Normal file
@ -0,0 +1,337 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Main entry point for handling filesystem-based configuration,
|
||||
* whether that's `mocha.opts` or a config file or `package.json` or whatever.
|
||||
* @module
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
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 yargsParserConfig = require('../../package.json').yargs;
|
||||
const {list} = require('./run-helpers');
|
||||
const {loadConfig, findConfig} = require('./config');
|
||||
const findup = require('findup-sync');
|
||||
const {deprecate} = require('../utils');
|
||||
const debug = require('debug')('mocha:cli:options');
|
||||
const {createMissingArgumentError} = require('../errors');
|
||||
const {isNodeFlag} = require('./node-flags');
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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({}, yargsParserConfig, {
|
||||
'camel-case-expansion': false
|
||||
});
|
||||
|
||||
/**
|
||||
* This is a really fancy way to ensure unique values for `array`-type
|
||||
* options.
|
||||
* This is passed as the `coerce` option to `yargs-parser`
|
||||
* @private
|
||||
* @ignore
|
||||
*/
|
||||
const coerceOpts = types.array.reduce(
|
||||
(acc, arg) => Object.assign(acc, {[arg]: v => Array.from(new Set(list(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} configObjects - `configObjects` for yargs-parser
|
||||
* @private
|
||||
* @ignore
|
||||
*/
|
||||
const parse = (args = [], ...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,
|
||||
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) {
|
||||
throw createMissingArgumentError(result.error.message);
|
||||
}
|
||||
|
||||
// reapply "=" arg values from above
|
||||
nodeArgs.forEach(([key, value]) => {
|
||||
result.argv[key] = value;
|
||||
});
|
||||
|
||||
return result.argv;
|
||||
};
|
||||
|
||||
/**
|
||||
* - Replaces comments with empty strings
|
||||
* - Replaces escaped spaces (e.g., 'xxx\ yyy') with HTML space
|
||||
* - Splits on whitespace, creating array of substrings
|
||||
* - Filters empty string elements from array
|
||||
* - Replaces any HTML space with space
|
||||
* @summary Parses options read from run-control file.
|
||||
* @private
|
||||
* @param {string} content - Content read from run-control file.
|
||||
* @returns {string[]} cmdline options (and associated arguments)
|
||||
* @ignore
|
||||
*/
|
||||
const parseMochaOpts = content =>
|
||||
content
|
||||
.replace(/^#.*$/gm, '')
|
||||
.replace(/\\\s/g, '%20')
|
||||
.split(/\s/)
|
||||
.filter(Boolean)
|
||||
.map(value => value.replace(/%20/g, ' '));
|
||||
|
||||
/**
|
||||
* Prepends options from run-control file to the command line arguments.
|
||||
*
|
||||
* @deprecated Deprecated in v6.0.0; This function is no longer used internally and will be removed in a future version.
|
||||
* @public
|
||||
* @alias module:lib/cli/options
|
||||
* @see {@link https://mochajs.org/#mochaopts|mocha.opts}
|
||||
*/
|
||||
module.exports = function getOptions() {
|
||||
deprecate(
|
||||
'getOptions() is DEPRECATED and will be removed from a future version of Mocha. Use loadOptions() instead'
|
||||
);
|
||||
if (process.argv.length === 3 && ONE_AND_DONE_ARGS.has(process.argv[2])) {
|
||||
return;
|
||||
}
|
||||
|
||||
const optsPath =
|
||||
process.argv.indexOf('--opts') === -1
|
||||
? mocharc.opts
|
||||
: process.argv[process.argv.indexOf('--opts') + 1];
|
||||
|
||||
try {
|
||||
const options = parseMochaOpts(fs.readFileSync(optsPath, 'utf8'));
|
||||
|
||||
process.argv = process.argv
|
||||
.slice(0, 2)
|
||||
.concat(options.concat(process.argv.slice(2)));
|
||||
} catch (ignore) {
|
||||
// NOTE: should console.error() and throw the error
|
||||
}
|
||||
|
||||
process.env.LOADED_MOCHA_OPTS = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Given filepath in `args.opts`, attempt to load and parse a `mocha.opts` file.
|
||||
* @param {Object} [args] - Arguments object
|
||||
* @param {string|boolean} [args.opts] - Filepath to mocha.opts; defaults to whatever's in `mocharc.opts`, or `false` to skip
|
||||
* @returns {external:yargsParser.Arguments|void} If read, object containing parsed arguments
|
||||
* @memberof module:lib/cli/options
|
||||
* @public
|
||||
*/
|
||||
const loadMochaOpts = (args = {}) => {
|
||||
let result;
|
||||
let filepath = args.opts;
|
||||
// /dev/null is backwards compat
|
||||
if (filepath === false || filepath === '/dev/null') {
|
||||
return result;
|
||||
}
|
||||
filepath = filepath || mocharc.opts;
|
||||
result = {};
|
||||
let mochaOpts;
|
||||
try {
|
||||
mochaOpts = fs.readFileSync(filepath, 'utf8');
|
||||
debug(`read ${filepath}`);
|
||||
} catch (err) {
|
||||
if (args.opts) {
|
||||
throw new Error(`Unable to read ${filepath}: ${err}`);
|
||||
}
|
||||
// ignore otherwise. we tried
|
||||
debug(`No mocha.opts found at ${filepath}`);
|
||||
}
|
||||
|
||||
// real args should override `mocha.opts` which should override defaults.
|
||||
// if there's an exception to catch here, I'm not sure what it is.
|
||||
// by attaching the `no-opts` arg, we avoid re-parsing of `mocha.opts`.
|
||||
if (mochaOpts) {
|
||||
result = parse(parseMochaOpts(mochaOpts));
|
||||
debug(`${filepath} parsed succesfully`);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports.loadMochaOpts = loadMochaOpts;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @memberof module:lib/cli/options
|
||||
* @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
|
||||
* @memberof module:lib/cli/options
|
||||
* @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(mocharc.package);
|
||||
if (filepath) {
|
||||
try {
|
||||
const pkg = JSON.parse(fs.readFileSync(filepath, 'utf8'));
|
||||
if (pkg.mocha) {
|
||||
debug(`'mocha' prop of package.json parsed:`, pkg.mocha);
|
||||
result = pkg.mocha;
|
||||
} else {
|
||||
debug(`no config found in ${filepath}`);
|
||||
}
|
||||
} catch (err) {
|
||||
if (args.package) {
|
||||
throw new Error(`Unable to read/parse ${filepath}: ${err}`);
|
||||
}
|
||||
debug(`failed to read default package.json at ${filepath}; ignoring`);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports.loadPkgRc = loadPkgRc;
|
||||
|
||||
/**
|
||||
* Priority list:
|
||||
*
|
||||
* 1. Command-line args
|
||||
* 2. RC file (`.mocharc.js`, `.mocharc.ya?ml`, `mocharc.json`)
|
||||
* 3. `mocha` prop of `package.json`
|
||||
* 4. `mocha.opts`
|
||||
* 5. 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 `mocha.opts`, `.mocharc.*` and `package.json`.
|
||||
* @param {string|string[]} [argv] - Arguments to parse
|
||||
* @public
|
||||
* @memberof module:lib/cli/options
|
||||
* @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 mocha.opts
|
||||
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);
|
||||
const optsConfig = loadMochaOpts(args);
|
||||
|
||||
if (rcConfig) {
|
||||
args.config = false;
|
||||
args._ = args._.concat(rcConfig._ || []);
|
||||
}
|
||||
if (pkgConfig) {
|
||||
args.package = false;
|
||||
args._ = args._.concat(pkgConfig._ || []);
|
||||
}
|
||||
if (optsConfig) {
|
||||
args.opts = false;
|
||||
args._ = args._.concat(optsConfig._ || []);
|
||||
}
|
||||
|
||||
args = parse(
|
||||
args._,
|
||||
args,
|
||||
rcConfig || {},
|
||||
pkgConfig || {},
|
||||
optsConfig || {},
|
||||
mocharc
|
||||
);
|
||||
|
||||
// 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;
|
337
node_modules/mocha/lib/cli/run-helpers.js
generated
vendored
Normal file
337
node_modules/mocha/lib/cli/run-helpers.js
generated
vendored
Normal file
@ -0,0 +1,337 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Helper scripts for the `run` command
|
||||
* @see module:lib/cli/run
|
||||
* @module
|
||||
* @private
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const ansi = require('ansi-colors');
|
||||
const debug = require('debug')('mocha:cli:run:helpers');
|
||||
const minimatch = require('minimatch');
|
||||
const Context = require('../context');
|
||||
const Mocha = require('../mocha');
|
||||
const utils = require('../utils');
|
||||
|
||||
const cwd = (exports.cwd = process.cwd());
|
||||
|
||||
/**
|
||||
* 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();
|
||||
};
|
||||
|
||||
/**
|
||||
* Hide the cursor.
|
||||
* @ignore
|
||||
* @private
|
||||
*/
|
||||
const hideCursor = () => {
|
||||
process.stdout.write('\u001b[?25l');
|
||||
};
|
||||
|
||||
/**
|
||||
* Show the cursor.
|
||||
* @ignore
|
||||
* @private
|
||||
*/
|
||||
const showCursor = () => {
|
||||
process.stdout.write('\u001b[?25h');
|
||||
};
|
||||
|
||||
/**
|
||||
* Stop cursor business
|
||||
* @private
|
||||
*/
|
||||
const stop = () => {
|
||||
process.stdout.write('\u001b[2K');
|
||||
};
|
||||
|
||||
/**
|
||||
* 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>`
|
||||
* @param {string[]} requires - Modules to require
|
||||
* @private
|
||||
*/
|
||||
exports.handleRequires = (requires = []) => {
|
||||
requires.forEach(mod => {
|
||||
let modpath = mod;
|
||||
if (fs.existsSync(mod, {cwd}) || fs.existsSync(`${mod}.js`, {cwd})) {
|
||||
modpath = path.resolve(mod);
|
||||
debug(`resolved ${mod} to ${modpath}`);
|
||||
}
|
||||
require(modpath);
|
||||
debug(`loaded require "${mod}"`);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Smash together an array of test files in the correct order
|
||||
* @param {Object} [opts] - Options
|
||||
* @param {string[]} [opts.extension] - File extensions to use
|
||||
* @param {string[]} [opts.spec] - Files, dirs, globs to run
|
||||
* @param {string[]} [opts.exclude] - Files, dirs, globs to exclude
|
||||
* @param {boolean} [opts.recursive=false] - Find files recursively
|
||||
* @param {boolean} [opts.sort=false] - Sort test files
|
||||
* @returns {string[]} List of files to test
|
||||
* @private
|
||||
*/
|
||||
exports.handleFiles = ({
|
||||
exclude = [],
|
||||
extension = [],
|
||||
file = [],
|
||||
recursive = false,
|
||||
sort = false,
|
||||
spec = []
|
||||
} = {}) => {
|
||||
let files = [];
|
||||
const unmatched = [];
|
||||
spec.forEach(arg => {
|
||||
let newFiles;
|
||||
try {
|
||||
newFiles = utils.lookupFiles(arg, extension, recursive);
|
||||
} catch (err) {
|
||||
if (err.code === 'ERR_MOCHA_NO_FILES_MATCH_PATTERN') {
|
||||
unmatched.push({message: err.message, pattern: err.pattern});
|
||||
return;
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
|
||||
if (typeof newFiles !== 'undefined') {
|
||||
if (typeof newFiles === 'string') {
|
||||
newFiles = [newFiles];
|
||||
}
|
||||
newFiles = newFiles.filter(fileName =>
|
||||
exclude.every(pattern => !minimatch(fileName, pattern))
|
||||
);
|
||||
}
|
||||
|
||||
files = files.concat(newFiles);
|
||||
});
|
||||
|
||||
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 an warning
|
||||
unmatched.forEach(warning => {
|
||||
console.warn(ansi.yellow(`Warning: ${warning.message}`));
|
||||
});
|
||||
}
|
||||
|
||||
const fileArgs = file.map(filepath => path.resolve(filepath));
|
||||
files = files.map(filepath => path.resolve(filepath));
|
||||
|
||||
// ensure we don't sort the stuff from fileArgs; order is important!
|
||||
if (sort) {
|
||||
files.sort();
|
||||
}
|
||||
|
||||
// add files given through --file to be ran first
|
||||
files = fileArgs.concat(files);
|
||||
debug('files (in order): ', files);
|
||||
return files;
|
||||
};
|
||||
|
||||
/**
|
||||
* Give Mocha files and tell it to run
|
||||
* @param {Mocha} mocha - Mocha instance
|
||||
* @param {Options} [opts] - Options
|
||||
* @param {string[]} [opts.files] - List of test files
|
||||
* @param {boolean} [opts.exit] - Whether or not to force-exit after tests are complete
|
||||
* @returns {Runner}
|
||||
* @private
|
||||
*/
|
||||
exports.singleRun = (mocha, {files = [], exit = false} = {}) => {
|
||||
mocha.files = files;
|
||||
return mocha.run(exit ? exitMocha : exitMochaLater);
|
||||
};
|
||||
|
||||
/**
|
||||
* Run Mocha in "watch" mode
|
||||
* @param {Mocha} mocha - Mocha instance
|
||||
* @param {Object} [opts] - Options
|
||||
* @param {string[]} [opts.extension] - List of extensions to watch
|
||||
* @param {string|RegExp} [opts.grep] - Grep for test titles
|
||||
* @param {string} [opts.ui=bdd] - User interface
|
||||
* @param {string[]} [files] - Array of test files
|
||||
* @private
|
||||
*/
|
||||
exports.watchRun = (
|
||||
mocha,
|
||||
{extension = ['js'], grep = '', ui = 'bdd', files = []} = {}
|
||||
) => {
|
||||
let runner;
|
||||
|
||||
console.log();
|
||||
hideCursor();
|
||||
process.on('SIGINT', () => {
|
||||
showCursor();
|
||||
console.log('\n');
|
||||
process.exit(130);
|
||||
});
|
||||
|
||||
const watchFiles = utils.files(cwd, extension);
|
||||
let runAgain = false;
|
||||
|
||||
const loadAndRun = () => {
|
||||
try {
|
||||
mocha.files = files;
|
||||
runAgain = false;
|
||||
runner = mocha.run(() => {
|
||||
runner = null;
|
||||
if (runAgain) {
|
||||
rerun();
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e.stack);
|
||||
}
|
||||
};
|
||||
|
||||
const purge = () => {
|
||||
watchFiles.forEach(Mocha.unloadFile);
|
||||
};
|
||||
|
||||
loadAndRun();
|
||||
|
||||
const rerun = () => {
|
||||
purge();
|
||||
stop();
|
||||
if (!grep) {
|
||||
mocha.grep(null);
|
||||
}
|
||||
mocha.suite = mocha.suite.clone();
|
||||
mocha.suite.ctx = new Context();
|
||||
mocha.ui(ui);
|
||||
loadAndRun();
|
||||
};
|
||||
|
||||
utils.watch(watchFiles, () => {
|
||||
runAgain = true;
|
||||
if (runner) {
|
||||
runner.abort();
|
||||
} else {
|
||||
rerun();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Actually run tests
|
||||
* @param {Mocha} mocha - Mocha instance
|
||||
* @param {Object} [opts] - Options
|
||||
* @param {boolean} [opts.watch=false] - Enable watch mode
|
||||
* @param {string[]} [opts.extension] - List of extensions to watch
|
||||
* @param {string|RegExp} [opts.grep] - Grep for test titles
|
||||
* @param {string} [opts.ui=bdd] - User interface
|
||||
* @param {boolean} [opts.exit=false] - Force-exit Mocha when tests done
|
||||
* @param {string[]} [files] - Array of test files
|
||||
* @private
|
||||
*/
|
||||
exports.runMocha = (
|
||||
mocha,
|
||||
{watch = false, extension = ['js'], grep = '', ui = 'bdd', exit = false} = {},
|
||||
files = []
|
||||
) => {
|
||||
if (watch) {
|
||||
exports.watchRun(mocha, {extension, grep, ui, files});
|
||||
} else {
|
||||
exports.singleRun(mocha, {files, exit});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Used for `--reporter` and `--ui`. Ensures there's only one, and asserts
|
||||
* that it actually exists.
|
||||
* @todo XXX This must get run after requires are processed, as it'll prevent
|
||||
* interfaces from loading.
|
||||
* @param {Object} opts - Options object
|
||||
* @param {string} key - Resolvable module name or path
|
||||
* @param {Object} [map] - An object perhaps having key `key`
|
||||
* @private
|
||||
*/
|
||||
exports.validatePlugin = (opts, key, map = {}) => {
|
||||
if (Array.isArray(opts[key])) {
|
||||
throw new TypeError(`"--${key} <${key}>" can only be specified once`);
|
||||
}
|
||||
|
||||
const unknownError = () => new Error(`Unknown "${key}": ${opts[key]}`);
|
||||
|
||||
if (!map[opts[key]]) {
|
||||
try {
|
||||
opts[key] = require(opts[key]);
|
||||
} catch (err) {
|
||||
if (err.code === 'MODULE_NOT_FOUND') {
|
||||
// Try to load reporters from a path (absolute or relative)
|
||||
try {
|
||||
opts[key] = require(path.resolve(process.cwd(), opts[key]));
|
||||
} catch (err) {
|
||||
throw unknownError();
|
||||
}
|
||||
} else {
|
||||
throw unknownError();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
76
node_modules/mocha/lib/cli/run-option-metadata.js
generated
vendored
Normal file
76
node_modules/mocha/lib/cli/run-option-metadata.js
generated
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
'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
|
||||
*/
|
||||
exports.types = {
|
||||
array: [
|
||||
'exclude',
|
||||
'extension',
|
||||
'file',
|
||||
'global',
|
||||
'require',
|
||||
'reporter-option',
|
||||
'spec'
|
||||
],
|
||||
boolean: [
|
||||
'allow-uncaught',
|
||||
'async-only',
|
||||
'bail',
|
||||
'check-leaks',
|
||||
'color',
|
||||
'delay',
|
||||
'diff',
|
||||
'exit',
|
||||
'forbid-only',
|
||||
'forbid-pending',
|
||||
'full-trace',
|
||||
'growl',
|
||||
'inline-diffs',
|
||||
'interfaces',
|
||||
'invert',
|
||||
'no-colors',
|
||||
'recursive',
|
||||
'reporters',
|
||||
'sort',
|
||||
'watch'
|
||||
],
|
||||
number: ['retries', 'slow', 'timeout'],
|
||||
string: ['fgrep', 'grep', 'package', 'reporter', 'ui']
|
||||
};
|
||||
|
||||
/**
|
||||
* 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'],
|
||||
extension: ['watch-extensions'],
|
||||
fgrep: ['f'],
|
||||
global: ['globals'],
|
||||
grep: ['g'],
|
||||
growl: ['G'],
|
||||
invert: ['i'],
|
||||
'no-colors': ['C'],
|
||||
reporter: ['R'],
|
||||
'reporter-option': ['reporter-options', 'O'],
|
||||
require: ['r'],
|
||||
slow: ['s'],
|
||||
sort: ['S'],
|
||||
timeout: ['t', 'timeouts'],
|
||||
ui: ['u'],
|
||||
watch: ['w']
|
||||
};
|
297
node_modules/mocha/lib/cli/run.js
generated
vendored
Normal file
297
node_modules/mocha/lib/cli/run.js
generated
vendored
Normal file
@ -0,0 +1,297 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Definition for Mocha's default ("run tests") command
|
||||
*
|
||||
* @module
|
||||
* @private
|
||||
*/
|
||||
|
||||
const Mocha = require('../mocha');
|
||||
const {
|
||||
createUnsupportedError,
|
||||
createInvalidArgumentValueError,
|
||||
createMissingArgumentError
|
||||
} = require('../errors');
|
||||
|
||||
const {
|
||||
list,
|
||||
handleFiles,
|
||||
handleRequires,
|
||||
validatePlugin,
|
||||
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..]', 'debug [spec..]'];
|
||||
|
||||
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
|
||||
},
|
||||
exclude: {
|
||||
defaultDescription: '(none)',
|
||||
description: 'Ignore file(s) or glob pattern(s)',
|
||||
group: GROUPS.FILES,
|
||||
requiresArg: true
|
||||
},
|
||||
exit: {
|
||||
description: 'Force Mocha to quit after tests complete',
|
||||
group: GROUPS.RULES
|
||||
},
|
||||
extension: {
|
||||
default: defaults.extension,
|
||||
defaultDescription: 'js',
|
||||
description: 'File extension(s) to load and/or watch',
|
||||
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
|
||||
},
|
||||
'inline-diffs': {
|
||||
description:
|
||||
'Display actual/expected differences inline within each string',
|
||||
group: GROUPS.OUTPUT
|
||||
},
|
||||
interfaces: {
|
||||
conflicts: Array.from(ONE_AND_DONE_ARGS),
|
||||
description: 'List built-in user interfaces & exit'
|
||||
},
|
||||
invert: {
|
||||
description: 'Inverts --grep and --fgrep matches',
|
||||
group: GROUPS.FILTERS
|
||||
},
|
||||
'no-colors': {
|
||||
description: 'Force-disable color output',
|
||||
group: GROUPS.OUTPUT,
|
||||
hidden: true
|
||||
},
|
||||
opts: {
|
||||
default: defaults.opts,
|
||||
description: 'Path to `mocha.opts`',
|
||||
group: GROUPS.CONFIG,
|
||||
normalize: true,
|
||||
requiresArg: true
|
||||
},
|
||||
package: {
|
||||
description: 'Path to package.json for config',
|
||||
group: GROUPS.CONFIG,
|
||||
normalize: true,
|
||||
requiresArg: true
|
||||
},
|
||||
recursive: {
|
||||
description: 'Look for tests in subdirectories',
|
||||
group: GROUPS.FILES
|
||||
},
|
||||
reporter: {
|
||||
default: defaults.reporter,
|
||||
description: 'Specify reporter to use',
|
||||
group: GROUPS.OUTPUT,
|
||||
requiresArg: true
|
||||
},
|
||||
reporters: {
|
||||
conflicts: Array.from(ONE_AND_DONE_ARGS),
|
||||
description: 'List built-in reporters & exit'
|
||||
},
|
||||
'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
|
||||
}
|
||||
})
|
||||
.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.compilers) {
|
||||
throw createUnsupportedError(
|
||||
`--compilers is DEPRECATED and no longer supported.
|
||||
See https://git.io/vdcSr for migration information.`
|
||||
);
|
||||
}
|
||||
|
||||
// load requires first, because it can impact "plugin" validation
|
||||
handleRequires(argv.require);
|
||||
validatePlugin(argv, 'reporter', Mocha.reporters);
|
||||
validatePlugin(argv, 'ui', Mocha.interfaces);
|
||||
|
||||
return true;
|
||||
})
|
||||
.array(types.array)
|
||||
.boolean(types.boolean)
|
||||
.string(types.string)
|
||||
.number(types.number)
|
||||
.alias(aliases);
|
||||
|
||||
exports.handler = argv => {
|
||||
debug('post-yargs config', argv);
|
||||
const mocha = new Mocha(argv);
|
||||
const files = handleFiles(argv);
|
||||
|
||||
debug('running tests with files', files);
|
||||
runMocha(mocha, argv, files);
|
||||
};
|
101
node_modules/mocha/lib/context.js
generated
vendored
Normal file
101
node_modules/mocha/lib/context.js
generated
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
'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 test timeout `enabled`.
|
||||
*
|
||||
* @private
|
||||
* @param {boolean} enabled
|
||||
* @return {Context} self
|
||||
*/
|
||||
Context.prototype.enableTimeouts = function(enabled) {
|
||||
if (!arguments.length) {
|
||||
return this.runnable().enableTimeouts();
|
||||
}
|
||||
this.runnable().enableTimeouts(enabled);
|
||||
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;
|
||||
};
|
141
node_modules/mocha/lib/errors.js
generated
vendored
Normal file
141
node_modules/mocha/lib/errors.js
generated
vendored
Normal file
@ -0,0 +1,141 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module Errors
|
||||
*/
|
||||
/**
|
||||
* Factory functions to create throwable error objects
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates an error object to be thrown when no files to be tested could be found using specified pattern.
|
||||
*
|
||||
* @public
|
||||
* @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 = 'ERR_MOCHA_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 = 'ERR_MOCHA_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
|
||||
* @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 = 'ERR_MOCHA_INVALID_INTERFACE';
|
||||
err.interface = ui;
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error object to be thrown when a behavior, option, or parameter is unsupported.
|
||||
*
|
||||
* @public
|
||||
* @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 = 'ERR_MOCHA_UNSUPPORTED';
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an error object to be thrown when an argument is missing.
|
||||
*
|
||||
* @public
|
||||
* @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
|
||||
* @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 = 'ERR_MOCHA_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
|
||||
* @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 = 'ERR_MOCHA_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
|
||||
* @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 = 'ERR_MOCHA_INVALID_EXCEPTION';
|
||||
err.valueType = typeof value;
|
||||
err.value = value;
|
||||
return err;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
createInvalidArgumentTypeError: createInvalidArgumentTypeError,
|
||||
createInvalidArgumentValueError: createInvalidArgumentValueError,
|
||||
createInvalidExceptionError: createInvalidExceptionError,
|
||||
createInvalidInterfaceError: createInvalidInterfaceError,
|
||||
createInvalidReporterError: createInvalidReporterError,
|
||||
createMissingArgumentError: createMissingArgumentError,
|
||||
createNoFilesMatchPatternError: createNoFilesMatchPatternError,
|
||||
createUnsupportedError: createUnsupportedError
|
||||
};
|
136
node_modules/mocha/lib/growl.js
generated
vendored
Normal file
136
node_modules/mocha/lib/growl.js
generated
vendored
Normal file
@ -0,0 +1,136 @@
|
||||
'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;
|
||||
|
||||
/**
|
||||
* @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 (!process.browser) {
|
||||
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()] || [];
|
||||
};
|
46
node_modules/mocha/lib/hook.js
generated
vendored
Normal file
46
node_modules/mocha/lib/hook.js
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
|
||||
var Runnable = require('./runnable');
|
||||
var inherits = require('./utils').inherits;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* 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;
|
||||
};
|
118
node_modules/mocha/lib/interfaces/bdd.js
generated
vendored
Normal file
118
node_modules/mocha/lib/interfaces/bdd.js
generated
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
'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);
|
||||
};
|
||||
|
||||
/**
|
||||
* Number of attempts to retry.
|
||||
*/
|
||||
context.it.retries = function(n) {
|
||||
context.retries(n);
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.description = 'BDD or RSpec style [default]';
|
191
node_modules/mocha/lib/interfaces/common.js
generated
vendored
Normal file
191
node_modules/mocha/lib/interfaces/common.js
generated
vendored
Normal file
@ -0,0 +1,191 @@
|
||||
'use strict';
|
||||
|
||||
var Suite = require('../suite');
|
||||
var errors = require('../errors');
|
||||
var createMissingArgumentError = errors.createMissingArgumentError;
|
||||
|
||||
/**
|
||||
* Functions common to more than one interface.
|
||||
*
|
||||
* @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) {
|
||||
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) {
|
||||
if (mocha.options.forbidOnly && shouldBeTested(suite)) {
|
||||
throw new Error('`.only` forbidden');
|
||||
}
|
||||
|
||||
suite.parent.appendOnlySuite(suite);
|
||||
}
|
||||
if (suite.pending) {
|
||||
if (mocha.options.forbidPending && shouldBeTested(suite)) {
|
||||
throw new Error('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) {
|
||||
test.parent.appendOnlyTest(test);
|
||||
return test;
|
||||
},
|
||||
|
||||
/**
|
||||
* Pending test case.
|
||||
*
|
||||
* @param {string} title
|
||||
*/
|
||||
skip: function(title) {
|
||||
context.test(title);
|
||||
},
|
||||
|
||||
/**
|
||||
* Number of retry attempts
|
||||
*
|
||||
* @param {number} n
|
||||
*/
|
||||
retries: function(n) {
|
||||
context.retries(n);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
60
node_modules/mocha/lib/interfaces/exports.js
generated
vendored
Normal file
60
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
node_modules/mocha/lib/interfaces/index.js
generated
vendored
Normal file
6
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');
|
99
node_modules/mocha/lib/interfaces/qunit.js
generated
vendored
Normal file
99
node_modules/mocha/lib/interfaces/qunit.js
generated
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
'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;
|
||||
context.test.retries = common.test.retries;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.description = 'QUnit style';
|
107
node_modules/mocha/lib/interfaces/tdd.js
generated
vendored
Normal file
107
node_modules/mocha/lib/interfaces/tdd.js
generated
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
'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;
|
||||
context.test.retries = common.test.retries;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.description =
|
||||
'traditional "suite"/"test" instead of BDD\'s "describe"/"it"';
|
840
node_modules/mocha/lib/mocha.js
generated
vendored
Normal file
840
node_modules/mocha/lib/mocha.js
generated
vendored
Normal file
@ -0,0 +1,840 @@
|
||||
'use strict';
|
||||
|
||||
/*!
|
||||
* mocha
|
||||
* Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
var escapeRe = require('escape-string-regexp');
|
||||
var path = require('path');
|
||||
var builtinReporters = require('./reporters');
|
||||
var growl = require('./growl');
|
||||
var utils = require('./utils');
|
||||
var mocharc = require('./mocharc.json');
|
||||
var errors = require('./errors');
|
||||
var Suite = require('./suite');
|
||||
var createStatsCollector = require('./stats-collector');
|
||||
var createInvalidReporterError = errors.createInvalidReporterError;
|
||||
var createInvalidInterfaceError = errors.createInvalidInterfaceError;
|
||||
var EVENT_FILE_PRE_REQUIRE = Suite.constants.EVENT_FILE_PRE_REQUIRE;
|
||||
var EVENT_FILE_POST_REQUIRE = Suite.constants.EVENT_FILE_POST_REQUIRE;
|
||||
var EVENT_FILE_REQUIRE = Suite.constants.EVENT_FILE_REQUIRE;
|
||||
var sQuote = utils.sQuote;
|
||||
|
||||
exports = module.exports = Mocha;
|
||||
|
||||
/**
|
||||
* To require local UIs and reporters when running in node.
|
||||
*/
|
||||
|
||||
if (!process.browser) {
|
||||
var cwd = process.cwd();
|
||||
module.paths.push(cwd, path.join(cwd, 'node_modules'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose internals.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @class utils
|
||||
* @memberof Mocha
|
||||
*/
|
||||
exports.utils = utils;
|
||||
exports.interfaces = require('./interfaces');
|
||||
/**
|
||||
* @public
|
||||
* @memberof Mocha
|
||||
*/
|
||||
exports.reporters = builtinReporters;
|
||||
exports.Runnable = require('./runnable');
|
||||
exports.Context = require('./context');
|
||||
/**
|
||||
*
|
||||
* @memberof Mocha
|
||||
*/
|
||||
exports.Runner = require('./runner');
|
||||
exports.Suite = Suite;
|
||||
exports.Hook = require('./hook');
|
||||
exports.Test = require('./test');
|
||||
|
||||
/**
|
||||
* Constructs a new Mocha instance with `options`.
|
||||
*
|
||||
* @public
|
||||
* @class Mocha
|
||||
* @param {Object} [options] - Settings object.
|
||||
* @param {boolean} [options.allowUncaught] - Propagate uncaught errors?
|
||||
* @param {boolean} [options.asyncOnly] - Force `done` callback or promise?
|
||||
* @param {boolean} [options.bail] - Bail after first test failure?
|
||||
* @param {boolean} [options.checkLeaks] - If true, check leaks.
|
||||
* @param {boolean} [options.delay] - Delay root suite execution?
|
||||
* @param {boolean} [options.enableTimeouts] - Enable timeouts?
|
||||
* @param {string} [options.fgrep] - Test filter given string.
|
||||
* @param {boolean} [options.forbidOnly] - Tests marked `only` fail the suite?
|
||||
* @param {boolean} [options.forbidPending] - Pending tests fail the suite?
|
||||
* @param {boolean} [options.fullStackTrace] - Full stacktrace upon failure?
|
||||
* @param {string[]} [options.global] - Variables expected in global scope.
|
||||
* @param {RegExp|string} [options.grep] - Test filter given regular expression.
|
||||
* @param {boolean} [options.growl] - Enable desktop notifications?
|
||||
* @param {boolean} [options.hideDiff] - Suppress diffs from failures?
|
||||
* @param {boolean} [options.ignoreLeaks] - Ignore global leaks?
|
||||
* @param {boolean} [options.invert] - Invert test filter matches?
|
||||
* @param {boolean} [options.noHighlighting] - Disable syntax highlighting?
|
||||
* @param {string} [options.reporter] - Reporter name.
|
||||
* @param {Object} [options.reporterOption] - Reporter settings object.
|
||||
* @param {number} [options.retries] - Number of times to retry failed tests.
|
||||
* @param {number} [options.slow] - Slow threshold value.
|
||||
* @param {number|string} [options.timeout] - Timeout threshold value.
|
||||
* @param {string} [options.ui] - Interface name.
|
||||
* @param {boolean} [options.color] - Color TTY output from reporter?
|
||||
* @param {boolean} [options.useInlineDiffs] - Use inline diffs?
|
||||
*/
|
||||
function Mocha(options) {
|
||||
options = utils.assign({}, mocharc, options || {});
|
||||
this.files = [];
|
||||
this.options = options;
|
||||
// root suite
|
||||
this.suite = new exports.Suite('', new exports.Context(), true);
|
||||
|
||||
if ('useColors' in options) {
|
||||
utils.deprecate(
|
||||
'useColors is DEPRECATED and will be removed from a future version of Mocha. Instead, use the "color" option'
|
||||
);
|
||||
options.color = 'color' in options ? options.color : options.useColors;
|
||||
}
|
||||
|
||||
this.grep(options.grep)
|
||||
.fgrep(options.fgrep)
|
||||
.ui(options.ui)
|
||||
.bail(options.bail)
|
||||
.reporter(options.reporter, options.reporterOptions)
|
||||
.useColors(options.color)
|
||||
.slow(options.slow)
|
||||
.useInlineDiffs(options.inlineDiffs)
|
||||
.globals(options.globals);
|
||||
|
||||
if ('enableTimeouts' in options) {
|
||||
utils.deprecate(
|
||||
'enableTimeouts is DEPRECATED and will be removed from a future version of Mocha. Instead, use "timeout: false" to disable timeouts.'
|
||||
);
|
||||
}
|
||||
this.timeout(
|
||||
options.enableTimeouts === false || options.timeout === false
|
||||
? 0
|
||||
: options.timeout
|
||||
);
|
||||
|
||||
if ('retries' in options) {
|
||||
this.retries(options.retries);
|
||||
}
|
||||
|
||||
if ('diff' in options) {
|
||||
this.hideDiff(!options.diff);
|
||||
}
|
||||
|
||||
[
|
||||
'allowUncaught',
|
||||
'asyncOnly',
|
||||
'checkLeaks',
|
||||
'delay',
|
||||
'forbidOnly',
|
||||
'forbidPending',
|
||||
'fullTrace',
|
||||
'growl',
|
||||
'invert'
|
||||
].forEach(function(opt) {
|
||||
if (options[opt]) {
|
||||
this[opt]();
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables bailing on the first failure.
|
||||
*
|
||||
* @public
|
||||
* @see {@link https://mochajs.org/#-b---bail|CLI option}
|
||||
* @param {boolean} [bail=true] - Whether to bail on first error.
|
||||
* @returns {Mocha} this
|
||||
* @chainable
|
||||
*/
|
||||
Mocha.prototype.bail = function(bail) {
|
||||
if (!arguments.length) {
|
||||
bail = true;
|
||||
}
|
||||
this.suite.bail(bail);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @summary
|
||||
* Adds `file` to be loaded for execution.
|
||||
*
|
||||
* @description
|
||||
* Useful for generic setup code that must be included within test suite.
|
||||
*
|
||||
* @public
|
||||
* @see {@link https://mochajs.org/#--file-file|CLI option}
|
||||
* @param {string} file - Pathname of file to be loaded.
|
||||
* @returns {Mocha} this
|
||||
* @chainable
|
||||
*/
|
||||
Mocha.prototype.addFile = function(file) {
|
||||
this.files.push(file);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets reporter to `reporter`, defaults to "spec".
|
||||
*
|
||||
* @public
|
||||
* @see {@link https://mochajs.org/#-r---reporter-name|CLI option}
|
||||
* @see {@link https://mochajs.org/#reporters|Reporters}
|
||||
* @param {String|Function} reporter - Reporter name or constructor.
|
||||
* @param {Object} [reporterOptions] - Options used to configure the reporter.
|
||||
* @returns {Mocha} this
|
||||
* @chainable
|
||||
* @throws {Error} if requested reporter cannot be loaded
|
||||
* @example
|
||||
*
|
||||
* // Use XUnit reporter and direct its output to file
|
||||
* mocha.reporter('xunit', { output: '/path/to/testspec.xunit.xml' });
|
||||
*/
|
||||
Mocha.prototype.reporter = function(reporter, reporterOptions) {
|
||||
if (typeof reporter === 'function') {
|
||||
this._reporter = reporter;
|
||||
} else {
|
||||
reporter = reporter || 'spec';
|
||||
var _reporter;
|
||||
// Try to load a built-in reporter.
|
||||
if (builtinReporters[reporter]) {
|
||||
_reporter = builtinReporters[reporter];
|
||||
}
|
||||
// Try to load reporters from process.cwd() and node_modules
|
||||
if (!_reporter) {
|
||||
try {
|
||||
_reporter = require(reporter);
|
||||
} catch (err) {
|
||||
if (
|
||||
err.code !== 'MODULE_NOT_FOUND' ||
|
||||
err.message.indexOf('Cannot find module') !== -1
|
||||
) {
|
||||
// Try to load reporters from a path (absolute or relative)
|
||||
try {
|
||||
_reporter = require(path.resolve(process.cwd(), reporter));
|
||||
} catch (_err) {
|
||||
_err.code !== 'MODULE_NOT_FOUND' ||
|
||||
_err.message.indexOf('Cannot find module') !== -1
|
||||
? console.warn(sQuote(reporter) + ' reporter not found')
|
||||
: console.warn(
|
||||
sQuote(reporter) +
|
||||
' reporter blew up with error:\n' +
|
||||
err.stack
|
||||
);
|
||||
}
|
||||
} else {
|
||||
console.warn(
|
||||
sQuote(reporter) + ' reporter blew up with error:\n' + err.stack
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!_reporter) {
|
||||
throw createInvalidReporterError(
|
||||
'invalid reporter ' + sQuote(reporter),
|
||||
reporter
|
||||
);
|
||||
}
|
||||
this._reporter = _reporter;
|
||||
}
|
||||
this.options.reporterOptions = reporterOptions;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets test UI `name`, defaults to "bdd".
|
||||
*
|
||||
* @public
|
||||
* @see {@link https://mochajs.org/#-u---ui-name|CLI option}
|
||||
* @see {@link https://mochajs.org/#interfaces|Interface DSLs}
|
||||
* @param {string|Function} [ui=bdd] - Interface name or class.
|
||||
* @returns {Mocha} this
|
||||
* @chainable
|
||||
* @throws {Error} if requested interface cannot be loaded
|
||||
*/
|
||||
Mocha.prototype.ui = function(ui) {
|
||||
var bindInterface;
|
||||
if (typeof ui === 'function') {
|
||||
bindInterface = ui;
|
||||
} else {
|
||||
ui = ui || 'bdd';
|
||||
bindInterface = exports.interfaces[ui];
|
||||
if (!bindInterface) {
|
||||
try {
|
||||
bindInterface = require(ui);
|
||||
} catch (err) {
|
||||
throw createInvalidInterfaceError(
|
||||
'invalid interface ' + sQuote(ui),
|
||||
ui
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
bindInterface(this.suite);
|
||||
|
||||
this.suite.on(EVENT_FILE_PRE_REQUIRE, function(context) {
|
||||
exports.afterEach = context.afterEach || context.teardown;
|
||||
exports.after = context.after || context.suiteTeardown;
|
||||
exports.beforeEach = context.beforeEach || context.setup;
|
||||
exports.before = context.before || context.suiteSetup;
|
||||
exports.describe = context.describe || context.suite;
|
||||
exports.it = context.it || context.test;
|
||||
exports.xit = context.xit || (context.test && context.test.skip);
|
||||
exports.setup = context.setup || context.beforeEach;
|
||||
exports.suiteSetup = context.suiteSetup || context.before;
|
||||
exports.suiteTeardown = context.suiteTeardown || context.after;
|
||||
exports.suite = context.suite || context.describe;
|
||||
exports.teardown = context.teardown || context.afterEach;
|
||||
exports.test = context.test || context.it;
|
||||
exports.run = context.run;
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Loads `files` prior to execution.
|
||||
*
|
||||
* @description
|
||||
* The implementation relies on Node's `require` to execute
|
||||
* the test interface functions and will be subject to its cache.
|
||||
*
|
||||
* @private
|
||||
* @see {@link Mocha#addFile}
|
||||
* @see {@link Mocha#run}
|
||||
* @see {@link Mocha#unloadFiles}
|
||||
* @param {Function} [fn] - Callback invoked upon completion.
|
||||
*/
|
||||
Mocha.prototype.loadFiles = function(fn) {
|
||||
var self = this;
|
||||
var suite = this.suite;
|
||||
this.files.forEach(function(file) {
|
||||
file = path.resolve(file);
|
||||
suite.emit(EVENT_FILE_PRE_REQUIRE, global, file, self);
|
||||
suite.emit(EVENT_FILE_REQUIRE, require(file), file, self);
|
||||
suite.emit(EVENT_FILE_POST_REQUIRE, global, file, self);
|
||||
});
|
||||
fn && fn();
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes a previously loaded file from Node's `require` cache.
|
||||
*
|
||||
* @private
|
||||
* @static
|
||||
* @see {@link Mocha#unloadFiles}
|
||||
* @param {string} file - Pathname of file to be unloaded.
|
||||
*/
|
||||
Mocha.unloadFile = function(file) {
|
||||
delete require.cache[require.resolve(file)];
|
||||
};
|
||||
|
||||
/**
|
||||
* Unloads `files` from Node's `require` cache.
|
||||
*
|
||||
* @description
|
||||
* This allows files to be "freshly" reloaded, providing the ability
|
||||
* to reuse a Mocha instance programmatically.
|
||||
*
|
||||
* <strong>Intended for consumers — not used internally</strong>
|
||||
*
|
||||
* @public
|
||||
* @see {@link Mocha.unloadFile}
|
||||
* @see {@link Mocha#loadFiles}
|
||||
* @see {@link Mocha#run}
|
||||
* @returns {Mocha} this
|
||||
* @chainable
|
||||
*/
|
||||
Mocha.prototype.unloadFiles = function() {
|
||||
this.files.forEach(Mocha.unloadFile);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets `grep` filter after escaping RegExp special characters.
|
||||
*
|
||||
* @public
|
||||
* @see {@link Mocha#grep}
|
||||
* @param {string} str - Value to be converted to a regexp.
|
||||
* @returns {Mocha} this
|
||||
* @chainable
|
||||
* @example
|
||||
*
|
||||
* // Select tests whose full title begins with `"foo"` followed by a period
|
||||
* mocha.fgrep('foo.');
|
||||
*/
|
||||
Mocha.prototype.fgrep = function(str) {
|
||||
if (!str) {
|
||||
return this;
|
||||
}
|
||||
return this.grep(new RegExp(escapeRe(str)));
|
||||
};
|
||||
|
||||
/**
|
||||
* @summary
|
||||
* Sets `grep` filter used to select specific tests for execution.
|
||||
*
|
||||
* @description
|
||||
* If `re` is a regexp-like string, it will be converted to regexp.
|
||||
* The regexp is tested against the full title of each test (i.e., the
|
||||
* name of the test preceded by titles of each its ancestral suites).
|
||||
* As such, using an <em>exact-match</em> fixed pattern against the
|
||||
* test name itself will not yield any matches.
|
||||
* <br>
|
||||
* <strong>Previous filter value will be overwritten on each call!</strong>
|
||||
*
|
||||
* @public
|
||||
* @see {@link https://mochajs.org/#-g---grep-pattern|CLI option}
|
||||
* @see {@link Mocha#fgrep}
|
||||
* @see {@link Mocha#invert}
|
||||
* @param {RegExp|String} re - Regular expression used to select tests.
|
||||
* @return {Mocha} this
|
||||
* @chainable
|
||||
* @example
|
||||
*
|
||||
* // Select tests whose full title contains `"match"`, ignoring case
|
||||
* mocha.grep(/match/i);
|
||||
* @example
|
||||
*
|
||||
* // Same as above but with regexp-like string argument
|
||||
* mocha.grep('/match/i');
|
||||
* @example
|
||||
*
|
||||
* // ## Anti-example
|
||||
* // Given embedded test `it('only-this-test')`...
|
||||
* mocha.grep('/^only-this-test$/'); // NO! Use `.only()` to do this!
|
||||
*/
|
||||
Mocha.prototype.grep = function(re) {
|
||||
if (utils.isString(re)) {
|
||||
// extract args if it's regex-like, i.e: [string, pattern, flag]
|
||||
var arg = re.match(/^\/(.*)\/(g|i|)$|.*/);
|
||||
this.options.grep = new RegExp(arg[1] || arg[0], arg[2]);
|
||||
} else {
|
||||
this.options.grep = re;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Inverts `grep` matches.
|
||||
*
|
||||
* @public
|
||||
* @see {@link Mocha#grep}
|
||||
* @return {Mocha} this
|
||||
* @chainable
|
||||
* @example
|
||||
*
|
||||
* // Select tests whose full title does *not* contain `"match"`, ignoring case
|
||||
* mocha.grep(/match/i).invert();
|
||||
*/
|
||||
Mocha.prototype.invert = function() {
|
||||
this.options.invert = true;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Enables or disables ignoring global leaks.
|
||||
*
|
||||
* @public
|
||||
* @see {@link Mocha#checkLeaks}
|
||||
* @param {boolean} ignoreLeaks - Whether to ignore global leaks.
|
||||
* @return {Mocha} this
|
||||
* @chainable
|
||||
* @example
|
||||
*
|
||||
* // Ignore global leaks
|
||||
* mocha.ignoreLeaks(true);
|
||||
*/
|
||||
Mocha.prototype.ignoreLeaks = function(ignoreLeaks) {
|
||||
this.options.ignoreLeaks = Boolean(ignoreLeaks);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Enables checking for global variables leaked while running tests.
|
||||
*
|
||||
* @public
|
||||
* @see {@link https://mochajs.org/#--check-leaks|CLI option}
|
||||
* @see {@link Mocha#ignoreLeaks}
|
||||
* @return {Mocha} this
|
||||
* @chainable
|
||||
*/
|
||||
Mocha.prototype.checkLeaks = function() {
|
||||
this.options.ignoreLeaks = false;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Displays full stack trace upon test failure.
|
||||
*
|
||||
* @public
|
||||
* @return {Mocha} this
|
||||
* @chainable
|
||||
*/
|
||||
Mocha.prototype.fullTrace = function() {
|
||||
this.options.fullStackTrace = true;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Enables desktop notification support if prerequisite software installed.
|
||||
*
|
||||
* @public
|
||||
* @see {@link Mocha#isGrowlCapable}
|
||||
* @see {@link Mocha#_growl}
|
||||
* @return {Mocha} this
|
||||
* @chainable
|
||||
*/
|
||||
Mocha.prototype.growl = function() {
|
||||
this.options.growl = this.isGrowlCapable();
|
||||
if (!this.options.growl) {
|
||||
var detail = process.browser
|
||||
? 'notification support not available in this browser...'
|
||||
: 'notification support prerequisites not installed...';
|
||||
console.error(detail + ' cannot enable!');
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @summary
|
||||
* Determines if Growl support seems likely.
|
||||
*
|
||||
* @description
|
||||
* <strong>Not available when run in browser.</strong>
|
||||
*
|
||||
* @private
|
||||
* @see {@link Growl#isCapable}
|
||||
* @see {@link Mocha#growl}
|
||||
* @return {boolean} whether Growl support can be expected
|
||||
*/
|
||||
Mocha.prototype.isGrowlCapable = growl.isCapable;
|
||||
|
||||
/**
|
||||
* Implements desktop notifications using a pseudo-reporter.
|
||||
*
|
||||
* @private
|
||||
* @see {@link Mocha#growl}
|
||||
* @see {@link Growl#notify}
|
||||
* @param {Runner} runner - Runner instance.
|
||||
*/
|
||||
Mocha.prototype._growl = growl.notify;
|
||||
|
||||
/**
|
||||
* Specifies whitelist of variable names to be expected in global scope.
|
||||
*
|
||||
* @public
|
||||
* @see {@link https://mochajs.org/#--globals-names|CLI option}
|
||||
* @see {@link Mocha#checkLeaks}
|
||||
* @param {String[]|String} globals - Accepted global variable name(s).
|
||||
* @return {Mocha} this
|
||||
* @chainable
|
||||
* @example
|
||||
*
|
||||
* // Specify variables to be expected in global scope
|
||||
* mocha.globals(['jQuery', 'MyLib']);
|
||||
*/
|
||||
Mocha.prototype.globals = function(globals) {
|
||||
this.options.globals = (this.options.globals || [])
|
||||
.concat(globals)
|
||||
.filter(Boolean);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Enables or disables TTY color output by screen-oriented reporters.
|
||||
*
|
||||
* @public
|
||||
* @param {boolean} colors - Whether to enable color output.
|
||||
* @return {Mocha} this
|
||||
* @chainable
|
||||
*/
|
||||
Mocha.prototype.useColors = function(colors) {
|
||||
if (colors !== undefined) {
|
||||
this.options.useColors = colors;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determines if reporter should use inline diffs (rather than +/-)
|
||||
* in test failure output.
|
||||
*
|
||||
* @public
|
||||
* @param {boolean} inlineDiffs - Whether to use inline diffs.
|
||||
* @return {Mocha} this
|
||||
* @chainable
|
||||
*/
|
||||
Mocha.prototype.useInlineDiffs = function(inlineDiffs) {
|
||||
this.options.useInlineDiffs = inlineDiffs !== undefined && inlineDiffs;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determines if reporter should include diffs in test failure output.
|
||||
*
|
||||
* @public
|
||||
* @param {boolean} hideDiff - Whether to hide diffs.
|
||||
* @return {Mocha} this
|
||||
* @chainable
|
||||
*/
|
||||
Mocha.prototype.hideDiff = function(hideDiff) {
|
||||
this.options.hideDiff = hideDiff !== undefined && hideDiff;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @summary
|
||||
* Sets timeout threshold value.
|
||||
*
|
||||
* @description
|
||||
* A string argument can use shorthand (such as "2s") and will be converted.
|
||||
* If the value is `0`, timeouts will be disabled.
|
||||
*
|
||||
* @public
|
||||
* @see {@link https://mochajs.org/#-t---timeout-ms|CLI option}
|
||||
* @see {@link https://mochajs.org/#--no-timeouts|CLI option}
|
||||
* @see {@link https://mochajs.org/#timeouts|Timeouts}
|
||||
* @see {@link Mocha#enableTimeouts}
|
||||
* @param {number|string} msecs - Timeout threshold value.
|
||||
* @return {Mocha} this
|
||||
* @chainable
|
||||
* @example
|
||||
*
|
||||
* // Sets timeout to one second
|
||||
* mocha.timeout(1000);
|
||||
* @example
|
||||
*
|
||||
* // Same as above but using string argument
|
||||
* mocha.timeout('1s');
|
||||
*/
|
||||
Mocha.prototype.timeout = function(msecs) {
|
||||
this.suite.timeout(msecs);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the number of times to retry failed tests.
|
||||
*
|
||||
* @public
|
||||
* @see {@link https://mochajs.org/#retry-tests|Retry Tests}
|
||||
* @param {number} retry - Number of times to retry failed tests.
|
||||
* @return {Mocha} this
|
||||
* @chainable
|
||||
* @example
|
||||
*
|
||||
* // Allow any failed test to retry one more time
|
||||
* mocha.retries(1);
|
||||
*/
|
||||
Mocha.prototype.retries = function(n) {
|
||||
this.suite.retries(n);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets slowness threshold value.
|
||||
*
|
||||
* @public
|
||||
* @see {@link https://mochajs.org/#-s---slow-ms|CLI option}
|
||||
* @param {number} msecs - Slowness threshold value.
|
||||
* @return {Mocha} this
|
||||
* @chainable
|
||||
* @example
|
||||
*
|
||||
* // Sets "slow" threshold to half a second
|
||||
* mocha.slow(500);
|
||||
* @example
|
||||
*
|
||||
* // Same as above but using string argument
|
||||
* mocha.slow('0.5s');
|
||||
*/
|
||||
Mocha.prototype.slow = function(msecs) {
|
||||
this.suite.slow(msecs);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Enables or disables timeouts.
|
||||
*
|
||||
* @public
|
||||
* @see {@link https://mochajs.org/#-t---timeout-ms|CLI option}
|
||||
* @see {@link https://mochajs.org/#--no-timeouts|CLI option}
|
||||
* @param {boolean} enableTimeouts - Whether to enable timeouts.
|
||||
* @return {Mocha} this
|
||||
* @chainable
|
||||
*/
|
||||
Mocha.prototype.enableTimeouts = function(enableTimeouts) {
|
||||
this.suite.enableTimeouts(
|
||||
arguments.length && enableTimeouts !== undefined ? enableTimeouts : true
|
||||
);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Forces all tests to either accept a `done` callback or return a promise.
|
||||
*
|
||||
* @public
|
||||
* @return {Mocha} this
|
||||
* @chainable
|
||||
*/
|
||||
Mocha.prototype.asyncOnly = function() {
|
||||
this.options.asyncOnly = true;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Disables syntax highlighting (in browser).
|
||||
*
|
||||
* @public
|
||||
* @return {Mocha} this
|
||||
* @chainable
|
||||
*/
|
||||
Mocha.prototype.noHighlighting = function() {
|
||||
this.options.noHighlighting = true;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Enables uncaught errors to propagate (in browser).
|
||||
*
|
||||
* @public
|
||||
* @return {Mocha} this
|
||||
* @chainable
|
||||
*/
|
||||
Mocha.prototype.allowUncaught = function() {
|
||||
this.options.allowUncaught = true;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @summary
|
||||
* Delays root suite execution.
|
||||
*
|
||||
* @description
|
||||
* Used to perform asynch operations before any suites are run.
|
||||
*
|
||||
* @public
|
||||
* @see {@link https://mochajs.org/#delayed-root-suite|delayed root suite}
|
||||
* @returns {Mocha} this
|
||||
* @chainable
|
||||
*/
|
||||
Mocha.prototype.delay = function delay() {
|
||||
this.options.delay = true;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Causes tests marked `only` to fail the suite.
|
||||
*
|
||||
* @public
|
||||
* @returns {Mocha} this
|
||||
* @chainable
|
||||
*/
|
||||
Mocha.prototype.forbidOnly = function() {
|
||||
this.options.forbidOnly = true;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Causes pending tests and tests marked `skip` to fail the suite.
|
||||
*
|
||||
* @public
|
||||
* @returns {Mocha} this
|
||||
* @chainable
|
||||
*/
|
||||
Mocha.prototype.forbidPending = function() {
|
||||
this.options.forbidPending = true;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Mocha version as specified by "package.json".
|
||||
*
|
||||
* @name Mocha#version
|
||||
* @type string
|
||||
* @readonly
|
||||
*/
|
||||
Object.defineProperty(Mocha.prototype, 'version', {
|
||||
value: require('../package.json').version,
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
writable: false
|
||||
});
|
||||
|
||||
/**
|
||||
* Callback to be invoked when test execution is complete.
|
||||
*
|
||||
* @callback DoneCB
|
||||
* @param {number} failures - Number of failures that occurred.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Runs root suite and invokes `fn()` when complete.
|
||||
*
|
||||
* @description
|
||||
* To run tests multiple times (or to run tests in files that are
|
||||
* already in the `require` cache), make sure to clear them from
|
||||
* the cache first!
|
||||
*
|
||||
* @public
|
||||
* @see {@link Mocha#loadFiles}
|
||||
* @see {@link Mocha#unloadFiles}
|
||||
* @see {@link Runner#run}
|
||||
* @param {DoneCB} [fn] - Callback invoked when test execution completed.
|
||||
* @return {Runner} runner instance
|
||||
*/
|
||||
Mocha.prototype.run = function(fn) {
|
||||
if (this.files.length) {
|
||||
this.loadFiles();
|
||||
}
|
||||
var suite = this.suite;
|
||||
var options = this.options;
|
||||
options.files = this.files;
|
||||
var runner = new exports.Runner(suite, options.delay);
|
||||
createStatsCollector(runner);
|
||||
var reporter = new this._reporter(runner, options);
|
||||
runner.ignoreLeaks = options.ignoreLeaks !== false;
|
||||
runner.fullStackTrace = options.fullStackTrace;
|
||||
runner.asyncOnly = options.asyncOnly;
|
||||
runner.allowUncaught = options.allowUncaught;
|
||||
runner.forbidOnly = options.forbidOnly;
|
||||
runner.forbidPending = options.forbidPending;
|
||||
if (options.grep) {
|
||||
runner.grep(options.grep, options.invert);
|
||||
}
|
||||
if (options.globals) {
|
||||
runner.globals(options.globals);
|
||||
}
|
||||
if (options.growl) {
|
||||
this._growl(runner);
|
||||
}
|
||||
if (options.useColors !== undefined) {
|
||||
exports.reporters.Base.useColors = options.useColors;
|
||||
}
|
||||
exports.reporters.Base.inlineDiffs = options.useInlineDiffs;
|
||||
exports.reporters.Base.hideDiff = options.hideDiff;
|
||||
|
||||
function done(failures) {
|
||||
fn = fn || utils.noop;
|
||||
if (reporter.done) {
|
||||
reporter.done(failures, fn);
|
||||
} else {
|
||||
fn(failures);
|
||||
}
|
||||
}
|
||||
|
||||
return runner.run(done);
|
||||
};
|
10
node_modules/mocha/lib/mocharc.json
generated
vendored
Normal file
10
node_modules/mocha/lib/mocharc.json
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"diff": true,
|
||||
"extension": ["js"],
|
||||
"opts": "./test/mocha.opts",
|
||||
"package": "./package.json",
|
||||
"reporter": "spec",
|
||||
"slow": 75,
|
||||
"timeout": 2000,
|
||||
"ui": "bdd"
|
||||
}
|
12
node_modules/mocha/lib/pending.js
generated
vendored
Normal file
12
node_modules/mocha/lib/pending.js
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = Pending;
|
||||
|
||||
/**
|
||||
* Initialize a new `Pending` error with the given message.
|
||||
*
|
||||
* @param {string} message
|
||||
*/
|
||||
function Pending(message) {
|
||||
this.message = message;
|
||||
}
|
490
node_modules/mocha/lib/reporters/base.js
generated
vendored
Normal file
490
node_modules/mocha/lib/reporters/base.js
generated
vendored
Normal file
@ -0,0 +1,490 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module Base
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var tty = require('tty');
|
||||
var diff = require('diff');
|
||||
var milliseconds = require('ms');
|
||||
var utils = require('../utils');
|
||||
var supportsColor = process.browser ? null : require('supports-color');
|
||||
var constants = require('../runner').constants;
|
||||
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
||||
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
||||
|
||||
/**
|
||||
* Expose `Base`.
|
||||
*/
|
||||
|
||||
exports = module.exports = Base;
|
||||
|
||||
/**
|
||||
* Check if both stdio streams are associated with a tty.
|
||||
*/
|
||||
|
||||
var isatty = tty.isatty(1) && tty.isatty(2);
|
||||
|
||||
/**
|
||||
* Enable coloring by default, except in the browser interface.
|
||||
*/
|
||||
|
||||
exports.useColors =
|
||||
!process.browser &&
|
||||
(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
|
||||
};
|
||||
|
||||
/**
|
||||
* Default symbol map.
|
||||
*/
|
||||
|
||||
exports.symbols = {
|
||||
ok: '✓',
|
||||
err: '✖',
|
||||
dot: '․',
|
||||
comma: ',',
|
||||
bang: '!'
|
||||
};
|
||||
|
||||
// With node.js on Windows: use symbols available in terminal default fonts
|
||||
if (process.platform === 'win32') {
|
||||
exports.symbols.ok = '\u221A';
|
||||
exports.symbols.err = '\u00D7';
|
||||
exports.symbols.dot = '.';
|
||||
}
|
||||
|
||||
/**
|
||||
* Color `str` with the given `type`,
|
||||
* allowing colors to be disabled,
|
||||
* as well as user-defined color
|
||||
* schemes.
|
||||
*
|
||||
* @param {string} type
|
||||
* @param {string} str
|
||||
* @return {string}
|
||||
* @private
|
||||
*/
|
||||
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) {
|
||||
exports.window.width = process.stdout.getWindowSize
|
||||
? process.stdout.getWindowSize(1)[0]
|
||||
: tty.getWindowSize()[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function showDiff(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.
|
||||
*
|
||||
* The diff will be either inline or unified dependant on the value
|
||||
* of `Base.inlineDiff`.
|
||||
*
|
||||
* @param {string} actual
|
||||
* @param {string} expected
|
||||
* @return {string} Diff
|
||||
*/
|
||||
var generateDiff = (exports.generateDiff = function(actual, expected) {
|
||||
return exports.inlineDiffs
|
||||
? inlineDiff(actual, expected)
|
||||
: unifiedDiff(actual, expected);
|
||||
});
|
||||
|
||||
/**
|
||||
* Output the given `failures` as a list.
|
||||
*
|
||||
* @public
|
||||
* @memberof Mocha.reporters.Base
|
||||
* @variation 1
|
||||
* @param {Array} failures
|
||||
*/
|
||||
|
||||
exports.list = function(failures) {
|
||||
console.log();
|
||||
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 = test.err;
|
||||
var message;
|
||||
if (err.message && typeof err.message.toString === 'function') {
|
||||
message = err.message + '';
|
||||
} else if (typeof err.inspect === 'function') {
|
||||
message = err.inspect() + '';
|
||||
} 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;
|
||||
});
|
||||
|
||||
console.log(fmt, i + 1, testTitle, msg, stack);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize a new `Base` reporter.
|
||||
*
|
||||
* All other reporters generally
|
||||
* inherit from this reporter.
|
||||
*
|
||||
* @memberof Mocha.reporters
|
||||
* @public
|
||||
* @class
|
||||
* @param {Runner} runner
|
||||
*/
|
||||
|
||||
function Base(runner) {
|
||||
var failures = (this.failures = []);
|
||||
|
||||
if (!runner) {
|
||||
throw new TypeError('Missing runner argument');
|
||||
}
|
||||
this.stats = runner.stats; // assigned so Reporters keep a closer reference
|
||||
this.runner = runner;
|
||||
|
||||
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);
|
||||
}
|
||||
test.err = err;
|
||||
failures.push(test);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Output common epilogue used by many of
|
||||
* the bundled reporters.
|
||||
*
|
||||
* @memberof Mocha.reporters.Base
|
||||
* @public
|
||||
*/
|
||||
Base.prototype.epilogue = function() {
|
||||
var stats = this.stats;
|
||||
var fmt;
|
||||
|
||||
console.log();
|
||||
|
||||
// passes
|
||||
fmt =
|
||||
color('bright pass', ' ') +
|
||||
color('green', ' %d passing') +
|
||||
color('light', ' (%s)');
|
||||
|
||||
console.log(fmt, stats.passes || 0, milliseconds(stats.duration));
|
||||
|
||||
// pending
|
||||
if (stats.pending) {
|
||||
fmt = color('pending', ' ') + color('pending', ' %d pending');
|
||||
|
||||
console.log(fmt, stats.pending);
|
||||
}
|
||||
|
||||
// failures
|
||||
if (stats.failures) {
|
||||
fmt = color('fail', ' %d failing');
|
||||
|
||||
console.log(fmt, stats.failures);
|
||||
|
||||
Base.list(this.failures);
|
||||
console.log();
|
||||
}
|
||||
|
||||
console.log();
|
||||
};
|
||||
|
||||
/**
|
||||
* Pad 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 an 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', 'actual') +
|
||||
' ' +
|
||||
color('diff added', 'expected') +
|
||||
'\n\n' +
|
||||
msg +
|
||||
'\n';
|
||||
|
||||
// indent
|
||||
msg = msg.replace(/^/gm, ' ');
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a 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')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a 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', str.value);
|
||||
}
|
||||
if (str.removed) {
|
||||
return colorLines('diff removed', str.value);
|
||||
}
|
||||
return str.value;
|
||||
})
|
||||
.join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Color 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;
|
||||
|
||||
/**
|
||||
* Check 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.abstract = true;
|
84
node_modules/mocha/lib/reporters/doc.js
generated
vendored
Normal file
84
node_modules/mocha/lib/reporters/doc.js
generated
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
'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;
|
||||
|
||||
/**
|
||||
* Initialize a new `Doc` reporter.
|
||||
*
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends {Base}
|
||||
* @public
|
||||
* @param {Runner} runner
|
||||
*/
|
||||
function Doc(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
var indents = 2;
|
||||
|
||||
function indent() {
|
||||
return Array(indents).join(' ');
|
||||
}
|
||||
|
||||
runner.on(EVENT_SUITE_BEGIN, function(suite) {
|
||||
if (suite.root) {
|
||||
return;
|
||||
}
|
||||
++indents;
|
||||
console.log('%s<section class="suite">', indent());
|
||||
++indents;
|
||||
console.log('%s<h1>%s</h1>', indent(), utils.escape(suite.title));
|
||||
console.log('%s<dl>', indent());
|
||||
});
|
||||
|
||||
runner.on(EVENT_SUITE_END, function(suite) {
|
||||
if (suite.root) {
|
||||
return;
|
||||
}
|
||||
console.log('%s</dl>', indent());
|
||||
--indents;
|
||||
console.log('%s</section>', indent());
|
||||
--indents;
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PASS, function(test) {
|
||||
console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title));
|
||||
var code = utils.escape(utils.clean(test.body));
|
||||
console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function(test, err) {
|
||||
console.log(
|
||||
'%s <dt class="error">%s</dt>',
|
||||
indent(),
|
||||
utils.escape(test.title)
|
||||
);
|
||||
var code = utils.escape(utils.clean(test.body));
|
||||
console.log(
|
||||
'%s <dd class="error"><pre><code>%s</code></pre></dd>',
|
||||
indent(),
|
||||
code
|
||||
);
|
||||
console.log('%s <dd class="error">%s</dd>', indent(), utils.escape(err));
|
||||
});
|
||||
}
|
||||
|
||||
Doc.description = 'HTML documentation';
|
80
node_modules/mocha/lib/reporters/dot.js
generated
vendored
Normal file
80
node_modules/mocha/lib/reporters/dot.js
generated
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
'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;
|
||||
|
||||
/**
|
||||
* Initialize a new `Dot` matrix test reporter.
|
||||
*
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @public
|
||||
* @param {Runner} runner
|
||||
*/
|
||||
function Dot(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
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() {
|
||||
console.log();
|
||||
self.epilogue();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Base.prototype`.
|
||||
*/
|
||||
inherits(Dot, Base);
|
||||
|
||||
Dot.description = 'dot matrix representation';
|
389
node_modules/mocha/lib/reporters/html.js
generated
vendored
Normal file
389
node_modules/mocha/lib/reporters/html.js
generated
vendored
Normal file
@ -0,0 +1,389 @@
|
||||
'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 = '‣';
|
||||
|
||||
/**
|
||||
* Initialize a new `HTML` reporter.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner
|
||||
*/
|
||||
function HTML(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
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');
|
||||
for (var i = 0; i < els.length; ++i) {
|
||||
els[i].className = els[i].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
node_modules/mocha/lib/reporters/index.js
generated
vendored
Normal file
19
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');
|
89
node_modules/mocha/lib/reporters/json-stream.js
generated
vendored
Normal file
89
node_modules/mocha/lib/reporters/json-stream.js
generated
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
'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
|
||||
* @extends Mocha.reporters.Base
|
||||
* @memberof Mocha.reporters
|
||||
* @param {Runner} runner - Instance triggers reporter actions.
|
||||
*/
|
||||
function JSONStream(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
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(),
|
||||
duration: test.duration,
|
||||
currentRetry: test.currentRetry()
|
||||
};
|
||||
}
|
||||
|
||||
JSONStream.description = 'newline delimited JSON events';
|
134
node_modules/mocha/lib/reporters/json.js
generated
vendored
Normal file
134
node_modules/mocha/lib/reporters/json.js
generated
vendored
Normal file
@ -0,0 +1,134 @@
|
||||
'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;
|
||||
|
||||
/**
|
||||
* Initialize a new `JSON` reporter.
|
||||
*
|
||||
* @public
|
||||
* @class JSON
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner
|
||||
*/
|
||||
function JSONReporter(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
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(),
|
||||
duration: test.duration,
|
||||
currentRetry: test.currentRetry(),
|
||||
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';
|
107
node_modules/mocha/lib/reporters/landing.js
generated
vendored
Normal file
107
node_modules/mocha/lib/reporters/landing.js
generated
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
'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;
|
||||
|
||||
/**
|
||||
* Initialize a new `Landing` reporter.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner
|
||||
*/
|
||||
function Landing(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
var self = this;
|
||||
var width = (Base.window.width * 0.75) | 0;
|
||||
var total = runner.total;
|
||||
var stream = process.stdout;
|
||||
var plane = color('plane', '✈');
|
||||
var crashed = -1;
|
||||
var n = 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();
|
||||
console.log();
|
||||
self.epilogue();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Base.prototype`.
|
||||
*/
|
||||
inherits(Landing, Base);
|
||||
|
||||
Landing.description = 'Unicode landing strip';
|
77
node_modules/mocha/lib/reporters/list.js
generated
vendored
Normal file
77
node_modules/mocha/lib/reporters/list.js
generated
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
'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;
|
||||
|
||||
/**
|
||||
* Initialize a new `List` test reporter.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner
|
||||
*/
|
||||
function List(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
var self = this;
|
||||
var n = 0;
|
||||
|
||||
runner.on(EVENT_RUN_BEGIN, function() {
|
||||
console.log();
|
||||
});
|
||||
|
||||
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');
|
||||
console.log(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();
|
||||
console.log(fmt, test.fullTitle(), test.duration);
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function(test) {
|
||||
cursor.CR();
|
||||
console.log(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';
|
111
node_modules/mocha/lib/reporters/markdown.js
generated
vendored
Normal file
111
node_modules/mocha/lib/reporters/markdown.js
generated
vendored
Normal file
@ -0,0 +1,111 @@
|
||||
'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;
|
||||
|
||||
/**
|
||||
* Initialize a new `Markdown` reporter.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner
|
||||
*/
|
||||
function Markdown(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
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';
|
48
node_modules/mocha/lib/reporters/min.js
generated
vendored
Normal file
48
node_modules/mocha/lib/reporters/min.js
generated
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
'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;
|
||||
|
||||
/**
|
||||
* Initialize a new `Min` minimal test reporter (best used with --watch).
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner
|
||||
*/
|
||||
function Min(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
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
node_modules/mocha/lib/reporters/nyan.js
generated
vendored
Normal file
276
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;
|
||||
|
||||
/**
|
||||
* Initialize a new `Dot` matrix test reporter.
|
||||
*
|
||||
* @param {Runner} runner
|
||||
* @public
|
||||
* @class Nyan
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
*/
|
||||
|
||||
function NyanCat(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
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
node_modules/mocha/lib/reporters/progress.js
generated
vendored
Normal file
104
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;
|
||||
|
||||
/**
|
||||
* Initialize a new `Progress` bar test reporter.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner
|
||||
* @param {Object} options
|
||||
*/
|
||||
function Progress(runner, options) {
|
||||
Base.call(this, runner);
|
||||
|
||||
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() {
|
||||
console.log();
|
||||
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();
|
||||
console.log();
|
||||
self.epilogue();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Base.prototype`.
|
||||
*/
|
||||
inherits(Progress, Base);
|
||||
|
||||
Progress.description = 'a progress bar';
|
98
node_modules/mocha/lib/reporters/spec.js
generated
vendored
Normal file
98
node_modules/mocha/lib/reporters/spec.js
generated
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
'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;
|
||||
|
||||
/**
|
||||
* Initialize a new `Spec` test reporter.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner
|
||||
*/
|
||||
function Spec(runner) {
|
||||
Base.call(this, runner);
|
||||
|
||||
var self = this;
|
||||
var indents = 0;
|
||||
var n = 0;
|
||||
|
||||
function indent() {
|
||||
return Array(indents).join(' ');
|
||||
}
|
||||
|
||||
runner.on(EVENT_RUN_BEGIN, function() {
|
||||
console.log();
|
||||
});
|
||||
|
||||
runner.on(EVENT_SUITE_BEGIN, function(suite) {
|
||||
++indents;
|
||||
console.log(color('suite', '%s%s'), indent(), suite.title);
|
||||
});
|
||||
|
||||
runner.on(EVENT_SUITE_END, function() {
|
||||
--indents;
|
||||
if (indents === 1) {
|
||||
console.log();
|
||||
}
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_PENDING, function(test) {
|
||||
var fmt = indent() + color('pending', ' - %s');
|
||||
console.log(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');
|
||||
console.log(fmt, test.title);
|
||||
} else {
|
||||
fmt =
|
||||
indent() +
|
||||
color('checkmark', ' ' + Base.symbols.ok) +
|
||||
color('pass', ' %s') +
|
||||
color(test.speed, ' (%dms)');
|
||||
console.log(fmt, test.title, test.duration);
|
||||
}
|
||||
});
|
||||
|
||||
runner.on(EVENT_TEST_FAIL, function(test) {
|
||||
console.log(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]';
|
294
node_modules/mocha/lib/reporters/tap.js
generated
vendored
Normal file
294
node_modules/mocha/lib/reporters/tap.js
generated
vendored
Normal file
@ -0,0 +1,294 @@
|
||||
'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 with runner instance and reporter options.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @extends Mocha.reporters.Base
|
||||
* @memberof Mocha.reporters
|
||||
* @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() {
|
||||
var ntests = runner.grepTotal(runner.suite);
|
||||
self._producer.writeVersion();
|
||||
self._producer.writePlan(ntests);
|
||||
});
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
/**
|
||||
* @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';
|
215
node_modules/mocha/lib/reporters/xunit.js
generated
vendored
Normal file
215
node_modules/mocha/lib/reporters/xunit.js
generated
vendored
Normal file
@ -0,0 +1,215 @@
|
||||
'use strict';
|
||||
/**
|
||||
* @module XUnit
|
||||
*/
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Base = require('./base');
|
||||
var utils = require('../utils');
|
||||
var fs = require('fs');
|
||||
var mkdirp = require('mkdirp');
|
||||
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;
|
||||
|
||||
/**
|
||||
* Initialize a new `XUnit` reporter.
|
||||
*
|
||||
* @public
|
||||
* @class
|
||||
* @memberof Mocha.reporters
|
||||
* @extends Mocha.reporters.Base
|
||||
* @param {Runner} runner
|
||||
*/
|
||||
function XUnit(runner, options) {
|
||||
Base.call(this, runner);
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
mkdirp.sync(path.dirname(options.reporterOptions.output));
|
||||
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 {
|
||||
console.log(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 || !err.actual || !err.expected
|
||||
? ''
|
||||
: '\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';
|
496
node_modules/mocha/lib/runnable.js
generated
vendored
Normal file
496
node_modules/mocha/lib/runnable.js
generated
vendored
Normal file
@ -0,0 +1,496 @@
|
||||
'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');
|
||||
var createInvalidExceptionError = require('./errors')
|
||||
.createInvalidExceptionError;
|
||||
|
||||
/**
|
||||
* Save timer references to avoid Sinon interfering (see GH-237).
|
||||
*/
|
||||
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._enableTimeouts = true;
|
||||
this.timedOut = false;
|
||||
this._retries = -1;
|
||||
this._currentRetry = 0;
|
||||
this.pending = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `EventEmitter.prototype`.
|
||||
*/
|
||||
utils.inherits(Runnable, EventEmitter);
|
||||
|
||||
/**
|
||||
* 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._enableTimeouts = false;
|
||||
}
|
||||
debug('timeout %d', ms);
|
||||
this._timeout = ms;
|
||||
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;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set and get whether timeout is `enabled`.
|
||||
*
|
||||
* @private
|
||||
* @param {boolean} enabled
|
||||
* @return {Runnable|boolean} enabled or Runnable instance.
|
||||
*/
|
||||
Runnable.prototype.enableTimeouts = function(enabled) {
|
||||
if (!arguments.length) {
|
||||
return this._enableTimeouts;
|
||||
}
|
||||
debug('enableTimeouts %s', enabled);
|
||||
this._enableTimeouts = enabled;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Halt and mark as pending.
|
||||
*
|
||||
* @memberof Mocha.Runnable
|
||||
* @public
|
||||
*/
|
||||
Runnable.prototype.skip = function() {
|
||||
throw new Pending('sync skip');
|
||||
};
|
||||
|
||||
/**
|
||||
* 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);
|
||||
};
|
||||
|
||||
/**
|
||||
* Inspect the runnable void of private properties.
|
||||
*
|
||||
* @private
|
||||
* @return {string}
|
||||
*/
|
||||
Runnable.prototype.inspect = function() {
|
||||
return JSON.stringify(
|
||||
this,
|
||||
function(key, val) {
|
||||
if (key[0] === '_') {
|
||||
return;
|
||||
}
|
||||
if (key === 'parent') {
|
||||
return '#<Suite>';
|
||||
}
|
||||
if (key === 'ctx') {
|
||||
return '#<Context>';
|
||||
}
|
||||
return val;
|
||||
},
|
||||
2
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Reset the timeout.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
Runnable.prototype.resetTimeout = function() {
|
||||
var self = this;
|
||||
var ms = this.timeout() || 1e9;
|
||||
|
||||
if (!this._enableTimeouts) {
|
||||
return;
|
||||
}
|
||||
this.clearTimeout();
|
||||
this.timer = setTimeout(function() {
|
||||
if (!self._enableTimeouts) {
|
||||
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 emitted;
|
||||
|
||||
// Sometimes the ctx exists, but it is not runnable
|
||||
if (ctx && ctx.runnable) {
|
||||
ctx.runnable(this);
|
||||
}
|
||||
|
||||
// called multiple times
|
||||
function multiple(err) {
|
||||
if (emitted) {
|
||||
return;
|
||||
}
|
||||
emitted = true;
|
||||
var msg = 'done() called multiple times';
|
||||
if (err && err.message) {
|
||||
err.message += " (and Mocha's " + msg + ')';
|
||||
self.emit('error', err);
|
||||
} else {
|
||||
self.emit('error', new Error(msg));
|
||||
}
|
||||
}
|
||||
|
||||
// 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 && self._enableTimeouts) {
|
||||
err = self._timeoutError(ms);
|
||||
}
|
||||
fn(err);
|
||||
}
|
||||
|
||||
// for .resetTimeout()
|
||||
this.callback = done;
|
||||
|
||||
// explicit async with `done` argument
|
||||
if (this.async) {
|
||||
this.resetTimeout();
|
||||
|
||||
// allows skip() to be used in an explicit async context
|
||||
this.skip = function asyncSkip() {
|
||||
done(new Pending('async skip call'));
|
||||
// halt execution. the Runnable will be marked pending
|
||||
// by the previous call, and the uncaught handler will ignore
|
||||
// the failure.
|
||||
throw new Pending('async skip; aborting execution');
|
||||
};
|
||||
|
||||
if (this.allowUncaught) {
|
||||
return callFnAsync(this.fn);
|
||||
}
|
||||
try {
|
||||
callFnAsync(this.fn);
|
||||
} catch (err) {
|
||||
emitted = true;
|
||||
done(Runnable.toValueOrError(err));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.allowUncaught) {
|
||||
if (this.isPending()) {
|
||||
done();
|
||||
} else {
|
||||
callFn(this.fn);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// sync or promise-returning
|
||||
try {
|
||||
if (this.isPending()) {
|
||||
done();
|
||||
} else {
|
||||
callFn(this.fn);
|
||||
}
|
||||
} catch (err) {
|
||||
emitted = true;
|
||||
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) {
|
||||
var 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 new Error(msg);
|
||||
};
|
||||
|
||||
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'
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* 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;
|
1036
node_modules/mocha/lib/runner.js
generated
vendored
Normal file
1036
node_modules/mocha/lib/runner.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
83
node_modules/mocha/lib/stats-collector.js
generated
vendored
Normal file
83
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;
|
640
node_modules/mocha/lib/suite.js
generated
vendored
Normal file
640
node_modules/mocha/lib/suite.js
generated
vendored
Normal file
@ -0,0 +1,640 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var Hook = require('./hook');
|
||||
var utils = require('./utils');
|
||||
var inherits = utils.inherits;
|
||||
var debug = require('debug')('mocha:suite');
|
||||
var milliseconds = require('ms');
|
||||
var errors = require('./errors');
|
||||
var createInvalidArgumentTypeError = errors.createInvalidArgumentTypeError;
|
||||
|
||||
/**
|
||||
* 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 (!utils.isString(title)) {
|
||||
throw 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.pending = false;
|
||||
this._beforeEach = [];
|
||||
this._beforeAll = [];
|
||||
this._afterEach = [];
|
||||
this._afterAll = [];
|
||||
this.root = isRoot === true;
|
||||
this._timeout = 2000;
|
||||
this._enableTimeouts = true;
|
||||
this._slow = 75;
|
||||
this._bail = false;
|
||||
this._retries = -1;
|
||||
this._onlyTests = [];
|
||||
this._onlySuites = [];
|
||||
this.delayed = false;
|
||||
|
||||
this.on('newListener', function(event) {
|
||||
if (deprecatedEvents[event]) {
|
||||
utils.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);
|
||||
|
||||
/**
|
||||
* 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.timeout(this.timeout());
|
||||
suite.retries(this.retries());
|
||||
suite.enableTimeouts(this.enableTimeouts());
|
||||
suite.slow(this.slow());
|
||||
suite.bail(this.bail());
|
||||
return suite;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set or get timeout `ms` or short-hand such as "2s".
|
||||
*
|
||||
* @private
|
||||
* @param {number|string} ms
|
||||
* @return {Suite|number} for chaining
|
||||
*/
|
||||
Suite.prototype.timeout = function(ms) {
|
||||
if (!arguments.length) {
|
||||
return this._timeout;
|
||||
}
|
||||
if (ms.toString() === '0') {
|
||||
this._enableTimeouts = false;
|
||||
}
|
||||
if (typeof ms === 'string') {
|
||||
ms = milliseconds(ms);
|
||||
}
|
||||
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 timeout to `enabled`.
|
||||
*
|
||||
* @private
|
||||
* @param {boolean} enabled
|
||||
* @return {Suite|boolean} self or enabled
|
||||
*/
|
||||
Suite.prototype.enableTimeouts = function(enabled) {
|
||||
if (!arguments.length) {
|
||||
return this._enableTimeouts;
|
||||
}
|
||||
debug('enableTimeouts %s', enabled);
|
||||
this._enableTimeouts = enabled;
|
||||
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.enableTimeouts(this.enableTimeouts());
|
||||
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.enableTimeouts(this.enableTimeouts());
|
||||
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.enableTimeouts(this.enableTimeouts());
|
||||
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);
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 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;
|
||||
}
|
||||
};
|
||||
|
||||
var constants = utils.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;
|
||||
}, utils.createMap());
|
||||
|
||||
Suite.constants = constants;
|
51
node_modules/mocha/lib/test.js
generated
vendored
Normal file
51
node_modules/mocha/lib/test.js
generated
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
'use strict';
|
||||
var Runnable = require('./runnable');
|
||||
var utils = require('./utils');
|
||||
var errors = require('./errors');
|
||||
var createInvalidArgumentTypeError = errors.createInvalidArgumentTypeError;
|
||||
var isString = utils.isString;
|
||||
|
||||
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'
|
||||
);
|
||||
}
|
||||
Runnable.call(this, title, fn);
|
||||
this.pending = !fn;
|
||||
this.type = 'test';
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `Runnable.prototype`.
|
||||
*/
|
||||
utils.inherits(Test, Runnable);
|
||||
|
||||
Test.prototype.clone = function() {
|
||||
var test = new Test(this.title, this.fn);
|
||||
test.timeout(this.timeout());
|
||||
test.slow(this.slow());
|
||||
test.enableTimeouts(this.enableTimeouts());
|
||||
test.retries(this.retries());
|
||||
test.currentRetry(this.currentRetry());
|
||||
test.globals(this.globals());
|
||||
test.parent = this.parent;
|
||||
test.file = this.file;
|
||||
test.ctx = this.ctx;
|
||||
return test;
|
||||
};
|
897
node_modules/mocha/lib/utils.js
generated
vendored
Normal file
897
node_modules/mocha/lib/utils.js
generated
vendored
Normal file
@ -0,0 +1,897 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Various utility functions used throughout Mocha's codebase.
|
||||
* @module utils
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var util = require('util');
|
||||
var glob = require('glob');
|
||||
var he = require('he');
|
||||
var errors = require('./errors');
|
||||
var createNoFilesMatchPatternError = errors.createNoFilesMatchPatternError;
|
||||
var createMissingArgumentError = errors.createMissingArgumentError;
|
||||
|
||||
var assign = (exports.assign = require('object.assign').getPolyfill());
|
||||
|
||||
/**
|
||||
* 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';
|
||||
};
|
||||
|
||||
/**
|
||||
* Watch the given `files` for changes
|
||||
* and invoke `fn(file)` on modification.
|
||||
*
|
||||
* @private
|
||||
* @param {Array} files
|
||||
* @param {Function} fn
|
||||
*/
|
||||
exports.watch = function(files, fn) {
|
||||
var options = {interval: 100};
|
||||
var debug = require('debug')('mocha:watch');
|
||||
files.forEach(function(file) {
|
||||
debug('file %s', file);
|
||||
fs.watchFile(file, options, function(curr, prev) {
|
||||
if (prev.mtime < curr.mtime) {
|
||||
fn(file);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Predicate to screen `pathname` for further consideration.
|
||||
*
|
||||
* @description
|
||||
* Returns <code>false</code> for pathname referencing:
|
||||
* <ul>
|
||||
* <li>'npm' package installation directory
|
||||
* <li>'git' version control directory
|
||||
* </ul>
|
||||
*
|
||||
* @private
|
||||
* @param {string} pathname - File or directory name to screen
|
||||
* @return {boolean} whether pathname should be further considered
|
||||
* @example
|
||||
* ['node_modules', 'test.js'].filter(considerFurther); // => ['test.js']
|
||||
*/
|
||||
function considerFurther(pathname) {
|
||||
var ignore = ['node_modules', '.git'];
|
||||
|
||||
return !~ignore.indexOf(pathname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup files in the given `dir`.
|
||||
*
|
||||
* @description
|
||||
* Filenames are returned in _traversal_ order by the OS/filesystem.
|
||||
* **Make no assumption that the names will be sorted in any fashion.**
|
||||
*
|
||||
* @private
|
||||
* @param {string} dir
|
||||
* @param {string[]} [exts=['js']]
|
||||
* @param {Array} [ret=[]]
|
||||
* @return {Array}
|
||||
*/
|
||||
exports.files = function(dir, exts, ret) {
|
||||
ret = ret || [];
|
||||
exts = exts || ['js'];
|
||||
|
||||
fs.readdirSync(dir)
|
||||
.filter(considerFurther)
|
||||
.forEach(function(dirent) {
|
||||
var pathname = path.join(dir, dirent);
|
||||
if (fs.lstatSync(pathname).isDirectory()) {
|
||||
exports.files(pathname, exts, ret);
|
||||
} else if (hasMatchingExtname(pathname, exts)) {
|
||||
ret.push(pathname);
|
||||
}
|
||||
});
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
/**
|
||||
* Compute a slug from the given `str`.
|
||||
*
|
||||
* @private
|
||||
* @param {string} str
|
||||
* @return {string}
|
||||
*/
|
||||
exports.slug = function(str) {
|
||||
return str
|
||||
.toLowerCase()
|
||||
.replace(/ +/g, '-')
|
||||
.replace(/[^-\w]/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();
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse the given `qs`.
|
||||
*
|
||||
* @private
|
||||
* @param {string} qs
|
||||
* @return {Object}
|
||||
*/
|
||||
exports.parseQuery = function(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;
|
||||
}, {});
|
||||
};
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
exports.highlightTags = function(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);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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
|
||||
* type({}) // 'object'
|
||||
* type([]) // 'array'
|
||||
* type(1) // 'number'
|
||||
* type(false) // 'boolean'
|
||||
* type(Infinity) // 'number'
|
||||
* type(null) // 'null'
|
||||
* type(new Date()) // 'date'
|
||||
* type(/foo/) // 'regexp'
|
||||
* type('type') // 'string'
|
||||
* type(global) // 'global'
|
||||
* type(new String('foo') // 'object'
|
||||
*/
|
||||
var type = (exports.type = function type(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();
|
||||
});
|
||||
|
||||
/**
|
||||
* 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 = type(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 (type(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 '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 || type(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 guard-for-in */
|
||||
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;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determines if pathname has a matching file extension.
|
||||
*
|
||||
* @private
|
||||
* @param {string} pathname - Pathname to check for match.
|
||||
* @param {string[]} exts - List of file extensions (sans period).
|
||||
* @return {boolean} whether file extension matches.
|
||||
* @example
|
||||
* hasMatchingExtname('foo.html', ['js', 'css']); // => false
|
||||
*/
|
||||
function hasMatchingExtname(pathname, exts) {
|
||||
var suffix = path.extname(pathname).slice(1);
|
||||
return exts.some(function(element) {
|
||||
return suffix === element;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
function isHiddenOnUnix(pathname) {
|
||||
return path.basename(pathname)[0] === '.';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @memberof Mocha.utils
|
||||
* @todo Fix extension handling
|
||||
* @param {string} filepath - Base path to start searching from.
|
||||
* @param {string[]} extensions - File extensions to look for.
|
||||
* @param {boolean} recursive - 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.
|
||||
*/
|
||||
exports.lookupFiles = function lookupFiles(filepath, extensions, recursive) {
|
||||
var files = [];
|
||||
var stat;
|
||||
|
||||
if (!fs.existsSync(filepath)) {
|
||||
if (fs.existsSync(filepath + '.js')) {
|
||||
filepath += '.js';
|
||||
} else {
|
||||
// Handle glob
|
||||
files = glob.sync(filepath);
|
||||
if (!files.length) {
|
||||
throw createNoFilesMatchPatternError(
|
||||
'Cannot find any files matching pattern ' + exports.dQuote(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(function(dirent) {
|
||||
var pathname = path.join(filepath, dirent);
|
||||
var stat;
|
||||
|
||||
try {
|
||||
stat = fs.statSync(pathname);
|
||||
if (stat.isDirectory()) {
|
||||
if (recursive) {
|
||||
files = files.concat(lookupFiles(pathname, extensions, recursive));
|
||||
}
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
// ignore error
|
||||
return;
|
||||
}
|
||||
if (!extensions) {
|
||||
throw createMissingArgumentError(
|
||||
util.format(
|
||||
'Argument %s required when argument %s is a directory',
|
||||
exports.sQuote('extensions'),
|
||||
exports.sQuote('filepath')
|
||||
),
|
||||
'extensions',
|
||||
'array'
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
!stat.isFile() ||
|
||||
!hasMatchingExtname(pathname, extensions) ||
|
||||
isHiddenOnUnix(pathname)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
files.push(pathname);
|
||||
});
|
||||
|
||||
return files;
|
||||
};
|
||||
|
||||
/**
|
||||
* process.emitWarning or a polyfill
|
||||
* @see https://nodejs.org/api/process.html#process_process_emitwarning_warning_options
|
||||
* @ignore
|
||||
*/
|
||||
function emitWarning(msg, type) {
|
||||
if (process.emitWarning) {
|
||||
process.emitWarning(msg, type);
|
||||
} else {
|
||||
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
|
||||
*/
|
||||
exports.deprecate = function deprecate(msg) {
|
||||
msg = String(msg);
|
||||
if (msg && !deprecate.cache[msg]) {
|
||||
deprecate.cache[msg] = true;
|
||||
emitWarning(msg, 'DeprecationWarning');
|
||||
}
|
||||
};
|
||||
exports.deprecate.cache = {};
|
||||
|
||||
/**
|
||||
* Show a generic warning.
|
||||
* Ignores empty messages.
|
||||
*
|
||||
* @param {string} [msg] - Warning to print
|
||||
* @private
|
||||
*/
|
||||
exports.warn = function warn(msg) {
|
||||
if (msg) {
|
||||
emitWarning(msg);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @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 = process.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')
|
||||
);
|
||||
}
|
||||
|
||||
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 {numer[]} 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]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Single quote text by combining with undirectional ASCII quotation marks.
|
||||
*
|
||||
* @description
|
||||
* Provides a simple means of markup for quoting text to be used in output.
|
||||
* Use this to quote names of variables, methods, and packages.
|
||||
*
|
||||
* <samp>package 'foo' cannot be found</samp>
|
||||
*
|
||||
* @private
|
||||
* @param {string} str - Value to be quoted.
|
||||
* @returns {string} quoted value
|
||||
* @example
|
||||
* sQuote('n') // => 'n'
|
||||
*/
|
||||
exports.sQuote = function(str) {
|
||||
return "'" + str + "'";
|
||||
};
|
||||
|
||||
/**
|
||||
* Double quote text by combining with undirectional ASCII quotation marks.
|
||||
*
|
||||
* @description
|
||||
* Provides a simple means of markup for quoting text to be used in output.
|
||||
* Use this to quote names of datatypes, classes, pathnames, and strings.
|
||||
*
|
||||
* <samp>argument 'value' must be "string" or "number"</samp>
|
||||
*
|
||||
* @private
|
||||
* @param {string} str - Value to be quoted.
|
||||
* @returns {string} quoted value
|
||||
* @example
|
||||
* dQuote('number') // => "number"
|
||||
*/
|
||||
exports.dQuote = function(str) {
|
||||
return '"' + str + '"';
|
||||
};
|
||||
|
||||
/**
|
||||
* Provides simplistic message translation for dealing with plurality.
|
||||
*
|
||||
* @description
|
||||
* Use this to create messages which need to be singular or plural.
|
||||
* Some languages have several plural forms, so _complete_ message clauses
|
||||
* are preferable to generating the message on the fly.
|
||||
*
|
||||
* @private
|
||||
* @param {number} n - Non-negative integer
|
||||
* @param {string} msg1 - Message to be used in English for `n = 1`
|
||||
* @param {string} msg2 - Message to be used in English for `n = 0, 2, 3, ...`
|
||||
* @returns {string} message corresponding to value of `n`
|
||||
* @example
|
||||
* var sprintf = require('util').format;
|
||||
* var pkgs = ['one', 'two'];
|
||||
* var msg = sprintf(
|
||||
* ngettext(
|
||||
* pkgs.length,
|
||||
* 'cannot load package: %s',
|
||||
* 'cannot load packages: %s'
|
||||
* ),
|
||||
* pkgs.map(sQuote).join(', ')
|
||||
* );
|
||||
* console.log(msg); // => cannot load packages: 'one', 'two'
|
||||
*/
|
||||
exports.ngettext = function(n, msg1, msg2) {
|
||||
if (typeof n === 'number' && n >= 0) {
|
||||
return n === 1 ? msg1 : msg2;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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|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|MDN:Object.assign}
|
||||
* @param {...*} [obj] - Arguments to `Object.assign()`.
|
||||
* @returns {Object} An object with no prototype, having `...obj` properties
|
||||
*/
|
||||
exports.createMap = function(obj) {
|
||||
return 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 (type(obj) !== 'object' || !Object.keys(obj).length) {
|
||||
throw new TypeError('Invalid argument; expected a non-empty object');
|
||||
}
|
||||
return Object.freeze(exports.createMap(obj));
|
||||
};
|
326
node_modules/mocha/mocha.css
generated
vendored
Normal file
326
node_modules/mocha/mocha.css
generated
vendored
Normal file
@ -0,0 +1,326 @@
|
||||
@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;
|
||||
line-height: 1.5;
|
||||
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;
|
||||
}
|
||||
}
|
17910
node_modules/mocha/mocha.js
generated
vendored
Normal file
17910
node_modules/mocha/mocha.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
395
node_modules/mocha/node_modules/debug/CHANGELOG.md
generated
vendored
Normal file
395
node_modules/mocha/node_modules/debug/CHANGELOG.md
generated
vendored
Normal file
@ -0,0 +1,395 @@
|
||||
|
||||
3.1.0 / 2017-09-26
|
||||
==================
|
||||
|
||||
* Add `DEBUG_HIDE_DATE` env var (#486)
|
||||
* Remove ReDoS regexp in %o formatter (#504)
|
||||
* Remove "component" from package.json
|
||||
* Remove `component.json`
|
||||
* Ignore package-lock.json
|
||||
* Examples: fix colors printout
|
||||
* Fix: browser detection
|
||||
* Fix: spelling mistake (#496, @EdwardBetts)
|
||||
|
||||
3.0.1 / 2017-08-24
|
||||
==================
|
||||
|
||||
* Fix: Disable colors in Edge and Internet Explorer (#489)
|
||||
|
||||
3.0.0 / 2017-08-08
|
||||
==================
|
||||
|
||||
* Breaking: Remove DEBUG_FD (#406)
|
||||
* Breaking: Use `Date#toISOString()` instead to `Date#toUTCString()` when output is not a TTY (#418)
|
||||
* Breaking: Make millisecond timer namespace specific and allow 'always enabled' output (#408)
|
||||
* Addition: document `enabled` flag (#465)
|
||||
* Addition: add 256 colors mode (#481)
|
||||
* Addition: `enabled()` updates existing debug instances, add `destroy()` function (#440)
|
||||
* Update: component: update "ms" to v2.0.0
|
||||
* Update: separate the Node and Browser tests in Travis-CI
|
||||
* Update: refactor Readme, fixed documentation, added "Namespace Colors" section, redid screenshots
|
||||
* Update: separate Node.js and web browser examples for organization
|
||||
* Update: update "browserify" to v14.4.0
|
||||
* Fix: fix Readme typo (#473)
|
||||
|
||||
2.6.9 / 2017-09-22
|
||||
==================
|
||||
|
||||
* remove ReDoS regexp in %o formatter (#504)
|
||||
|
||||
2.6.8 / 2017-05-18
|
||||
==================
|
||||
|
||||
* Fix: Check for undefined on browser globals (#462, @marbemac)
|
||||
|
||||
2.6.7 / 2017-05-16
|
||||
==================
|
||||
|
||||
* Fix: Update ms to 2.0.0 to fix regular expression denial of service vulnerability (#458, @hubdotcom)
|
||||
* Fix: Inline extend function in node implementation (#452, @dougwilson)
|
||||
* Docs: Fix typo (#455, @msasad)
|
||||
|
||||
2.6.5 / 2017-04-27
|
||||
==================
|
||||
|
||||
* Fix: null reference check on window.documentElement.style.WebkitAppearance (#447, @thebigredgeek)
|
||||
* Misc: clean up browser reference checks (#447, @thebigredgeek)
|
||||
* Misc: add npm-debug.log to .gitignore (@thebigredgeek)
|
||||
|
||||
|
||||
2.6.4 / 2017-04-20
|
||||
==================
|
||||
|
||||
* Fix: bug that would occur if process.env.DEBUG is a non-string value. (#444, @LucianBuzzo)
|
||||
* Chore: ignore bower.json in npm installations. (#437, @joaovieira)
|
||||
* Misc: update "ms" to v0.7.3 (@tootallnate)
|
||||
|
||||
2.6.3 / 2017-03-13
|
||||
==================
|
||||
|
||||
* Fix: Electron reference to `process.env.DEBUG` (#431, @paulcbetts)
|
||||
* Docs: Changelog fix (@thebigredgeek)
|
||||
|
||||
2.6.2 / 2017-03-10
|
||||
==================
|
||||
|
||||
* Fix: DEBUG_MAX_ARRAY_LENGTH (#420, @slavaGanzin)
|
||||
* Docs: Add backers and sponsors from Open Collective (#422, @piamancini)
|
||||
* Docs: Add Slackin invite badge (@tootallnate)
|
||||
|
||||
2.6.1 / 2017-02-10
|
||||
==================
|
||||
|
||||
* Fix: Module's `export default` syntax fix for IE8 `Expected identifier` error
|
||||
* Fix: Whitelist DEBUG_FD for values 1 and 2 only (#415, @pi0)
|
||||
* Fix: IE8 "Expected identifier" error (#414, @vgoma)
|
||||
* Fix: Namespaces would not disable once enabled (#409, @musikov)
|
||||
|
||||
2.6.0 / 2016-12-28
|
||||
==================
|
||||
|
||||
* Fix: added better null pointer checks for browser useColors (@thebigredgeek)
|
||||
* Improvement: removed explicit `window.debug` export (#404, @tootallnate)
|
||||
* Improvement: deprecated `DEBUG_FD` environment variable (#405, @tootallnate)
|
||||
|
||||
2.5.2 / 2016-12-25
|
||||
==================
|
||||
|
||||
* Fix: reference error on window within webworkers (#393, @KlausTrainer)
|
||||
* Docs: fixed README typo (#391, @lurch)
|
||||
* Docs: added notice about v3 api discussion (@thebigredgeek)
|
||||
|
||||
2.5.1 / 2016-12-20
|
||||
==================
|
||||
|
||||
* Fix: babel-core compatibility
|
||||
|
||||
2.5.0 / 2016-12-20
|
||||
==================
|
||||
|
||||
* Fix: wrong reference in bower file (@thebigredgeek)
|
||||
* Fix: webworker compatibility (@thebigredgeek)
|
||||
* Fix: output formatting issue (#388, @kribblo)
|
||||
* Fix: babel-loader compatibility (#383, @escwald)
|
||||
* Misc: removed built asset from repo and publications (@thebigredgeek)
|
||||
* Misc: moved source files to /src (#378, @yamikuronue)
|
||||
* Test: added karma integration and replaced babel with browserify for browser tests (#378, @yamikuronue)
|
||||
* Test: coveralls integration (#378, @yamikuronue)
|
||||
* Docs: simplified language in the opening paragraph (#373, @yamikuronue)
|
||||
|
||||
2.4.5 / 2016-12-17
|
||||
==================
|
||||
|
||||
* Fix: `navigator` undefined in Rhino (#376, @jochenberger)
|
||||
* Fix: custom log function (#379, @hsiliev)
|
||||
* Improvement: bit of cleanup + linting fixes (@thebigredgeek)
|
||||
* Improvement: rm non-maintainted `dist/` dir (#375, @freewil)
|
||||
* Docs: simplified language in the opening paragraph. (#373, @yamikuronue)
|
||||
|
||||
2.4.4 / 2016-12-14
|
||||
==================
|
||||
|
||||
* Fix: work around debug being loaded in preload scripts for electron (#368, @paulcbetts)
|
||||
|
||||
2.4.3 / 2016-12-14
|
||||
==================
|
||||
|
||||
* Fix: navigation.userAgent error for react native (#364, @escwald)
|
||||
|
||||
2.4.2 / 2016-12-14
|
||||
==================
|
||||
|
||||
* Fix: browser colors (#367, @tootallnate)
|
||||
* Misc: travis ci integration (@thebigredgeek)
|
||||
* Misc: added linting and testing boilerplate with sanity check (@thebigredgeek)
|
||||
|
||||
2.4.1 / 2016-12-13
|
||||
==================
|
||||
|
||||
* Fix: typo that broke the package (#356)
|
||||
|
||||
2.4.0 / 2016-12-13
|
||||
==================
|
||||
|
||||
* Fix: bower.json references unbuilt src entry point (#342, @justmatt)
|
||||
* Fix: revert "handle regex special characters" (@tootallnate)
|
||||
* Feature: configurable util.inspect()`options for NodeJS (#327, @tootallnate)
|
||||
* Feature: %O`(big O) pretty-prints objects (#322, @tootallnate)
|
||||
* Improvement: allow colors in workers (#335, @botverse)
|
||||
* Improvement: use same color for same namespace. (#338, @lchenay)
|
||||
|
||||
2.3.3 / 2016-11-09
|
||||
==================
|
||||
|
||||
* Fix: Catch `JSON.stringify()` errors (#195, Jovan Alleyne)
|
||||
* Fix: Returning `localStorage` saved values (#331, Levi Thomason)
|
||||
* Improvement: Don't create an empty object when no `process` (Nathan Rajlich)
|
||||
|
||||
2.3.2 / 2016-11-09
|
||||
==================
|
||||
|
||||
* Fix: be super-safe in index.js as well (@TooTallNate)
|
||||
* Fix: should check whether process exists (Tom Newby)
|
||||
|
||||
2.3.1 / 2016-11-09
|
||||
==================
|
||||
|
||||
* Fix: Added electron compatibility (#324, @paulcbetts)
|
||||
* Improvement: Added performance optimizations (@tootallnate)
|
||||
* Readme: Corrected PowerShell environment variable example (#252, @gimre)
|
||||
* Misc: Removed yarn lock file from source control (#321, @fengmk2)
|
||||
|
||||
2.3.0 / 2016-11-07
|
||||
==================
|
||||
|
||||
* Fix: Consistent placement of ms diff at end of output (#215, @gorangajic)
|
||||
* Fix: Escaping of regex special characters in namespace strings (#250, @zacronos)
|
||||
* Fix: Fixed bug causing crash on react-native (#282, @vkarpov15)
|
||||
* Feature: Enabled ES6+ compatible import via default export (#212 @bucaran)
|
||||
* Feature: Added %O formatter to reflect Chrome's console.log capability (#279, @oncletom)
|
||||
* Package: Update "ms" to 0.7.2 (#315, @DevSide)
|
||||
* Package: removed superfluous version property from bower.json (#207 @kkirsche)
|
||||
* Readme: fix USE_COLORS to DEBUG_COLORS
|
||||
* Readme: Doc fixes for format string sugar (#269, @mlucool)
|
||||
* Readme: Updated docs for DEBUG_FD and DEBUG_COLORS environment variables (#232, @mattlyons0)
|
||||
* Readme: doc fixes for PowerShell (#271 #243, @exoticknight @unreadable)
|
||||
* Readme: better docs for browser support (#224, @matthewmueller)
|
||||
* Tooling: Added yarn integration for development (#317, @thebigredgeek)
|
||||
* Misc: Renamed History.md to CHANGELOG.md (@thebigredgeek)
|
||||
* Misc: Added license file (#226 #274, @CantemoInternal @sdaitzman)
|
||||
* Misc: Updated contributors (@thebigredgeek)
|
||||
|
||||
2.2.0 / 2015-05-09
|
||||
==================
|
||||
|
||||
* package: update "ms" to v0.7.1 (#202, @dougwilson)
|
||||
* README: add logging to file example (#193, @DanielOchoa)
|
||||
* README: fixed a typo (#191, @amir-s)
|
||||
* browser: expose `storage` (#190, @stephenmathieson)
|
||||
* Makefile: add a `distclean` target (#189, @stephenmathieson)
|
||||
|
||||
2.1.3 / 2015-03-13
|
||||
==================
|
||||
|
||||
* Updated stdout/stderr example (#186)
|
||||
* Updated example/stdout.js to match debug current behaviour
|
||||
* Renamed example/stderr.js to stdout.js
|
||||
* Update Readme.md (#184)
|
||||
* replace high intensity foreground color for bold (#182, #183)
|
||||
|
||||
2.1.2 / 2015-03-01
|
||||
==================
|
||||
|
||||
* dist: recompile
|
||||
* update "ms" to v0.7.0
|
||||
* package: update "browserify" to v9.0.3
|
||||
* component: fix "ms.js" repo location
|
||||
* changed bower package name
|
||||
* updated documentation about using debug in a browser
|
||||
* fix: security error on safari (#167, #168, @yields)
|
||||
|
||||
2.1.1 / 2014-12-29
|
||||
==================
|
||||
|
||||
* browser: use `typeof` to check for `console` existence
|
||||
* browser: check for `console.log` truthiness (fix IE 8/9)
|
||||
* browser: add support for Chrome apps
|
||||
* Readme: added Windows usage remarks
|
||||
* Add `bower.json` to properly support bower install
|
||||
|
||||
2.1.0 / 2014-10-15
|
||||
==================
|
||||
|
||||
* node: implement `DEBUG_FD` env variable support
|
||||
* package: update "browserify" to v6.1.0
|
||||
* package: add "license" field to package.json (#135, @panuhorsmalahti)
|
||||
|
||||
2.0.0 / 2014-09-01
|
||||
==================
|
||||
|
||||
* package: update "browserify" to v5.11.0
|
||||
* node: use stderr rather than stdout for logging (#29, @stephenmathieson)
|
||||
|
||||
1.0.4 / 2014-07-15
|
||||
==================
|
||||
|
||||
* dist: recompile
|
||||
* example: remove `console.info()` log usage
|
||||
* example: add "Content-Type" UTF-8 header to browser example
|
||||
* browser: place %c marker after the space character
|
||||
* browser: reset the "content" color via `color: inherit`
|
||||
* browser: add colors support for Firefox >= v31
|
||||
* debug: prefer an instance `log()` function over the global one (#119)
|
||||
* Readme: update documentation about styled console logs for FF v31 (#116, @wryk)
|
||||
|
||||
1.0.3 / 2014-07-09
|
||||
==================
|
||||
|
||||
* Add support for multiple wildcards in namespaces (#122, @seegno)
|
||||
* browser: fix lint
|
||||
|
||||
1.0.2 / 2014-06-10
|
||||
==================
|
||||
|
||||
* browser: update color palette (#113, @gscottolson)
|
||||
* common: make console logging function configurable (#108, @timoxley)
|
||||
* node: fix %o colors on old node <= 0.8.x
|
||||
* Makefile: find node path using shell/which (#109, @timoxley)
|
||||
|
||||
1.0.1 / 2014-06-06
|
||||
==================
|
||||
|
||||
* browser: use `removeItem()` to clear localStorage
|
||||
* browser, node: don't set DEBUG if namespaces is undefined (#107, @leedm777)
|
||||
* package: add "contributors" section
|
||||
* node: fix comment typo
|
||||
* README: list authors
|
||||
|
||||
1.0.0 / 2014-06-04
|
||||
==================
|
||||
|
||||
* make ms diff be global, not be scope
|
||||
* debug: ignore empty strings in enable()
|
||||
* node: make DEBUG_COLORS able to disable coloring
|
||||
* *: export the `colors` array
|
||||
* npmignore: don't publish the `dist` dir
|
||||
* Makefile: refactor to use browserify
|
||||
* package: add "browserify" as a dev dependency
|
||||
* Readme: add Web Inspector Colors section
|
||||
* node: reset terminal color for the debug content
|
||||
* node: map "%o" to `util.inspect()`
|
||||
* browser: map "%j" to `JSON.stringify()`
|
||||
* debug: add custom "formatters"
|
||||
* debug: use "ms" module for humanizing the diff
|
||||
* Readme: add "bash" syntax highlighting
|
||||
* browser: add Firebug color support
|
||||
* browser: add colors for WebKit browsers
|
||||
* node: apply log to `console`
|
||||
* rewrite: abstract common logic for Node & browsers
|
||||
* add .jshintrc file
|
||||
|
||||
0.8.1 / 2014-04-14
|
||||
==================
|
||||
|
||||
* package: re-add the "component" section
|
||||
|
||||
0.8.0 / 2014-03-30
|
||||
==================
|
||||
|
||||
* add `enable()` method for nodejs. Closes #27
|
||||
* change from stderr to stdout
|
||||
* remove unnecessary index.js file
|
||||
|
||||
0.7.4 / 2013-11-13
|
||||
==================
|
||||
|
||||
* remove "browserify" key from package.json (fixes something in browserify)
|
||||
|
||||
0.7.3 / 2013-10-30
|
||||
==================
|
||||
|
||||
* fix: catch localStorage security error when cookies are blocked (Chrome)
|
||||
* add debug(err) support. Closes #46
|
||||
* add .browser prop to package.json. Closes #42
|
||||
|
||||
0.7.2 / 2013-02-06
|
||||
==================
|
||||
|
||||
* fix package.json
|
||||
* fix: Mobile Safari (private mode) is broken with debug
|
||||
* fix: Use unicode to send escape character to shell instead of octal to work with strict mode javascript
|
||||
|
||||
0.7.1 / 2013-02-05
|
||||
==================
|
||||
|
||||
* add repository URL to package.json
|
||||
* add DEBUG_COLORED to force colored output
|
||||
* add browserify support
|
||||
* fix component. Closes #24
|
||||
|
||||
0.7.0 / 2012-05-04
|
||||
==================
|
||||
|
||||
* Added .component to package.json
|
||||
* Added debug.component.js build
|
||||
|
||||
0.6.0 / 2012-03-16
|
||||
==================
|
||||
|
||||
* Added support for "-" prefix in DEBUG [Vinay Pulim]
|
||||
* Added `.enabled` flag to the node version [TooTallNate]
|
||||
|
||||
0.5.0 / 2012-02-02
|
||||
==================
|
||||
|
||||
* Added: humanize diffs. Closes #8
|
||||
* Added `debug.disable()` to the CS variant
|
||||
* Removed padding. Closes #10
|
||||
* Fixed: persist client-side variant again. Closes #9
|
||||
|
||||
0.4.0 / 2012-02-01
|
||||
==================
|
||||
|
||||
* Added browser variant support for older browsers [TooTallNate]
|
||||
* Added `debug.enable('project:*')` to browser variant [TooTallNate]
|
||||
* Added padding to diff (moved it to the right)
|
||||
|
||||
0.3.0 / 2012-01-26
|
||||
==================
|
||||
|
||||
* Added millisecond diff when isatty, otherwise UTC string
|
||||
|
||||
0.2.0 / 2012-01-22
|
||||
==================
|
||||
|
||||
* Added wildcard support
|
||||
|
||||
0.1.0 / 2011-12-02
|
||||
==================
|
||||
|
||||
* Added: remove colors unless stderr isatty [TooTallNate]
|
||||
|
||||
0.0.1 / 2010-01-03
|
||||
==================
|
||||
|
||||
* Initial release
|
19
node_modules/mocha/node_modules/debug/LICENSE
generated
vendored
Normal file
19
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.
|
||||
|
437
node_modules/mocha/node_modules/debug/README.md
generated
vendored
Normal file
437
node_modules/mocha/node_modules/debug/README.md
generated
vendored
Normal file
@ -0,0 +1,437 @@
|
||||
# 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
|
||||
```
|
||||
|
||||
## 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.
|
886
node_modules/mocha/node_modules/debug/dist/debug.js
generated
vendored
Normal file
886
node_modules/mocha/node_modules/debug/dist/debug.js
generated
vendored
Normal file
@ -0,0 +1,886 @@
|
||||
"use strict";
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
(function (f) {
|
||||
if ((typeof exports === "undefined" ? "undefined" : _typeof(exports)) === "object" && typeof module !== "undefined") {
|
||||
module.exports = f();
|
||||
} else if (typeof define === "function" && define.amd) {
|
||||
define([], f);
|
||||
} else {
|
||||
var g;
|
||||
|
||||
if (typeof window !== "undefined") {
|
||||
g = window;
|
||||
} else if (typeof global !== "undefined") {
|
||||
g = global;
|
||||
} else if (typeof self !== "undefined") {
|
||||
g = self;
|
||||
} else {
|
||||
g = this;
|
||||
}
|
||||
|
||||
g.debug = f();
|
||||
}
|
||||
})(function () {
|
||||
var define, module, exports;
|
||||
return function () {
|
||||
function r(e, n, t) {
|
||||
function o(i, f) {
|
||||
if (!n[i]) {
|
||||
if (!e[i]) {
|
||||
var c = "function" == typeof require && require;
|
||||
if (!f && c) return c(i, !0);
|
||||
if (u) return u(i, !0);
|
||||
var a = new Error("Cannot find module '" + i + "'");
|
||||
throw a.code = "MODULE_NOT_FOUND", a;
|
||||
}
|
||||
|
||||
var p = n[i] = {
|
||||
exports: {}
|
||||
};
|
||||
e[i][0].call(p.exports, function (r) {
|
||||
var n = e[i][1][r];
|
||||
return o(n || r);
|
||||
}, p, p.exports, r, e, n, t);
|
||||
}
|
||||
|
||||
return n[i].exports;
|
||||
}
|
||||
|
||||
for (var u = "function" == typeof require && require, i = 0; i < t.length; i++) {
|
||||
o(t[i]);
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
return r;
|
||||
}()({
|
||||
1: [function (require, module, exports) {
|
||||
/**
|
||||
* 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' && isNaN(val) === false) {
|
||||
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?\.?\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' : '');
|
||||
}
|
||||
}, {}],
|
||||
2: [function (require, module, exports) {
|
||||
// shim for using process in browser
|
||||
var process = module.exports = {}; // cached from whatever global is present so that test runners that stub it
|
||||
// don't break things. But we need to wrap it in a try catch in case it is
|
||||
// wrapped in strict mode code which doesn't define any globals. It's inside a
|
||||
// function because try/catches deoptimize in certain engines.
|
||||
|
||||
var cachedSetTimeout;
|
||||
var cachedClearTimeout;
|
||||
|
||||
function defaultSetTimout() {
|
||||
throw new Error('setTimeout has not been defined');
|
||||
}
|
||||
|
||||
function defaultClearTimeout() {
|
||||
throw new Error('clearTimeout has not been defined');
|
||||
}
|
||||
|
||||
(function () {
|
||||
try {
|
||||
if (typeof setTimeout === 'function') {
|
||||
cachedSetTimeout = setTimeout;
|
||||
} else {
|
||||
cachedSetTimeout = defaultSetTimout;
|
||||
}
|
||||
} catch (e) {
|
||||
cachedSetTimeout = defaultSetTimout;
|
||||
}
|
||||
|
||||
try {
|
||||
if (typeof clearTimeout === 'function') {
|
||||
cachedClearTimeout = clearTimeout;
|
||||
} else {
|
||||
cachedClearTimeout = defaultClearTimeout;
|
||||
}
|
||||
} catch (e) {
|
||||
cachedClearTimeout = defaultClearTimeout;
|
||||
}
|
||||
})();
|
||||
|
||||
function runTimeout(fun) {
|
||||
if (cachedSetTimeout === setTimeout) {
|
||||
//normal enviroments in sane situations
|
||||
return setTimeout(fun, 0);
|
||||
} // if setTimeout wasn't available but was latter defined
|
||||
|
||||
|
||||
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
||||
cachedSetTimeout = setTimeout;
|
||||
return setTimeout(fun, 0);
|
||||
}
|
||||
|
||||
try {
|
||||
// when when somebody has screwed with setTimeout but no I.E. maddness
|
||||
return cachedSetTimeout(fun, 0);
|
||||
} catch (e) {
|
||||
try {
|
||||
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
||||
return cachedSetTimeout.call(null, fun, 0);
|
||||
} catch (e) {
|
||||
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
|
||||
return cachedSetTimeout.call(this, fun, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function runClearTimeout(marker) {
|
||||
if (cachedClearTimeout === clearTimeout) {
|
||||
//normal enviroments in sane situations
|
||||
return clearTimeout(marker);
|
||||
} // if clearTimeout wasn't available but was latter defined
|
||||
|
||||
|
||||
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
||||
cachedClearTimeout = clearTimeout;
|
||||
return clearTimeout(marker);
|
||||
}
|
||||
|
||||
try {
|
||||
// when when somebody has screwed with setTimeout but no I.E. maddness
|
||||
return cachedClearTimeout(marker);
|
||||
} catch (e) {
|
||||
try {
|
||||
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
||||
return cachedClearTimeout.call(null, marker);
|
||||
} catch (e) {
|
||||
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
|
||||
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
|
||||
return cachedClearTimeout.call(this, marker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var queue = [];
|
||||
var draining = false;
|
||||
var currentQueue;
|
||||
var queueIndex = -1;
|
||||
|
||||
function cleanUpNextTick() {
|
||||
if (!draining || !currentQueue) {
|
||||
return;
|
||||
}
|
||||
|
||||
draining = false;
|
||||
|
||||
if (currentQueue.length) {
|
||||
queue = currentQueue.concat(queue);
|
||||
} else {
|
||||
queueIndex = -1;
|
||||
}
|
||||
|
||||
if (queue.length) {
|
||||
drainQueue();
|
||||
}
|
||||
}
|
||||
|
||||
function drainQueue() {
|
||||
if (draining) {
|
||||
return;
|
||||
}
|
||||
|
||||
var timeout = runTimeout(cleanUpNextTick);
|
||||
draining = true;
|
||||
var len = queue.length;
|
||||
|
||||
while (len) {
|
||||
currentQueue = queue;
|
||||
queue = [];
|
||||
|
||||
while (++queueIndex < len) {
|
||||
if (currentQueue) {
|
||||
currentQueue[queueIndex].run();
|
||||
}
|
||||
}
|
||||
|
||||
queueIndex = -1;
|
||||
len = queue.length;
|
||||
}
|
||||
|
||||
currentQueue = null;
|
||||
draining = false;
|
||||
runClearTimeout(timeout);
|
||||
}
|
||||
|
||||
process.nextTick = function (fun) {
|
||||
var args = new Array(arguments.length - 1);
|
||||
|
||||
if (arguments.length > 1) {
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
args[i - 1] = arguments[i];
|
||||
}
|
||||
}
|
||||
|
||||
queue.push(new Item(fun, args));
|
||||
|
||||
if (queue.length === 1 && !draining) {
|
||||
runTimeout(drainQueue);
|
||||
}
|
||||
}; // v8 likes predictible objects
|
||||
|
||||
|
||||
function Item(fun, array) {
|
||||
this.fun = fun;
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
Item.prototype.run = function () {
|
||||
this.fun.apply(null, this.array);
|
||||
};
|
||||
|
||||
process.title = 'browser';
|
||||
process.browser = true;
|
||||
process.env = {};
|
||||
process.argv = [];
|
||||
process.version = ''; // empty string to avoid regexp issues
|
||||
|
||||
process.versions = {};
|
||||
|
||||
function noop() {}
|
||||
|
||||
process.on = noop;
|
||||
process.addListener = noop;
|
||||
process.once = noop;
|
||||
process.off = noop;
|
||||
process.removeListener = noop;
|
||||
process.removeAllListeners = noop;
|
||||
process.emit = noop;
|
||||
process.prependListener = noop;
|
||||
process.prependOnceListener = noop;
|
||||
|
||||
process.listeners = function (name) {
|
||||
return [];
|
||||
};
|
||||
|
||||
process.binding = function (name) {
|
||||
throw new Error('process.binding is not supported');
|
||||
};
|
||||
|
||||
process.cwd = function () {
|
||||
return '/';
|
||||
};
|
||||
|
||||
process.chdir = function (dir) {
|
||||
throw new Error('process.chdir is not supported');
|
||||
};
|
||||
|
||||
process.umask = function () {
|
||||
return 0;
|
||||
};
|
||||
}, {}],
|
||||
3: [function (require, module, exports) {
|
||||
/**
|
||||
* 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');
|
||||
Object.keys(env).forEach(function (key) {
|
||||
createDebug[key] = env[key];
|
||||
});
|
||||
/**
|
||||
* Active `debug` instances.
|
||||
*/
|
||||
|
||||
createDebug.instances = [];
|
||||
/**
|
||||
* 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) {
|
||||
var hash = 0;
|
||||
|
||||
for (var 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) {
|
||||
var prevTime;
|
||||
|
||||
function debug() {
|
||||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
// Disabled?
|
||||
if (!debug.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
var self = debug; // Set `diff` timestamp
|
||||
|
||||
var curr = Number(new Date());
|
||||
var 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
|
||||
|
||||
|
||||
var index = 0;
|
||||
args[0] = args[0].replace(/%([a-zA-Z%])/g, function (match, format) {
|
||||
// If we encounter an escaped % then don't increase the array index
|
||||
if (match === '%%') {
|
||||
return match;
|
||||
}
|
||||
|
||||
index++;
|
||||
var formatter = createDebug.formatters[format];
|
||||
|
||||
if (typeof formatter === 'function') {
|
||||
var 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);
|
||||
var logFn = self.log || createDebug.log;
|
||||
logFn.apply(self, args);
|
||||
}
|
||||
|
||||
debug.namespace = namespace;
|
||||
debug.enabled = createDebug.enabled(namespace);
|
||||
debug.useColors = createDebug.useColors();
|
||||
debug.color = selectColor(namespace);
|
||||
debug.destroy = destroy;
|
||||
debug.extend = extend; // Debug.formatArgs = formatArgs;
|
||||
// debug.rawLog = rawLog;
|
||||
// env-specific initialization logic for debug instances
|
||||
|
||||
if (typeof createDebug.init === 'function') {
|
||||
createDebug.init(debug);
|
||||
}
|
||||
|
||||
createDebug.instances.push(debug);
|
||||
return debug;
|
||||
}
|
||||
|
||||
function destroy() {
|
||||
var index = createDebug.instances.indexOf(this);
|
||||
|
||||
if (index !== -1) {
|
||||
createDebug.instances.splice(index, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function extend(namespace, delimiter) {
|
||||
return createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
||||
}
|
||||
/**
|
||||
* 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 = [];
|
||||
var i;
|
||||
var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
||||
var 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 + '$'));
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < createDebug.instances.length; i++) {
|
||||
var instance = createDebug.instances[i];
|
||||
instance.enabled = createDebug.enabled(instance.namespace);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Disable debug output.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
|
||||
function disable() {
|
||||
createDebug.enable('');
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
var i;
|
||||
var 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;
|
||||
}
|
||||
/**
|
||||
* Coerce `val`.
|
||||
*
|
||||
* @param {Mixed} val
|
||||
* @return {Mixed}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
|
||||
function coerce(val) {
|
||||
if (val instanceof Error) {
|
||||
return val.stack || val.message;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
createDebug.enable(createDebug.load());
|
||||
return createDebug;
|
||||
}
|
||||
|
||||
module.exports = setup;
|
||||
}, {
|
||||
"ms": 1
|
||||
}],
|
||||
4: [function (require, module, exports) {
|
||||
(function (process) {
|
||||
/* eslint-env browser */
|
||||
|
||||
/**
|
||||
* This is the web browser implementation of `debug()`.
|
||||
*/
|
||||
exports.log = log;
|
||||
exports.formatArgs = formatArgs;
|
||||
exports.save = save;
|
||||
exports.load = load;
|
||||
exports.useColors = useColors;
|
||||
exports.storage = localstorage();
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
var 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
|
||||
|
||||
var index = 0;
|
||||
var lastC = 0;
|
||||
args[0].replace(/%[a-zA-Z%]/g, function (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.log()` when available.
|
||||
* No-op when `console.log` is not a "function".
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
|
||||
function log() {
|
||||
var _console;
|
||||
|
||||
// This hackery is required for IE8/9, where
|
||||
// the `console.log` function doesn't have 'apply'
|
||||
return (typeof console === "undefined" ? "undefined" : _typeof(console)) === 'object' && console.log && (_console = console).log.apply(_console, arguments);
|
||||
}
|
||||
/**
|
||||
* 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() {
|
||||
var 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);
|
||||
var formatters = module.exports.formatters;
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
};
|
||||
}).call(this, require('_process'));
|
||||
}, {
|
||||
"./common": 3,
|
||||
"_process": 2
|
||||
}]
|
||||
}, {}, [4])(4);
|
||||
});
|
||||
|
1
node_modules/mocha/node_modules/debug/node.js
generated
vendored
Normal file
1
node_modules/mocha/node_modules/debug/node.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require('./src/node');
|
90
node_modules/mocha/node_modules/debug/package.json
generated
vendored
Normal file
90
node_modules/mocha/node_modules/debug/package.json
generated
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
{
|
||||
"_from": "debug@3.2.6",
|
||||
"_id": "debug@3.2.6",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
|
||||
"_location": "/mocha/debug",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "debug@3.2.6",
|
||||
"name": "debug",
|
||||
"escapedName": "debug",
|
||||
"rawSpec": "3.2.6",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "3.2.6"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/mocha"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
|
||||
"_shasum": "e83d17de16d8a7efb7717edbe5fb10135eee629b",
|
||||
"_spec": "debug@3.2.6",
|
||||
"_where": "/Users/josh.burman/Projects/braid/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"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"ms": "^2.1.1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "small debugging utility",
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.0.0",
|
||||
"@babel/core": "^7.0.0",
|
||||
"@babel/preset-env": "^7.0.0",
|
||||
"browserify": "14.4.0",
|
||||
"chai": "^3.5.0",
|
||||
"concurrently": "^3.1.0",
|
||||
"coveralls": "^3.0.2",
|
||||
"istanbul": "^0.4.5",
|
||||
"karma": "^3.0.0",
|
||||
"karma-chai": "^0.1.0",
|
||||
"karma-mocha": "^1.3.0",
|
||||
"karma-phantomjs-launcher": "^1.0.2",
|
||||
"mocha": "^5.2.0",
|
||||
"mocha-lcov-reporter": "^1.2.0",
|
||||
"rimraf": "^2.5.4",
|
||||
"xo": "^0.23.0"
|
||||
},
|
||||
"files": [
|
||||
"src",
|
||||
"node.js",
|
||||
"dist/debug.js",
|
||||
"LICENSE",
|
||||
"README.md"
|
||||
],
|
||||
"homepage": "https://github.com/visionmedia/debug#readme",
|
||||
"keywords": [
|
||||
"debug",
|
||||
"log",
|
||||
"debugger"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./src/index.js",
|
||||
"name": "debug",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/visionmedia/debug.git"
|
||||
},
|
||||
"unpkg": "./dist/debug.js",
|
||||
"version": "3.2.6"
|
||||
}
|
180
node_modules/mocha/node_modules/debug/src/browser.js
generated
vendored
Normal file
180
node_modules/mocha/node_modules/debug/src/browser.js
generated
vendored
Normal file
@ -0,0 +1,180 @@
|
||||
"use strict";
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
/* eslint-env browser */
|
||||
|
||||
/**
|
||||
* This is the web browser implementation of `debug()`.
|
||||
*/
|
||||
exports.log = log;
|
||||
exports.formatArgs = formatArgs;
|
||||
exports.save = save;
|
||||
exports.load = load;
|
||||
exports.useColors = useColors;
|
||||
exports.storage = localstorage();
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
var 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
|
||||
|
||||
var index = 0;
|
||||
var lastC = 0;
|
||||
args[0].replace(/%[a-zA-Z%]/g, function (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.log()` when available.
|
||||
* No-op when `console.log` is not a "function".
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
|
||||
function log() {
|
||||
var _console;
|
||||
|
||||
// This hackery is required for IE8/9, where
|
||||
// the `console.log` function doesn't have 'apply'
|
||||
return (typeof console === "undefined" ? "undefined" : _typeof(console)) === 'object' && console.log && (_console = console).log.apply(_console, arguments);
|
||||
}
|
||||
/**
|
||||
* 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() {
|
||||
var 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);
|
||||
var formatters = module.exports.formatters;
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
};
|
||||
|
249
node_modules/mocha/node_modules/debug/src/common.js
generated
vendored
Normal file
249
node_modules/mocha/node_modules/debug/src/common.js
generated
vendored
Normal file
@ -0,0 +1,249 @@
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* 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');
|
||||
Object.keys(env).forEach(function (key) {
|
||||
createDebug[key] = env[key];
|
||||
});
|
||||
/**
|
||||
* Active `debug` instances.
|
||||
*/
|
||||
|
||||
createDebug.instances = [];
|
||||
/**
|
||||
* 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) {
|
||||
var hash = 0;
|
||||
|
||||
for (var 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) {
|
||||
var prevTime;
|
||||
|
||||
function debug() {
|
||||
// Disabled?
|
||||
if (!debug.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
var self = debug; // Set `diff` timestamp
|
||||
|
||||
var curr = Number(new Date());
|
||||
var 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
|
||||
|
||||
|
||||
var index = 0;
|
||||
args[0] = args[0].replace(/%([a-zA-Z%])/g, function (match, format) {
|
||||
// If we encounter an escaped % then don't increase the array index
|
||||
if (match === '%%') {
|
||||
return match;
|
||||
}
|
||||
|
||||
index++;
|
||||
var formatter = createDebug.formatters[format];
|
||||
|
||||
if (typeof formatter === 'function') {
|
||||
var 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);
|
||||
var logFn = self.log || createDebug.log;
|
||||
logFn.apply(self, args);
|
||||
}
|
||||
|
||||
debug.namespace = namespace;
|
||||
debug.enabled = createDebug.enabled(namespace);
|
||||
debug.useColors = createDebug.useColors();
|
||||
debug.color = selectColor(namespace);
|
||||
debug.destroy = destroy;
|
||||
debug.extend = extend; // Debug.formatArgs = formatArgs;
|
||||
// debug.rawLog = rawLog;
|
||||
// env-specific initialization logic for debug instances
|
||||
|
||||
if (typeof createDebug.init === 'function') {
|
||||
createDebug.init(debug);
|
||||
}
|
||||
|
||||
createDebug.instances.push(debug);
|
||||
return debug;
|
||||
}
|
||||
|
||||
function destroy() {
|
||||
var index = createDebug.instances.indexOf(this);
|
||||
|
||||
if (index !== -1) {
|
||||
createDebug.instances.splice(index, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function extend(namespace, delimiter) {
|
||||
return createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
||||
}
|
||||
/**
|
||||
* 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 = [];
|
||||
var i;
|
||||
var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
||||
var 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 + '$'));
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < createDebug.instances.length; i++) {
|
||||
var instance = createDebug.instances[i];
|
||||
instance.enabled = createDebug.enabled(instance.namespace);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Disable debug output.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
|
||||
function disable() {
|
||||
createDebug.enable('');
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
var i;
|
||||
var 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;
|
||||
}
|
||||
/**
|
||||
* Coerce `val`.
|
||||
*
|
||||
* @param {Mixed} val
|
||||
* @return {Mixed}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
|
||||
function coerce(val) {
|
||||
if (val instanceof Error) {
|
||||
return val.stack || val.message;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
createDebug.enable(createDebug.load());
|
||||
return createDebug;
|
||||
}
|
||||
|
||||
module.exports = setup;
|
||||
|
12
node_modules/mocha/node_modules/debug/src/index.js
generated
vendored
Normal file
12
node_modules/mocha/node_modules/debug/src/index.js
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* 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');
|
||||
}
|
||||
|
174
node_modules/mocha/node_modules/debug/src/node.js
generated
vendored
Normal file
174
node_modules/mocha/node_modules/debug/src/node.js
generated
vendored
Normal file
@ -0,0 +1,174 @@
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var tty = require('tty');
|
||||
|
||||
var 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;
|
||||
/**
|
||||
* 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
|
||||
var 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(function (key) {
|
||||
return /^debug_/i.test(key);
|
||||
}).reduce(function (obj, key) {
|
||||
// Camel-case
|
||||
var prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, function (_, k) {
|
||||
return k.toUpperCase();
|
||||
}); // Coerce string value into JS value
|
||||
|
||||
var 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) {
|
||||
var name = this.namespace,
|
||||
useColors = this.useColors;
|
||||
|
||||
if (useColors) {
|
||||
var c = this.color;
|
||||
var colorCode = "\x1B[3" + (c < 8 ? c : '8;5;' + c);
|
||||
var prefix = " ".concat(colorCode, ";1m").concat(name, " \x1B[0m");
|
||||
args[0] = prefix + args[0].split('\n').join('\n' + prefix);
|
||||
args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + "\x1B[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() {
|
||||
return process.stderr.write(util.format.apply(util, arguments) + '\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 = {};
|
||||
var keys = Object.keys(exports.inspectOpts);
|
||||
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = require('./common')(exports);
|
||||
var formatters = module.exports.formatters;
|
||||
/**
|
||||
* 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).replace(/\s*\n\s*/g, ' ');
|
||||
};
|
||||
/**
|
||||
* 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
node_modules/mocha/node_modules/ms/index.js
generated
vendored
Normal file
162
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' && isNaN(val) === false) {
|
||||
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?\.?\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
node_modules/mocha/node_modules/ms/license.md
generated
vendored
Normal file
21
node_modules/mocha/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.
|
70
node_modules/mocha/node_modules/ms/package.json
generated
vendored
Normal file
70
node_modules/mocha/node_modules/ms/package.json
generated
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
{
|
||||
"_from": "ms@2.1.1",
|
||||
"_id": "ms@2.1.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==",
|
||||
"_location": "/mocha/ms",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "ms@2.1.1",
|
||||
"name": "ms",
|
||||
"escapedName": "ms",
|
||||
"rawSpec": "2.1.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "2.1.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/mocha",
|
||||
"/mocha/debug"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
|
||||
"_shasum": "30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a",
|
||||
"_spec": "ms@2.1.1",
|
||||
"_where": "/Users/josh.burman/Projects/braid/node_modules/mocha",
|
||||
"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.1"
|
||||
}
|
60
node_modules/mocha/node_modules/ms/readme.md
generated
vendored
Normal file
60
node_modules/mocha/node_modules/ms/readme.md
generated
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
# ms
|
||||
|
||||
[](https://travis-ci.org/zeit/ms)
|
||||
[](https://zeit.chat/)
|
||||
|
||||
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`
|
2006
node_modules/mocha/package.json
generated
vendored
Normal file
2006
node_modules/mocha/package.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user