☕️ Classic, reliable, trusted test framework for Node.js and the browser
building
Christopher Hillereab389f3f106
diff --git a/mocha.js b/mocha.jsindex 128dbd84..5039bfaf 100644--- a/mocha.js+++ b/mocha.js@@ -223,22 +223,7 @@ var JsDiff = (function() {var LineDiff = new Diff();LineDiff.tokenize = function(value) {- var retLines = [],- lines = value.split(/^/m);-- for(var i = 0; i < lines.length; i++) {- var line = lines[i],- lastLine = lines[i - 1];-- // Merge lines that may contain windows new lines- if (line == '\n' && lastLine && lastLine[lastLine.length - 1] === '\r') {- retLines[retLines.length - 1] += '\n';- } else if (line) {- retLines.push(line);- }- }-- return retLines;+ return value.split(/^/m);};return {@@ -851,6 +836,18 @@ Context.prototype.slow = function(ms){return this;};+/**+ * Mark a test as skipped.+ *+ * @return {Context} self+ * @api private+ */++Context.prototype.skip = function(){+ this.runnable().skip();+ return this;+};+/*** Inspect the context void of `._runnable`.*@@ -1825,9 +1822,7 @@ Mocha.prototype.run = function(fn){function done(failures) {if (reporter.done) {reporter.done(failures, fn);- } else {- fn(failures);- }+ } else fn && fn(failures);}return runner.run(done);@@ -1948,6 +1943,26 @@ function plural(ms, n, name) {}); // module: ms.js+require.register("pending.js", function(module, exports, require){++/**+ * Expose `Pending`.+ */++module.exports = Pending;++/**+ * Initialize a new `Pending` error with the given message.+ *+ * @param {String} message+ */++function Pending(message) {+ this.message = message;+}++}); // module: pending.js+require.register("reporters/base.js", function(module, exports, require){/*** Module dependencies.@@ -1956,7 +1971,8 @@ require.register("reporters/base.js", function(module, exports, require){var tty = require('browser/tty'), diff = require('browser/diff'), ms = require('../ms')- , utils = require('../utils');+ , utils = require('../utils')+ , supportsColor = require('supports-color');/*** Save timer references to avoid Sinon interfering (see GH-237).@@ -1984,7 +2000,7 @@ exports = module.exports = Base;* Enable coloring by default.*/-exports.useColors = isatty || (process.env.MOCHA_COLORS !== undefined);+exports.useColors = supportsColor || (process.env.MOCHA_COLORS !== undefined);/*** Inline diffs instead of +/-@@ -2126,7 +2142,6 @@ exports.list = function(failures){if (err.uncaught) {msg = 'Uncaught ' + msg;}-// explicitly show diffif (err.showDiff && sameType(actual, expected)) {@@ -2337,7 +2352,7 @@ function unifiedDiff(err, escape) {function notBlank(line) {return line != null;}- msg = diff.createPatch('string', err.actual, err.expected);+ var msg = diff.createPatch('string', err.actual, err.expected);var lines = msg.split('\n').splice(4);return '\n '+ colorLines('diff added', '+ expected') + ' '@@ -2785,6 +2800,12 @@ function HTML(runner) {*/var makeUrl = 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(s);};@@ -4245,6 +4266,7 @@ require.register("runnable.js", function(module, exports, require){var EventEmitter = require('browser/events').EventEmitter, debug = require('browser/debug')('mocha:runnable')+ , Pending = require('./pending'), milliseconds = require('./ms'), utils = require('./utils');@@ -4349,6 +4371,16 @@ Runnable.prototype.enableTimeouts = function(enabled){return this;};+/**+ * Halt and mark as pending.+ *+ * @api private+ */++Runnable.prototype.skip = function(){+ throw new Pending();+};+/*** Return the full title generated by recursively* concatenating the parent's full title.@@ -4518,10 +4550,13 @@ require.register("runner.js", function(module, exports, require){var EventEmitter = require('browser/events').EventEmitter, debug = require('browser/debug')('mocha:runner')+ , Pending = require('./pending'), Test = require('./test'), utils = require('./utils'), filter = utils.filter- , keys = utils.keys;+ , keys = utils.keys+ , type = utils.type+ , stringify = utils.stringify;/*** Non-enumerable globals.@@ -4714,6 +4749,8 @@ Runner.prototype.fail = function(test, err){if ('string' == typeof err) {err = new Error('the string "' + err + '" was thrown, throw an Error :)');+ } else if (!(err instanceof Error)) {+ err = new Error('the ' + type(err) + ' ' + stringify(err) + ' was thrown, throw an Error :)');}this.emit('fail', test, err);@@ -4779,10 +4816,14 @@ Runner.prototype.hook = function(name, fn){var testError = hook.error();if (testError) self.fail(self.test, testError);if (err) {- self.failHook(hook, err);+ if (err instanceof Pending) {+ suite.pending = true;+ } else {+ self.failHook(hook, err);- // stop executing hooks, notify callee of hook err- return fn(err);+ // stop executing hooks, notify callee of hook err+ return fn(err);+ }}self.emit('hook end', hook);delete hook.ctx.currentTest;@@ -4964,6 +5005,11 @@ Runner.prototype.runTests = function(suite, fn){self.emit('test', self.test = test);self.hookDown('beforeEach', function(err, errSuite){+ if (suite.pending) {+ self.emit('pending', test);+ self.emit('test end', test);+ return next();+ }if (err) return hookErr(err, errSuite, false);self.currentRunnable = self.test;@@ -4971,8 +5017,17 @@ Runner.prototype.runTests = function(suite, fn){test = self.test;if (err) {- self.fail(test, err);+ if (err instanceof Pending) {+ self.emit('pending', test);+ } else {+ self.fail(test, err);+ }self.emit('test end', test);++ if (err instanceof Pending) {+ return next();+ }+return self.hookUp('afterEach', next);}@@ -5646,7 +5701,7 @@ exports.forEach = function(arr, fn, scope){exports.map = function(arr, fn, scope){var result = [];for (var i = 0, l = arr.length; i < l; i++)- result.push(fn.call(scope, arr[i], i));+ result.push(fn.call(scope, arr[i], i, arr));return result;};@@ -5715,7 +5770,7 @@ exports.filter = function(arr, fn){exports.keys = Object.keys || function(obj) {var keys = []- , has = Object.prototype.hasOwnProperty // for `window` on <=IE8+ , has = Object.prototype.hasOwnProperty; // for `window` on <=IE8for (var key in obj) {if (has.call(obj, key)) {@@ -5745,6 +5800,26 @@ exports.watch = function(files, fn){});};+/**+ * Array.isArray (<=IE8)+ *+ * @param {Object} obj+ * @return {Boolean}+ * @api private+ */+var isArray = Array.isArray || function (obj) {+ return '[object Array]' == {}.toString.call(obj);+};++/**+ * @description+ * Buffer.prototype.toJSON polyfill+ * @type {Function}+ */+Buffer.prototype.toJSON = Buffer.prototype.toJSON || function () {+ return Array.prototype.slice.call(this, 0);+};+/*** Ignored files.*/@@ -5767,15 +5842,15 @@ exports.files = function(dir, ext, ret){var re = new RegExp('\\.(' + ext.join('|') + ')$');fs.readdirSync(dir)- .filter(ignored)- .forEach(function(path){- path = join(dir, path);- if (fs.statSync(path).isDirectory()) {- exports.files(path, ext, ret);- } else if (path.match(re)) {- ret.push(path);- }- });+ .filter(ignored)+ .forEach(function(path){+ path = join(dir, path);+ if (fs.statSync(path).isDirectory()) {+ exports.files(path, ext, ret);+ } else if (path.match(re)) {+ ret.push(path);+ }+ });return ret;};@@ -5952,30 +6027,94 @@ exports.type = function type(value) {*/exports.stringify = function(value) {- var prop,- type = exports.type(value);-- if (type === 'null' || type === 'undefined') {- return '[' + type + ']';- }-- if (type === 'date') {- return '[Date: ' + value.toISOString() + ']';- }+ var type = exports.type(value);if (!~exports.indexOf(['object', 'array', 'function'], type)) {- return value.toString();+ if(type != 'buffer') {+ return jsonStringify(value);+ }+ var json = value.toJSON();+ // Based on the toJSON result+ return jsonStringify(json.data && json.type ? json.data : json, 2)+ .replace(/,(\n|$)/g, '$1');}- for (prop in value) {+ for (var prop in value) {if (Object.prototype.hasOwnProperty.call(value, prop)) {- return JSON.stringify(exports.canonicalize(value), null, 2).replace(/,(\n|$)/g, '$1');+ return jsonStringify(exports.canonicalize(value), 2).replace(/,(\n|$)/g, '$1');}}return emptyRepresentation(value, type);};+/**+ * @description+ * like JSON.stringify but more sense.+ * @param {Object} object+ * @param {Number=} spaces+ * @param {number=} depth+ * @returns {*}+ * @private+ */+function jsonStringify(object, spaces, depth) {+ if(typeof spaces == 'undefined') return _stringify(object); // primitive types++ depth = depth || 1;+ var space = spaces * depth+ , str = isArray(object) ? '[' : '{'+ , end = isArray(object) ? ']' : '}'+ , length = object.length || exports.keys(object).length+ , repeat = function(s, n) { return new Array(n).join(s); }; // `.repeat()` polyfill++ function _stringify(val) {+ switch (exports.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 'number':+ val = val === 0 && (1/val) === -Infinity // `-0`+ ? '-0'+ : val.toString();+ break;+ case 'date':+ val = '[Date: ' + val.toISOString() + ']';+ 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+ : '"' + val + '"'; //string+ }+ return val;+ }++ for(var i in object) {+ if(!object.hasOwnProperty(i)) continue; // not my business+ --length;+ str += '\n ' + repeat(' ', space)+ + (isArray(object) ? '' : '"' + i + '": ') // key+ + _stringify(object[i]) // value+ + (length ? ',' : ''); // comma+ }++ return str + (str.length != 1 // [], {}+ ? '\n' + repeat(' ', --space) + end+ : end);+}+/*** Return if obj is a Buffer* @param {Object} arg@@ -6022,8 +6161,6 @@ exports.canonicalize = function(value, stack) {switch(type) {case 'undefined':- canonicalizedObj = '[undefined]';- break;case 'buffer':case 'null':canonicalizedObj = value;@@ -6035,9 +6172,6 @@ exports.canonicalize = function(value, stack) {});});break;- case 'date':- canonicalizedObj = '[Date: ' + value.toISOString() + ']';- break;case 'function':for (prop in value) {canonicalizedObj = {};@@ -6056,7 +6190,9 @@ exports.canonicalize = function(value, stack) {});});break;+ case 'date':case 'number':+ case 'regexp':case 'boolean':canonicalizedObj = value;break;