Files

Return to Package Diff Home.
Brought to you by Intrinsic.

Package Diff: mocha @ 4.0.1 .. 4.1.0

bin/.eslintrc.yml

@@ -0,0 +1,3 @@
+env:
+ es6: true
+ browser: false

bin/mocha

@@ -7,17 +7,17 @@
* when found, before invoking the "real" _mocha(1) executable.
*/
-var spawn = require('child_process').spawn;
-var path = require('path');
-var getOptions = require('./options');
-var args = [path.join(__dirname, '_mocha')];
+const spawn = require('child_process').spawn;
+const path = require('path');
+const getOptions = require('./options');
+const args = [path.join(__dirname, '_mocha')];
// Load mocha.opts into process.argv
// Must be loaded here to handle node-specific options
getOptions();
-process.argv.slice(2).forEach(function (arg) {
- var flag = arg.split('=')[0];
+process.argv.slice(2).forEach(arg => {
+ const flag = arg.split('=')[0];
switch (flag) {
case '-d':
@@ -69,9 +69,11 @@
}
});
-var proc = spawn(process.execPath, args, { stdio: 'inherit' });
-proc.on('exit', function (code, signal) {
- process.on('exit', function () {
+const proc = spawn(process.execPath, args, {
+ stdio: 'inherit'
+});
+proc.on('exit', (code, signal) => {
+ process.on('exit', () => {
if (signal) {
process.kill(process.pid, signal);
} else {
@@ -81,7 +83,7 @@
});
// terminate children.
-process.on('SIGINT', function () {
+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.
});

bin/_mocha

@@ -7,52 +7,136 @@
* Module dependencies.
*/
-var program = require('commander');
-var path = require('path');
-var fs = require('fs');
-var resolve = path.resolve;
-var exists = fs.existsSync || path.existsSync;
-var Mocha = require('../');
-var utils = Mocha.utils;
-var interfaceNames = Object.keys(Mocha.interfaces);
-var join = path.join;
-var cwd = process.cwd();
-var getOptions = require('./options');
-var mocha = new Mocha();
+const program = require('commander');
+const path = require('path');
+const fs = require('fs');
+const resolve = path.resolve;
+const exists = fs.existsSync;
+const Mocha = require('../');
+const utils = Mocha.utils;
+const interfaceNames = Object.keys(Mocha.interfaces);
+const join = path.join;
+const cwd = process.cwd();
+const getOptions = require('./options');
+const mocha = new Mocha();
/**
* 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;
+const Date = global.Date;
+const setTimeout = global.setTimeout;
+const setInterval = global.setInterval;
+const clearTimeout = global.clearTimeout;
+const clearInterval = global.clearInterval;
+
+/**
+ * Exits Mocha when tests + code under test has finished execution (default)
+ * @param {number} code - Exit code; typically # of failures
+ */
+const exitLater = code => {
+ process.on('exit', () => {
+ process.exit(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
+ */
+const exit = 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();
+};
+
+/**
+ * Parse list.
+ */
+const list = str => str.split(/ *, */);
+
+/**
+ * Hide the cursor.
+ */
+const hideCursor = () => {
+ process.stdout.write('\u001b[?25l');
+};
+
+/**
+ * Show the cursor.
+ */
+const showCursor = () => {
+ process.stdout.write('\u001b[?25h');
+};
+
+/**
+ * Stop play()ing.
+ */
+const stop = () => {
+ process.stdout.write('\u001b[2K');
+ clearInterval(play.timer);
+};
+
+/**
+ * Play the given array of strings.
+ */
+const play = (arr, interval) => {
+ const len = arr.length;
+ interval = interval || 100;
+ let i = 0;
+
+ play.timer = setInterval(() => {
+ const str = arr[i++ % len];
+ process.stdout.write(`\u001b[0G${str}`);
+ }, interval);
+};
/**
* Files.
*/
-var files = [];
+let files = [];
/**
* Globals.
*/
-var globals = [];
+let globals = [];
/**
* Requires.
*/
-var requires = [];
+const requires = [];
/**
* Images.
*/
-var images = {
+const images = {
fail: path.join(__dirname, '..', 'images', 'error.png'),
pass: path.join(__dirname, '..', 'images', 'ok.png')
};
@@ -78,7 +162,7 @@
.option('-r, --require <name>', 'require the given module')
.option('-s, --slow <ms>', '"slow" test threshold in milliseconds [75]')
.option('-t, --timeout <ms>', 'set test-case timeout in milliseconds [2000]')
- .option('-u, --ui <name>', 'specify user-interface (' + interfaceNames.join('|') + ')', 'bdd')
+ .option('-u, --ui <name>', `specify user-interface (${interfaceNames.join('|')})`, 'bdd')
.option('-w, --watch', 'watch files for changes')
.option('--check-leaks', 'check for global variable leaks')
.option('--full-trace', 'display the full stack trace')
@@ -90,6 +174,7 @@
.option('--preserve-symlinks', 'Instructs the module loader to preserve symbolic links when resolving and caching modules')
.option('--icu-data-dir', 'include ICU data')
.option('--inline-diffs', 'display actual/expected differences inline within each string')
+ .option('--no-diff', 'do not show a diff on failure')
.option('--inspect', 'activate devtools in chrome')
.option('--inspect-brk', 'activate devtools in chrome and break on the first line')
.option('--interfaces', 'display available interfaces')
@@ -123,12 +208,12 @@
program
.command('init <path>')
.description('initialize a client-side mocha setup at <path>')
- .action(function (path) {
- var mkdir = require('mkdirp');
+ .action(path => {
+ const mkdir = require('mkdirp');
mkdir.sync(path);
- var css = fs.readFileSync(join(__dirname, '..', 'mocha.css'));
- var js = fs.readFileSync(join(__dirname, '..', 'mocha.js'));
- var tmpl = fs.readFileSync(join(__dirname, '..', 'lib/template.html'));
+ const css = fs.readFileSync(join(__dirname, '..', 'mocha.css'));
+ const js = fs.readFileSync(join(__dirname, '..', 'mocha.js'));
+ const tmpl = fs.readFileSync(join(__dirname, '..', 'lib/template.html'));
fs.writeFileSync(join(path, 'mocha.css'), css);
fs.writeFileSync(join(path, 'mocha.js'), js);
fs.writeFileSync(join(path, 'tests.js'), '');
@@ -138,13 +223,13 @@
// --globals
-program.on('option:globals', function (val) {
+program.on('option:globals', val => {
globals = globals.concat(list(val));
});
// --reporters
-program.on('option:reporters', function () {
+program.on('option:reporters', () => {
console.log();
console.log(' dot - dot matrix');
console.log(' doc - html documentation');
@@ -165,10 +250,10 @@
// --interfaces
-program.on('option:interfaces', function () {
+program.on('option:interfaces', () => {
console.log('');
- interfaceNames.forEach(function (interfaceName) {
- console.log(' ' + interfaceName);
+ interfaceNames.forEach(interfaceName => {
+ console.log(` ${interfaceName}`);
});
console.log('');
process.exit();
@@ -178,8 +263,8 @@
module.paths.push(cwd, join(cwd, 'node_modules'));
-program.on('option:require', function (mod) {
- var abs = exists(mod) || exists(mod + '.js');
+program.on('option:require', mod => {
+ const abs = exists(mod) || exists(`${mod}.js`);
if (abs) {
mod = resolve(mod);
}
@@ -201,12 +286,12 @@
// reporter options
-var reporterOptions = {};
+const reporterOptions = {};
if (program.reporterOptions !== undefined) {
- program.reporterOptions.split(',').forEach(function (opt) {
- var L = opt.split('=');
+ program.reporterOptions.split(',').forEach(opt => {
+ const L = opt.split('=');
if (L.length > 2 || L.length === 0) {
- throw new Error("invalid reporter option '" + opt + "'");
+ throw new Error(`invalid reporter option '${opt}'`);
} else if (L.length === 2) {
reporterOptions[L[0]] = L[1];
} else {
@@ -221,14 +306,14 @@
// load reporter
-var Reporter = null;
+let Reporter = null;
try {
- Reporter = require('../lib/reporters/' + program.reporter);
+ Reporter = require(`../lib/reporters/${program.reporter}`);
} catch (err) {
try {
Reporter = require(program.reporter);
} catch (err2) {
- throw new Error('reporter "' + program.reporter + '" does not exist');
+ throw new Error(`reporter "${program.reporter}" does not exist`);
}
}
@@ -250,6 +335,12 @@
mocha.useInlineDiffs(true);
}
+// --no-diff
+
+if (process.argv.indexOf('--no-diff') !== -1) {
+ mocha.hideDiff(true);
+}
+
// --slow <ms>
if (program.slow) {
@@ -347,14 +438,14 @@
// custom compiler support
if (program.compilers.length > 0) {
- require('util').deprecate(function () {},
+ require('util').deprecate(() => {},
'"--compilers" will be removed in a future version of Mocha; see https://git.io/vdcSr for more info')();
}
-var extensions = ['js'];
-program.compilers.forEach(function (c) {
- var idx = c.indexOf(':');
- var ext = c.slice(0, idx);
- var mod = c.slice(idx + 1);
+const extensions = ['js'];
+program.compilers.forEach(c => {
+ const idx = c.indexOf(':');
+ const ext = c.slice(0, idx);
+ let mod = c.slice(idx + 1);
if (mod[0] === '.') {
mod = join(process.cwd(), mod);
@@ -366,7 +457,7 @@
// requires
-requires.forEach(function (mod) {
+requires.forEach(mod => {
require(mod);
});
@@ -376,7 +467,7 @@
// args
-var args = program.args;
+const args = program.args;
// default files to test/*.{js,coffee}
@@ -384,13 +475,13 @@
args.push('test');
}
-args.forEach(function (arg) {
- var newFiles;
+args.forEach(arg => {
+ let newFiles;
try {
newFiles = utils.lookupFiles(arg, extensions, program.recursive);
} catch (err) {
if (err.message.indexOf('cannot resolve path') === 0) {
- console.error('Warning: Could not find any test files matching pattern: ' + arg);
+ console.error(`Warning: Could not find any test files matching pattern: ${arg}`);
return;
}
@@ -407,9 +498,7 @@
// resolve
-files = files.map(function (path) {
- return resolve(path);
-});
+files = files.map(path => resolve(path));
if (program.sort) {
files.sort();
@@ -417,28 +506,28 @@
// --watch
-var runner;
-var loadAndRun;
-var purge;
-var rerun;
+let runner;
+let loadAndRun;
+let purge;
+let rerun;
if (program.watch) {
console.log();
hideCursor();
- process.on('SIGINT', function () {
+ process.on('SIGINT', () => {
showCursor();
console.log('\n');
process.exit(130);
});
- var watchFiles = utils.files(cwd, [ 'js' ].concat(program.watchExtensions));
- var runAgain = false;
+ const watchFiles = utils.files(cwd, [ 'js' ].concat(program.watchExtensions));
+ let runAgain = false;
- loadAndRun = function loadAndRun () {
+ loadAndRun = () => {
try {
mocha.files = files;
runAgain = false;
- runner = mocha.run(function () {
+ runner = mocha.run(() => {
runner = null;
if (runAgain) {
rerun();
@@ -449,15 +538,15 @@
}
};
- purge = function purge () {
- watchFiles.forEach(function (file) {
+ purge = () => {
+ watchFiles.forEach(file => {
delete require.cache[file];
});
};
loadAndRun();
- rerun = function rerun () {
+ rerun = () => {
purge();
stop();
if (!program.grep) {
@@ -469,7 +558,7 @@
loadAndRun();
};
- utils.watch(watchFiles, function () {
+ utils.watch(watchFiles, () => {
runAgain = true;
if (runner) {
runner.abort();
@@ -484,41 +573,7 @@
runner = mocha.run(program.exit ? exit : exitLater);
}
-function exitLater (code) {
- process.on('exit', function () {
- process.exit(Math.min(code, 255));
- });
-}
-
-function exit (code) {
- var clampedCode = Math.min(code, 255);
-
- // 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
- function done () {
- if (!(draining--)) {
- process.exit(clampedCode);
- }
- }
-
- var draining = 0;
- var streams = [process.stdout, process.stderr];
-
- streams.forEach(function (stream) {
- // submit empty write request and wait for completion
- draining += 1;
- stream.write('', done);
- });
-
- done();
-}
-
-process.on('SIGINT', function () {
+process.on('SIGINT', () => {
runner.abort();
// This is a hack:
@@ -526,51 +581,3 @@
// The amount of failures will be emitted as error code later
runner.failures = 130;
});
-
-/**
- * Parse list.
- */
-
-function list (str) {
- return str.split(/ *, */);
-}
-
-/**
- * Hide the cursor.
- */
-
-function hideCursor () {
- process.stdout.write('\u001b[?25l');
-}
-
-/**
- * Show the cursor.
- */
-
-function showCursor () {
- process.stdout.write('\u001b[?25h');
-}
-
-/**
- * Stop play()ing.
- */
-
-function stop () {
- process.stdout.write('\u001b[2K');
- clearInterval(play.timer);
-}
-
-/**
- * Play the given array of strings.
- */
-
-function play (arr, interval) {
- var len = arr.length;
- interval = interval || 100;
- var i = 0;
-
- play.timer = setInterval(function () {
- var str = arr[i++ % len];
- process.stdout.write('\u001b[0G' + str);
- }, interval);
-}

bin/options.js

@@ -4,7 +4,7 @@
* Dependencies.
*/
-var fs = require('fs');
+const fs = require('fs');
/**
* Export `getOptions`.
@@ -17,18 +17,20 @@
*/
function getOptions () {
- var optsPath = process.argv.indexOf('--opts') === -1
+ if (process.argv.length === 3 && (process.argv[2] === '-h' || process.argv[2] === '--help')) {
+ return;
+ }
+
+ const optsPath = process.argv.indexOf('--opts') === -1
? 'test/mocha.opts'
: process.argv[process.argv.indexOf('--opts') + 1];
try {
- var opts = fs.readFileSync(optsPath, 'utf8')
+ const opts = fs.readFileSync(optsPath, 'utf8')
.replace(/\\\s/g, '%20')
.split(/\s/)
.filter(Boolean)
- .map(function (value) {
- return value.replace(/%20/g, ' ');
- });
+ .map(value => value.replace(/%20/g, ' '));
process.argv = process.argv
.slice(0, 2)

CHANGELOG.md

@@ -1,3 +1,55 @@
+# 4.1.0 / 2017-12-28
+
+This is mainly a "housekeeping" release.
+
+Welcome [@Bamieh] and [@xxczaki] to the team!
+
+## :bug:: Fixes
+
+- [#2661]: `progress` reporter now accepts reporter options ([@canoztokmak])
+- [#3142]: `xit` in `bdd` interface now properly returns its `Test` object ([@Bamieh])
+- [#3075]: Diffs now computed eagerly to avoid misinformation when reported ([@abrady0])
+- [#2745]: `--help` will now help you even if you have a `mocha.opts` ([@Zarel])
+
+## :tada: Enhancements
+
+- [#2514]: The `--no-diff` flag will completely disable diff output ([@CapacitorSet])
+- [#3058]: All "setters" in Mocha's API are now also "getters" if called without arguments ([@makepanic])
+
+## :book: Documentation
+
+- [#3170]: Optimization and site speed improvements ([@Munter])
+- [#2987]: Moved the old [site repo](https://github.com/mochajs/mochajs.github.io) into the main repo under `docs/` ([@boneskull])
+- [#2896]: Add [maintainer guide](https://github.com/mochajs/mocha/blob/master/MAINTAINERS.md) ([@boneskull])
+- Various fixes and updates ([@xxczaki], [@maty21], [@leedm777])
+
+## :nut_and_bolt: Other
+
+- Test improvements and fixes ([@eugenet8k], [@ngeor], [@38elements], [@Gerhut], [@ScottFreeCode], [@boneskull])
+- Refactoring and cruft excision ([@38elements], [@Bamieh], [@finnigantime], [@boneskull])
+
+[#2661]: https://github.com/mochajs/mocha/issues/2661
+[#3142]: https://github.com/mochajs/mocha/issues/3142
+[#3075]: https://github.com/mochajs/mocha/pull/3075
+[#2745]: https://github.com/mochajs/mocha/issues/2745
+[#2514]: https://github.com/mochajs/mocha/issues/2514
+[#3058]: https://github.com/mochajs/mocha/issues/3058
+[#3170]: https://github.com/mochajs/mocha/pull/3170
+[#2987]: https://github.com/mochajs/mocha/issues/2987
+[#2896]: https://github.com/mochajs/mocha/issues/2896
+[@canoztokmak]: https://github.com/canoztokmak
+[@Bamieh]: https://github.com/Bamieh
+[@abrady0]: https://github.com/abrady0
+[@Zarel]: https://github.com/Zarel
+[@CapacitorSet]: https://github.com/CapacitorSet
+[@xxczaki]: https://github.com/xxczaki
+[@maty21]: https://github.com/maty21
+[@leedm777]: https://github.com/leedm777
+[@eugenet8k]: https://github.com/eugenet8k
+[@38elements]: https://github.com/38elements
+[@Gerhut]: https://github.com/Gerhut
+[@finnigantime]: https://github.com/finnigantime
+
# 4.0.1 / 2017-10-05
## :bug: Fixes

lib/browser/.eslintrc.yaml

@@ -1,4 +0,0 @@
-env:
- node: false
- browser: false
- commonjs: true

lib/browser/.eslintrc.yml

@@ -0,0 +1,4 @@
+env:
+ node: false
+ browser: false
+ commonjs: true

lib/context.js

@@ -29,7 +29,7 @@
};
/**
- * Set test timeout `ms`.
+ * Set or get test timeout `ms`.
*
* @api private
* @param {number} ms
@@ -51,18 +51,24 @@
* @return {Context} self
*/
Context.prototype.enableTimeouts = function (enabled) {
+ if (!arguments.length) {
+ return this.runnable().enableTimeouts();
+ }
this.runnable().enableTimeouts(enabled);
return this;
};
/**
- * Set test slowness threshold `ms`.
+ * Set or get test slowness threshold `ms`.
*
* @api 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;
};
@@ -78,7 +84,7 @@
};
/**
- * Allow a number of retries on failed tests
+ * Set or get a number of allowed retries on failed tests
*
* @api private
* @param {number} n
@@ -91,15 +97,3 @@
this.runnable().retries(n);
return this;
};
-
-/**
- * Inspect the context void of `._runnable`.
- *
- * @api private
- * @return {string}
- */
-Context.prototype.inspect = function () {
- return JSON.stringify(this, function (key, val) {
- return key === 'runnable' || key === 'test' ? undefined : val;
- }, 2);
-};

lib/interfaces/bdd.js

@@ -102,7 +102,7 @@
*/
context.xit = context.xspecify = context.it.skip = function (title) {
- context.it(title);
+ return context.it(title);
};
/**

lib/mocha.js

@@ -390,6 +390,20 @@
};
/**
+ * Do not show diffs at all.
+ *
+ * @param {Boolean} hideDiff
+ * @return {Mocha}
+ * @api public
+ * @param {boolean} hideDiff
+ * @return {Mocha}
+ */
+Mocha.prototype.hideDiff = function (hideDiff) {
+ this.options.hideDiff = hideDiff !== undefined && hideDiff;
+ return this;
+};
+
+/**
* Set the timeout in milliseconds.
*
* @param {Number} timeout
@@ -505,6 +519,14 @@
/**
* Run tests and invoke `fn()` when complete.
*
+ * Note that `loadFiles` relies on Node's `require` to execute
+ * the test interface functions and will be subject to the
+ * cache - if the files are already in the `require` cache,
+ * they will effectively be skipped. Therefore, 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 in whichever manner best suits your needs.
+ *
* @api public
* @param {Function} fn
* @return {Runner}
@@ -537,6 +559,7 @@
exports.reporters.Base.useColors = options.useColors;
}
exports.reporters.Base.inlineDiffs = options.useInlineDiffs;
+ exports.reporters.Base.hideDiff = options.hideDiff;
function done (failures) {
if (reporter.done) {

lib/ms.js

@@ -13,22 +13,15 @@
/**
* Parse or format the given `val`.
*
- * Options:
- *
- * - `long` verbose formatting [false]
- *
* @api public
* @param {string|number} val
- * @param {Object} options
* @return {string|number}
*/
-module.exports = function (val, options) {
- options = options || {};
+module.exports = function (val) {
if (typeof val === 'string') {
return parse(val);
}
- // https://github.com/mochajs/mocha/pull/1035
- return options['long'] ? longFormat(val) : shortFormat(val);
+ return format(val);
};
/**
@@ -74,13 +67,13 @@
}
/**
- * Short format for `ms`.
+ * Format for `ms`.
*
* @api private
* @param {number} ms
* @return {string}
*/
-function shortFormat (ms) {
+function format (ms) {
if (ms >= d) {
return Math.round(ms / d) + 'd';
}
@@ -95,36 +88,3 @@
}
return ms + 'ms';
}
-
-/**
- * Long format for `ms`.
- *
- * @api private
- * @param {number} ms
- * @return {string}
- */
-function longFormat (ms) {
- return plural(ms, d, 'day') ||
- plural(ms, h, 'hour') ||
- plural(ms, m, 'minute') ||
- plural(ms, s, 'second') ||
- ms + ' ms';
-}
-
-/**
- * Pluralization helper.
- *
- * @api private
- * @param {number} ms
- * @param {number} n
- * @param {string} name
- */
-function plural (ms, n, name) {
- if (ms < n) {
- return;
- }
- if (ms < n * 1.5) {
- return Math.floor(ms / n) + ' ' + name;
- }
- return Math.ceil(ms / n) + ' ' + name + 's';
-}

lib/reporters/base.js

@@ -155,6 +155,17 @@
}
};
+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);
+ }
+}
+
/**
* Output the given `failures` as a list.
*
@@ -183,9 +194,6 @@
}
var stack = err.stack || message;
var index = message ? stack.indexOf(message) : -1;
- var actual = err.actual;
- var expected = err.expected;
- var escape = true;
if (index === -1) {
msg = message;
@@ -201,21 +209,16 @@
msg = 'Uncaught ' + msg;
}
// explicitly show diff
- if (err.showDiff !== false && sameType(actual, expected) && expected !== undefined) {
- escape = false;
- if (!(utils.isString(actual) && utils.isString(expected))) {
- err.actual = actual = utils.stringify(actual);
- err.expected = expected = utils.stringify(expected);
- }
-
+ 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);
if (exports.inlineDiffs) {
- msg += inlineDiff(err, escape);
+ msg += inlineDiff(err);
} else {
- msg += unifiedDiff(err, escape);
+ msg += unifiedDiff(err);
}
}
@@ -292,6 +295,9 @@
runner.on('fail', function (test, err) {
stats.failures = stats.failures || 0;
stats.failures++;
+ if (showDiff(err)) {
+ stringifyDiffObjs(err);
+ }
test.err = err;
failures.push(test);
});
@@ -366,11 +372,10 @@
*
* @api private
* @param {Error} err with actual/expected
- * @param {boolean} escape
* @return {string} Diff
*/
-function inlineDiff (err, escape) {
- var msg = errorDiff(err, 'WordsWithSpace', escape);
+function inlineDiff (err) {
+ var msg = errorDiff(err);
// linenos
var lines = msg.split('\n');
@@ -400,15 +405,11 @@
*
* @api private
* @param {Error} err with actual/expected
- * @param {boolean} escape
* @return {string} The diff.
*/
-function unifiedDiff (err, escape) {
+function unifiedDiff (err) {
var indent = ' ';
function cleanUp (line) {
- if (escape) {
- line = escapeInvisibles(line);
- }
if (line[0] === '+') {
return indent + colorLines('diff added', line);
}
@@ -440,14 +441,10 @@
*
* @api private
* @param {Error} err
- * @param {string} type
- * @param {boolean} escape
* @return {string}
*/
-function errorDiff (err, type, escape) {
- var actual = escape ? escapeInvisibles(err.actual) : err.actual;
- var expected = escape ? escapeInvisibles(err.expected) : err.expected;
- return diff['diff' + type](actual, expected).map(function (str) {
+function errorDiff (err) {
+ return diff.diffWordsWithSpace(err.actual, err.expected).map(function (str) {
if (str.added) {
return colorLines('diff added', str.value);
}
@@ -459,19 +456,6 @@
}
/**
- * Returns a string with all invisible characters in plain text
- *
- * @api private
- * @param {string} line
- * @return {string}
- */
-function escapeInvisibles (line) {
- return line.replace(/\t/g, '<tab>')
- .replace(/\r/g, '<CR>')
- .replace(/\n/g, '<LF>\n');
-}
-
-/**
* Color lines for `str`, using the color `name`.
*
* @api private

lib/reporters/base.js.orig

@@ -0,0 +1,498 @@
+'use strict';
+
+/**
+ * Module dependencies.
+ */
+
+var tty = require('tty');
+var diff = require('diff');
+var ms = require('../ms');
+var utils = require('../utils');
+var supportsColor = process.browser ? null : require('supports-color');
+
+/**
+ * Expose `Base`.
+ */
+
+exports = module.exports = Base;
+
+/**
+ * Save timer references to avoid Sinon interfering.
+ * See: https://github.com/mochajs/mocha/issues/237
+ */
+
+/* eslint-disable no-unused-vars, no-native-reassign */
+var Date = global.Date;
+var setTimeout = global.setTimeout;
+var setInterval = global.setInterval;
+var clearTimeout = global.clearTimeout;
+var clearInterval = global.clearInterval;
+/* eslint-enable no-unused-vars, no-native-reassign */
+
+/**
+ * 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 || (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}
+ * @api 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);
+ }
+}
+
+/**
+ * Output the given `failures` as a list.
+ *
+ * @param {Array} failures
+ * @api public
+ */
+
+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
+<<<<<<< HEAD
+ if (showDiff(err)) {
+ stringifyDiffObjs(err);
+=======
+ if (exports.hideDiff !== true && err.showDiff !== false && sameType(actual, expected) && expected !== undefined) {
+ escape = false;
+ if (!(utils.isString(actual) && utils.isString(expected))) {
+ err.actual = actual = utils.stringify(actual);
+ err.expected = expected = utils.stringify(expected);
+ }
+
+>>>>>>> Add --no-diff option (fixes mochajs/mocha#2514)
+ 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);
+
+ if (exports.inlineDiffs) {
+ msg += inlineDiff(err);
+ } else {
+ msg += unifiedDiff(err);
+ }
+ }
+
+ // 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, providing
+ * stats such as test duration, number
+ * of tests passed / failed etc.
+ *
+ * @param {Runner} runner
+ * @api public
+ */
+
+function Base (runner) {
+ var stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 };
+ var failures = this.failures = [];
+
+ if (!runner) {
+ return;
+ }
+ this.runner = runner;
+
+ runner.stats = stats;
+
+ runner.on('start', function () {
+ stats.start = new Date();
+ });
+
+ runner.on('suite', function (suite) {
+ stats.suites = stats.suites || 0;
+ suite.root || stats.suites++;
+ });
+
+ runner.on('test end', function () {
+ stats.tests = stats.tests || 0;
+ stats.tests++;
+ });
+
+ runner.on('pass', function (test) {
+ stats.passes = stats.passes || 0;
+
+ if (test.duration > test.slow()) {
+ test.speed = 'slow';
+ } else if (test.duration > test.slow() / 2) {
+ test.speed = 'medium';
+ } else {
+ test.speed = 'fast';
+ }
+
+ stats.passes++;
+ });
+
+ runner.on('fail', function (test, err) {
+ stats.failures = stats.failures || 0;
+ stats.failures++;
+ if (showDiff(err)) {
+ stringifyDiffObjs(err);
+ }
+ test.err = err;
+ failures.push(test);
+ });
+
+ runner.on('end', function () {
+ stats.end = new Date();
+ stats.duration = new Date() - stats.start;
+ });
+
+ runner.on('pending', function () {
+ stats.pending++;
+ });
+}
+
+/**
+ * Output common epilogue used by many of
+ * the bundled reporters.
+ *
+ * @api 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,
+ ms(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`.
+ *
+ * @api 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
+ *
+ * @api private
+ * @param {Error} err with actual/expected
+ * @return {string} Diff
+ */
+function inlineDiff (err) {
+ var msg = errorDiff(err);
+
+ // 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.
+ *
+ * @api private
+ * @param {Error} err with actual/expected
+ * @return {string} The diff.
+ */
+function unifiedDiff (err) {
+ 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', err.actual, err.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`.
+ *
+ * @api private
+ * @param {Error} err
+ * @return {string}
+ */
+function errorDiff (err) {
+ return diff.diffWordsWithSpace(err.actual, err.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`.
+ *
+ * @api 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.
+ *
+ * @api private
+ * @param {Object} a
+ * @param {Object} b
+ * @return {boolean}
+ */
+function sameType (a, b) {
+ return objToString.call(a) === objToString.call(b);
+}

lib/reporters/progress.js

@@ -39,11 +39,13 @@
// default chars
options = options || {};
- options.open = options.open || '[';
- options.complete = options.complete || '▬';
- options.incomplete = options.incomplete || Base.symbols.dot;
- options.close = options.close || ']';
- options.verbose = false;
+ 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('start', function () {

lib/runnable.js

@@ -91,14 +91,14 @@
};
/**
- * Set & get slow `ms`.
+ * Set or get slow `ms`.
*
* @api private
* @param {number|string} ms
* @return {Runnable|number} ms or Runnable instance.
*/
Runnable.prototype.slow = function (ms) {
- if (typeof ms === 'undefined') {
+ if (!arguments.length || typeof ms === 'undefined') {
return this._slow;
}
if (typeof ms === 'string') {
@@ -144,7 +144,7 @@
};
/**
- * Set number of retries.
+ * Set or get number of retries.
*
* @api private
*/
@@ -156,7 +156,7 @@
};
/**
- * Get current retry
+ * Set or get current retry
*
* @api private
*/
@@ -242,7 +242,7 @@
};
/**
- * Whitelist a list of globals for this test run.
+ * Set or get a list of whitelisted globals for this test run.
*
* @api private
* @param {string[]} globals

lib/suite.js

@@ -92,7 +92,7 @@
};
/**
- * Set timeout `ms` or short-hand such as "2s".
+ * Set or get timeout `ms` or short-hand such as "2s".
*
* @api private
* @param {number|string} ms
@@ -114,7 +114,7 @@
};
/**
- * Set number of times to retry a failed test.
+ * Set or get number of times to retry a failed test.
*
* @api private
* @param {number|string} n
@@ -130,7 +130,7 @@
};
/**
- * Set timeout to `enabled`.
+ * Set or get timeout to `enabled`.
*
* @api private
* @param {boolean} enabled
@@ -146,7 +146,7 @@
};
/**
- * Set slow `ms` or short-hand such as "2s".
+ * Set or get slow `ms` or short-hand such as "2s".
*
* @api private
* @param {number|string} ms
@@ -165,7 +165,7 @@
};
/**
- * Sets whether to bail after first error.
+ * Set or get whether to bail after first error.
*
* @api private
* @param {boolean} bail

lib/utils.js

@@ -476,7 +476,6 @@
*/
exports.lookupFiles = function lookupFiles (path, extensions, recursive) {
var files = [];
- var re = new RegExp('\\.(' + extensions.join('|') + ')$');
if (!exists(path)) {
if (exists(path + '.js')) {
@@ -514,6 +513,7 @@
// ignore error
return;
}
+ var re = new RegExp('\\.(?:' + extensions.join('|') + ')$');
if (!stat.isFile() || !re.test(file) || basename(file)[0] === '.') {
return;
}

mocha.js

@@ -366,7 +366,7 @@
};
/**
- * Set test timeout `ms`.
+ * Set or get test timeout `ms`.
*
* @api private
* @param {number} ms
@@ -388,18 +388,24 @@
* @return {Context} self
*/
Context.prototype.enableTimeouts = function (enabled) {
+ if (!arguments.length) {
+ return this.runnable().enableTimeouts();
+ }
this.runnable().enableTimeouts(enabled);
return this;
};
/**
- * Set test slowness threshold `ms`.
+ * Set or get test slowness threshold `ms`.
*
* @api 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;
};
@@ -415,7 +421,7 @@
};
/**
- * Allow a number of retries on failed tests
+ * Set or get a number of allowed retries on failed tests
*
* @api private
* @param {number} n
@@ -429,18 +435,6 @@
return this;
};
-/**
- * Inspect the context void of `._runnable`.
- *
- * @api private
- * @return {string}
- */
-Context.prototype.inspect = function () {
- return JSON.stringify(this, function (key, val) {
- return key === 'runnable' || key === 'test' ? undefined : val;
- }, 2);
-};
-
},{}],6:[function(require,module,exports){
'use strict';
@@ -596,7 +590,7 @@
*/
context.xit = context.xspecify = context.it.skip = function (title) {
- context.it(title);
+ return context.it(title);
};
/**
@@ -1441,6 +1435,20 @@
};
/**
+ * Do not show diffs at all.
+ *
+ * @param {Boolean} hideDiff
+ * @return {Mocha}
+ * @api public
+ * @param {boolean} hideDiff
+ * @return {Mocha}
+ */
+Mocha.prototype.hideDiff = function (hideDiff) {
+ this.options.hideDiff = hideDiff !== undefined && hideDiff;
+ return this;
+};
+
+/**
* Set the timeout in milliseconds.
*
* @param {Number} timeout
@@ -1556,6 +1564,14 @@
/**
* Run tests and invoke `fn()` when complete.
*
+ * Note that `loadFiles` relies on Node's `require` to execute
+ * the test interface functions and will be subject to the
+ * cache - if the files are already in the `require` cache,
+ * they will effectively be skipped. Therefore, 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 in whichever manner best suits your needs.
+ *
* @api public
* @param {Function} fn
* @return {Runner}
@@ -1588,6 +1604,7 @@
exports.reporters.Base.useColors = options.useColors;
}
exports.reporters.Base.inlineDiffs = options.useInlineDiffs;
+ exports.reporters.Base.hideDiff = options.hideDiff;
function done (failures) {
if (reporter.done) {
@@ -1617,22 +1634,15 @@
/**
* Parse or format the given `val`.
*
- * Options:
- *
- * - `long` verbose formatting [false]
- *
* @api public
* @param {string|number} val
- * @param {Object} options
* @return {string|number}
*/
-module.exports = function (val, options) {
- options = options || {};
+module.exports = function (val) {
if (typeof val === 'string') {
return parse(val);
}
- // https://github.com/mochajs/mocha/pull/1035
- return options['long'] ? longFormat(val) : shortFormat(val);
+ return format(val);
};
/**
@@ -1678,13 +1688,13 @@
}
/**
- * Short format for `ms`.
+ * Format for `ms`.
*
* @api private
* @param {number} ms
* @return {string}
*/
-function shortFormat (ms) {
+function format (ms) {
if (ms >= d) {
return Math.round(ms / d) + 'd';
}
@@ -1700,39 +1710,6 @@
return ms + 'ms';
}
-/**
- * Long format for `ms`.
- *
- * @api private
- * @param {number} ms
- * @return {string}
- */
-function longFormat (ms) {
- return plural(ms, d, 'day') ||
- plural(ms, h, 'hour') ||
- plural(ms, m, 'minute') ||
- plural(ms, s, 'second') ||
- ms + ' ms';
-}
-
-/**
- * Pluralization helper.
- *
- * @api private
- * @param {number} ms
- * @param {number} n
- * @param {string} name
- */
-function plural (ms, n, name) {
- if (ms < n) {
- return;
- }
- if (ms < n * 1.5) {
- return Math.floor(ms / n) + ' ' + name;
- }
- return Math.ceil(ms / n) + ' ' + name + 's';
-}
-
},{}],15:[function(require,module,exports){
'use strict';
@@ -1910,6 +1887,17 @@
}
};
+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);
+ }
+}
+
/**
* Output the given `failures` as a list.
*
@@ -1938,9 +1926,6 @@
}
var stack = err.stack || message;
var index = message ? stack.indexOf(message) : -1;
- var actual = err.actual;
- var expected = err.expected;
- var escape = true;
if (index === -1) {
msg = message;
@@ -1956,21 +1941,16 @@
msg = 'Uncaught ' + msg;
}
// explicitly show diff
- if (err.showDiff !== false && sameType(actual, expected) && expected !== undefined) {
- escape = false;
- if (!(utils.isString(actual) && utils.isString(expected))) {
- err.actual = actual = utils.stringify(actual);
- err.expected = expected = utils.stringify(expected);
- }
-
+ 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);
if (exports.inlineDiffs) {
- msg += inlineDiff(err, escape);
+ msg += inlineDiff(err);
} else {
- msg += unifiedDiff(err, escape);
+ msg += unifiedDiff(err);
}
}
@@ -2047,6 +2027,9 @@
runner.on('fail', function (test, err) {
stats.failures = stats.failures || 0;
stats.failures++;
+ if (showDiff(err)) {
+ stringifyDiffObjs(err);
+ }
test.err = err;
failures.push(test);
});
@@ -2121,11 +2104,10 @@
*
* @api private
* @param {Error} err with actual/expected
- * @param {boolean} escape
* @return {string} Diff
*/
-function inlineDiff (err, escape) {
- var msg = errorDiff(err, 'WordsWithSpace', escape);
+function inlineDiff (err) {
+ var msg = errorDiff(err);
// linenos
var lines = msg.split('\n');
@@ -2155,15 +2137,11 @@
*
* @api private
* @param {Error} err with actual/expected
- * @param {boolean} escape
* @return {string} The diff.
*/
-function unifiedDiff (err, escape) {
+function unifiedDiff (err) {
var indent = ' ';
function cleanUp (line) {
- if (escape) {
- line = escapeInvisibles(line);
- }
if (line[0] === '+') {
return indent + colorLines('diff added', line);
}
@@ -2195,14 +2173,10 @@
*
* @api private
* @param {Error} err
- * @param {string} type
- * @param {boolean} escape
* @return {string}
*/
-function errorDiff (err, type, escape) {
- var actual = escape ? escapeInvisibles(err.actual) : err.actual;
- var expected = escape ? escapeInvisibles(err.expected) : err.expected;
- return diff['diff' + type](actual, expected).map(function (str) {
+function errorDiff (err) {
+ return diff.diffWordsWithSpace(err.actual, err.expected).map(function (str) {
if (str.added) {
return colorLines('diff added', str.value);
}
@@ -2214,19 +2188,6 @@
}
/**
- * Returns a string with all invisible characters in plain text
- *
- * @api private
- * @param {string} line
- * @return {string}
- */
-function escapeInvisibles (line) {
- return line.replace(/\t/g, '<tab>')
- .replace(/\r/g, '<CR>')
- .replace(/\n/g, '<LF>\n');
-}
-
-/**
* Color lines for `str`, using the color `name`.
*
* @api private
@@ -3551,11 +3512,13 @@
// default chars
options = options || {};
- options.open = options.open || '[';
- options.complete = options.complete || '▬';
- options.incomplete = options.incomplete || Base.symbols.dot;
- options.close = options.close || ']';
- options.verbose = false;
+ 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('start', function () {
@@ -4040,14 +4003,14 @@
};
/**
- * Set & get slow `ms`.
+ * Set or get slow `ms`.
*
* @api private
* @param {number|string} ms
* @return {Runnable|number} ms or Runnable instance.
*/
Runnable.prototype.slow = function (ms) {
- if (typeof ms === 'undefined') {
+ if (!arguments.length || typeof ms === 'undefined') {
return this._slow;
}
if (typeof ms === 'string') {
@@ -4093,7 +4056,7 @@
};
/**
- * Set number of retries.
+ * Set or get number of retries.
*
* @api private
*/
@@ -4105,7 +4068,7 @@
};
/**
- * Get current retry
+ * Set or get current retry
*
* @api private
*/
@@ -4191,7 +4154,7 @@
};
/**
- * Whitelist a list of globals for this test run.
+ * Set or get a list of whitelisted globals for this test run.
*
* @api private
* @param {string[]} globals
@@ -5422,7 +5385,7 @@
};
/**
- * Set timeout `ms` or short-hand such as "2s".
+ * Set or get timeout `ms` or short-hand such as "2s".
*
* @api private
* @param {number|string} ms
@@ -5444,7 +5407,7 @@
};
/**
- * Set number of times to retry a failed test.
+ * Set or get number of times to retry a failed test.
*
* @api private
* @param {number|string} n
@@ -5460,7 +5423,7 @@
};
/**
- * Set timeout to `enabled`.
+ * Set or get timeout to `enabled`.
*
* @api private
* @param {boolean} enabled
@@ -5476,7 +5439,7 @@
};
/**
- * Set slow `ms` or short-hand such as "2s".
+ * Set or get slow `ms` or short-hand such as "2s".
*
* @api private
* @param {number|string} ms
@@ -5495,7 +5458,7 @@
};
/**
- * Sets whether to bail after first error.
+ * Set or get whether to bail after first error.
*
* @api private
* @param {boolean} bail
@@ -6275,7 +6238,6 @@
*/
exports.lookupFiles = function lookupFiles (path, extensions, recursive) {
var files = [];
- var re = new RegExp('\\.(' + extensions.join('|') + ')$');
if (!exists(path)) {
if (exists(path + '.js')) {
@@ -6313,6 +6275,7 @@
// ignore error
return;
}
+ var re = new RegExp('\\.(?:' + extensions.join('|') + ')$');
if (!stat.isFile() || !re.test(file) || basename(file)[0] === '.') {
return;
}

package.json

@@ -1,6 +1,6 @@
{
"name": "mocha",
- "version": "4.0.1",
+ "version": "4.1.0",
"description": "simple, flexible, fun test framework",
"keywords": [
"mocha",
@@ -198,6 +198,7 @@
"Nathan Houle <nathan+github@nathanhoule.com> (https://github.com/ndhoule)",
"Nathan Rajlich <nathan@tootallnate.net> (https://github.com/TooTallNate)",
"Nick Fitzgerald (https://github.com/fitzgen)",
+ "Nikolaos Georgiou (https://github.com/ngeor)",
"noirlab (https://github.com/noirlab)",
"Noshir Patel <nosh@blackpiano.com> (https://github.com/noshir-patel)",
"OlegTsyba <oleg.tsyba.ua@gmail.com> (https://github.com/OlegTsyba)",
@@ -295,14 +296,18 @@
"_mocha": "./bin/_mocha"
},
"engines": {
- "node": ">= 4.0.0",
- "npm": ">= 2.15.11"
+ "node": ">= 4.0.0"
},
"scripts": {
"lint": "eslint . bin/*",
"test": "make clean && make test",
"prepublishOnly": "npm test && make clean && make mocha.js",
- "coveralls": "nyc report --reporter=text-lcov | coveralls"
+ "coveralls": "nyc report --reporter=text-lcov | coveralls",
+ "prebuildDocs": "rm -rf docs/_dist && node scripts/docs-update-toc.js",
+ "buildDocs": "bundle exec jekyll build --source ./docs --destination ./docs/_site --config ./docs/_config.yml --safe --drafts",
+ "postbuildDocs": "buildProduction docs/_site/index.html --outroot docs/_dist --canonicalroot https://mochajs.org/ --optimizeimages --svgo --inlinehtmlimage 9400 --inlinehtmlscript 0 --asyncscripts && cp docs/_headers docs/_dist/_headers && node scripts/netlify-headers.js >> docs/_dist/_headers",
+ "prewatchDocs": "node scripts/docs-update-toc.js",
+ "watchDocs": "bundle exec jekyll serve --source ./docs --destination ./docs/_site --config ./docs/_config.yml --safe --drafts --watch"
},
"dependencies": {
"browser-stdout": "1.3.0",
@@ -318,6 +323,7 @@
},
"devDependencies": {
"assert": "^1.4.1",
+ "assetgraph-builder": "^5.6.4",
"browserify": "^14.4.0",
"buffer": "^4.9.1",
"coffee-script": "^1.10.0",
@@ -339,9 +345,10 @@
"karma-mocha-reporter": "^2.2.4",
"karma-phantomjs-launcher": "^1.0.4",
"karma-sauce-launcher": "^1.2.0",
+ "markdown-toc": "^1.2.0",
"nyc": "^11.2.1",
"rimraf": "^2.5.2",
- "should": "^13.1.0",
+ "svgo": "^0.7.2",
"through2": "^2.0.1",
"watchify": "^3.7.0"
},