☕️ Classic, reliable, trusted test framework for Node.js and the browser
build
TJ Holowaychuk741808236efb
diff --git a/mocha.js b/mocha.jsindex 408c3dd4..dee24d69 100644--- a/mocha.js+++ b/mocha.js@@ -1,6 +1,5 @@;(function(){-// CommonJS require()function require(p){@@ -32,11 +31,11 @@ require.register = function (path, fn){require.relative = function (parent) {return function(p){if ('.' != p.charAt(0)) return require(p);-+var path = parent.split('/'), segs = p.split('/');path.pop();-+for (var i = 0; i < segs.length; i++) {var seg = segs[i];if ('..' == seg) path.pop();@@ -52,9 +51,9 @@ require.register("browser/debug.js", function(module, exports, require){module.exports = function(type){return function(){-}};+}); // module: browser/debug.jsrequire.register("browser/diff.js", function(module, exports, require){@@ -805,7 +804,6 @@ Hook.prototype.error = function(err){this._error = err;};-}); // module: hook.jsrequire.register("interfaces/bdd.js", function(module, exports, require){@@ -819,7 +817,7 @@ var Suite = require('../suite')/*** BDD-style interface:- *+ ** describe('Array', function(){* describe('#indexOf()', function(){* it('should return -1 when not present', function(){@@ -831,7 +829,7 @@ var Suite = require('../suite')* });* });* });- *+ **/module.exports = function(suite){@@ -876,7 +874,7 @@ module.exports = function(suite){* and callback `fn` containing nested suites* and/or tests.*/-+context.describe = context.context = function(title, fn){var suite = Suite.create(suites[0], title);suites.unshift(suite);@@ -956,19 +954,19 @@ var Suite = require('../suite')/*** TDD-style 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(){- *+ ** }* }* };- *+ **/module.exports = function(suite){@@ -1006,6 +1004,7 @@ module.exports = function(suite){}}};+}); // module: interfaces/exports.jsrequire.register("interfaces/index.js", function(module, exports, require){@@ -1028,27 +1027,27 @@ var Suite = require('../suite')/*** 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);* });- *+ **/module.exports = function(suite){@@ -1091,7 +1090,7 @@ module.exports = function(suite){/*** Describe a "suite" with the given `title`.*/-+context.suite = function(title){if (suites.length > 1) suites.shift();var suite = Suite.create(suites[0], title);@@ -1129,7 +1128,7 @@ var Suite = require('../suite')* suiteSetup(function(){** });- *+ ** test('should return -1 when not present', function(){** });@@ -1549,7 +1548,7 @@ Mocha.prototype.run = function(fn){var options = this.options;var runner = new exports.Runner(suite);var reporter = new this._reporter(runner);- runner.ignoreLeaks = options.ignoreLeaks;+ runner.ignoreLeaks = false !== options.ignoreLeaks;runner.asyncOnly = options.asyncOnly;if (options.grep) runner.grep(options.grep, options.invert);if (options.globals) runner.globals(options.globals);@@ -1710,7 +1709,7 @@ exports.colors = {/*** Default symbol map.*/-+exports.symbols = {ok: '✓',err: '✖',@@ -2334,8 +2333,6 @@ function HTML(runner, root) {});runner.on('test end', function(test){- window.scrollTo(0, document.body.scrollHeight);-// TODO: add to statsvar percent = stats.tests / this.total * 100 | 0;if (progress) progress.update(percent).draw(ctx);@@ -3080,7 +3077,7 @@ exports = module.exports = Min;function Min(runner) {Base.call(this, runner);-+runner.on('start', function(){// clear screenprocess.stdout.write('\u001b[2J');@@ -3100,10 +3097,10 @@ F.prototype = Base.prototype;Min.prototype = new F;Min.prototype.constructor = Min;+}); // module: reporters/min.jsrequire.register("reporters/nyan.js", function(module, exports, require){-/*** Module dependencies.*/@@ -3249,44 +3246,39 @@ NyanCat.prototype.drawRainbow = function(){NyanCat.prototype.drawNyanCat = function(status) {var self = this;var startWidth = this.scoreboardWidth + this.trajectories[0].length;-- [0, 1, 2, 3].forEach(function(index) {- write('\u001b[' + startWidth + 'C');-- switch (index) {- case 0:- write('_,------,');- write('\n');- break;- case 1:- var padding = self.tick ? ' ' : ' ';- write('_|' + padding + '/\\_/\\ ');- write('\n');- break;- case 2:- var padding = self.tick ? '_' : '__';- var tail = self.tick ? '~' : '^';- var face;- switch (status) {- case 'pass':- face = '( ^ .^)';- break;- case 'fail':- face = '( o .o)';- break;- default:- face = '( - .-)';- }- write(tail + '|' + padding + face + ' ');- write('\n');- break;- case 3:- var padding = self.tick ? ' ' : ' ';- write(padding + '"" "" ');- write('\n');- break;- }- });+ var color = '\u001b[' + startWidth + 'C';+ var padding = '';++ write(color);+ write('_,------,');+ write('\n');++ write(color);+ padding = self.tick ? ' ' : ' ';+ write('_|' + padding + '/\\_/\\ ');+ write('\n');++ write(color);+ padding = self.tick ? '_' : '__';+ var tail = self.tick ? '~' : '^';+ var face;+ switch (status) {+ case 'pass':+ face = '( ^ .^)';+ break;+ case 'fail':+ face = '( o .o)';+ break;+ default:+ face = '( - .-)';+ }+ write(tail + '|' + padding + face + ' ');+ write('\n');++ write(color);+ padding = self.tick ? ' ' : ' ';+ write(padding + '"" "" ');+ write('\n');this.cursorUp(this.numberOfLines);};@@ -3746,7 +3738,7 @@ function XUnit(runner) {runner.on('pass', function(test){tests.push(test);});-+runner.on('fail', function(test){tests.push(test);});@@ -3763,7 +3755,7 @@ function XUnit(runner) {}, false));tests.forEach(test);- console.log('</testsuite>');+ console.log('</testsuite>');});}@@ -4065,9 +4057,7 @@ var EventEmitter = require('browser/events').EventEmitter, Test = require('./test'), utils = require('./utils'), filter = utils.filter- , keys = utils.keys- , noop = function(){}- , immediately = global.setImmediate || process.nextTick;+ , keys = utils.keys;/*** Non-enumerable globals.@@ -4119,6 +4109,15 @@ function Runner(suite) {this.globals(this.globalProps().concat(['errno']));}+/**+ * Wrapper for setImmediate, process.nextTick, or browser polyfill.+ *+ * @param {Function} fn+ * @api private+ */++Runner.immediately = global.setImmediate || process.nextTick;+/*** Inherit from `EventEmitter.prototype`.*/@@ -4304,7 +4303,7 @@ Runner.prototype.hook = function(name, fn){});}- immediately(function(){+ Runner.immediately(function(){next(0);});};@@ -5006,7 +5005,7 @@ exports.indexOf = function(arr, obj, start){/*** Array#reduce (<=IE8)- *+ ** @param {Array} array* @param {Function} fn* @param {Object} initial value@@ -5239,34 +5238,6 @@ process.exit = function(status){};process.stdout = {};global = window;-/**- * next tick implementation.- */--process.nextTick = (function(){- // postMessage behaves badly on IE8- if (window.ActiveXObject || !window.postMessage) {- return function(fn){ fn() };- }-- // based on setZeroTimeout by David Baron- // - http://dbaron.org/log/20100309-faster-timeouts- var timeouts = []- , name = 'mocha-zero-timeout'-- window.addEventListener('message', function(e){- if (e.source == window && e.data == name) {- if (e.stopPropagation) e.stopPropagation();- if (timeouts.length) timeouts.shift()();- }- }, true);-- return function(fn){- timeouts.push(fn);- window.postMessage(name, '*');- }-})();-/*** Remove uncaughtException listener.*/@@ -5299,6 +5270,32 @@ process.on = function(e, fn){var Mocha = window.Mocha = require('mocha'),mocha = window.mocha = new Mocha({ reporter: 'html' });+ var immediateQueue = []+ , 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);+ }+ };+/*** Override ui to ensure that the ui functions are initialized.* Normally this would happen in Mocha.prototype.loadFiles.diff --git a/test/browser/array.js b/test/browser/array.jsindex a8a709c0..26404f6a 100644--- a/test/browser/array.js+++ b/test/browser/array.js@@ -1,6 +1,7 @@describe('Array', function(){describe('#push()', function(){it('should append a value', function(){+ foo = 'asdf'var arr = [];arr.push('foo');arr.push('bar');diff --git a/test/browser/index.html b/test/browser/index.htmlindex 7663f6a5..f10732dd 100644--- a/test/browser/index.html+++ b/test/browser/index.html@@ -16,8 +16,9 @@<script src="../acceptance/timeout.js"></script><script>onload = function(){+ mocha.checkLeaks();+ mocha.globals(['foo']);var runner = mocha.run();- runner.globals(['foo', 'bar', 'baz']);// runner.on('test end', function(test){// console.log(test.fullTitle());