vendor/node_modules/mocha/mocha.js in stylus-source-0.28.2 vs vendor/node_modules/mocha/mocha.js in stylus-source-0.29.0

- old
+ new

@@ -535,15 +535,10 @@ module.exports = function(suite){ var suites = [suite]; suite.on('pre-require', function(context){ - // noop variants - - context.xdescribe = function(){}; - context.xit = function(){}; - /** * Execute before running tests. */ context.before = function(fn){ @@ -573,10 +568,22 @@ context.afterEach = function(fn){ suites[0].afterEach(fn); }; /** + * Pending describe. + */ + + context.xdescribe = context.xcontext = function(title, fn){ + var suite = Suite.create(suites[0], title); + suite.pending = true; + suites.unshift(suite); + fn(); + suites.shift(); + }; + + /** * Describe a "suite" with the given `title` * and callback `fn` containing nested suites * and/or tests. */ @@ -592,12 +599,22 @@ * with the given `title` and callback `fn` * acting as a thunk. */ context.it = context.specify = function(title, fn){ - suites[0].addTest(new Test(title, fn)); + var suite = suites[0]; + if (suite.pending) var fn = null; + suite.addTest(new Test(title, fn)); }; + + /** + * Pending test case. + */ + + context.xit = context.xspecify = function(title){ + context.it(title); + }; }); }; }); // module: interfaces/bdd.js @@ -983,27 +1000,29 @@ * Load registered files. * * @api private */ -Mocha.prototype.loadFiles = function(){ +Mocha.prototype.loadFiles = function(fn){ var suite = this.suite; + var pending = this.files.length; this.files.forEach(function(file){ file = path.resolve(file); suite.emit('pre-require', global, file); suite.emit('require', require(file), file); suite.emit('post-require', global, file); + --pending || (fn && fn()); }); }; /** * Enable growl support. * * @api private */ -Mocha.prototype.growl = function(runner, reporter) { +Mocha.prototype._growl = function(runner, reporter) { var notify = require('growl'); runner.on('end', function(){ var stats = reporter.stats; if (stats.failures) { @@ -1033,10 +1052,59 @@ : re; return this; }; /** + * Invert `.grep()` matches. + * + * @return {Mocha} + * @api public + */ + +Mocha.prototype.invert = function(){ + this.options.invert = true; + return this; +}; + +/** + * Ignore global leaks. + * + * @return {Mocha} + * @api public + */ + +Mocha.prototype.ignoreLeaks = function(){ + this.options.ignoreLeaks = true; + return this; +}; + +/** + * Enable growl support. + * + * @return {Mocha} + * @api public + */ + +Mocha.prototype.growl = function(){ + this.options.growl = true; + return this; +}; + +/** + * Ignore `globals`. + * + * @param {Array} globals + * @return {Mocha} + * @api public + */ + +Mocha.prototype.globals = function(globals){ + this.options.globals = globals; + return this; +}; + +/** * Run tests and invoke `fn()` when complete. * * @param {Function} fn * @return {Runner} * @api public @@ -1047,13 +1115,13 @@ var suite = this.suite; var options = this.options; var runner = new exports.Runner(suite); var reporter = new this._reporter(runner); runner.ignoreLeaks = options.ignoreLeaks; - if (options.grep) runner.grep(options.grep); + if (options.grep) runner.grep(options.grep, options.invert); if (options.globals) runner.globals(options.globals); - if (options.growl) this.growl(runner, reporter); + if (options.growl) this._growl(runner, reporter); return runner.run(fn); }; }); // module: mocha.js @@ -1132,11 +1200,11 @@ * @api private */ var color = exports.color = function(type, str) { if (!exports.useColors) return str; - return '\033[' + exports.colors[type] + 'm' + str + '\033[0m'; + return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m'; }; /** * Expose term window size, with some * defaults for when stderr is not a tty. @@ -1155,23 +1223,23 @@ * that are common among reporters. */ exports.cursor = { hide: function(){ - process.stdout.write('\033[?25l'); + process.stdout.write('\u001b[?25l'); }, show: function(){ - process.stdout.write('\033[?25h'); + process.stdout.write('\u001b[?25h'); }, deleteLine: function(){ - process.stdout.write('\033[2K'); + process.stdout.write('\u001b[2K'); }, beginningOfLine: function(){ - process.stdout.write('\033[0G'); + process.stdout.write('\u001b[0G'); }, CR: function(){ exports.cursor.deleteLine(); exports.cursor.beginningOfLine(); @@ -1502,32 +1570,33 @@ Base.call(this, runner); var self = this , stats = this.stats , width = Base.window.width * .75 | 0 + , c = '․' , n = 0; runner.on('start', function(){ process.stdout.write('\n '); }); runner.on('pending', function(test){ - process.stdout.write(color('pending', '.')); + process.stdout.write(color('pending', c)); }); runner.on('pass', function(test){ if (++n % width == 0) process.stdout.write('\n '); if ('slow' == test.speed) { - process.stdout.write(color('bright yellow', '.')); + process.stdout.write(color('bright yellow', c)); } else { - process.stdout.write(color(test.speed, '.')); + process.stdout.write(color(test.speed, c)); } }); runner.on('fail', function(test, err){ if (++n % width == 0) process.stdout.write('\n '); - process.stdout.write(color('fail', '.')); + process.stdout.write(color('fail', c)); }); runner.on('end', function(){ console.log(); self.epilogue(); @@ -1628,12 +1697,12 @@ * Stats template. */ var statsTemplate = '<ul id="stats">' + '<li class="progress"><canvas width="40" height="40"></canvas></li>' - + '<li class="passes">passes: <em>0</em></li>' - + '<li class="failures">failures: <em>0</em></li>' + + '<li class="passes"><a href="#">passes:</a> <em>0</em></li>' + + '<li class="failures"><a href="#">failures:</a> <em>0</em></li>' + '<li class="duration">duration: <em>0</em>s</li>' + '</ul>'; /** * Initialize a new `Doc` reporter. @@ -1650,11 +1719,13 @@ , total = runner.total , root = document.getElementById('mocha') , stat = fragment(statsTemplate) , items = stat.getElementsByTagName('li') , passes = items[1].getElementsByTagName('em')[0] + , passesLink = items[1].getElementsByTagName('a')[0] , failures = items[2].getElementsByTagName('em')[0] + , failuresLink = items[2].getElementsByTagName('a')[0] , duration = items[3].getElementsByTagName('em')[0] , canvas = stat.getElementsByTagName('canvas')[0] , report = fragment('<ul id="report"></ul>') , stack = [report] , progress @@ -1665,10 +1736,22 @@ progress = new Progress; } if (!root) return error('#mocha div missing, add it to your document'); + // pass toggle + on(passesLink, 'click', function () { + var className = /pass/.test(report.className) ? '' : ' pass'; + report.className = report.className.replace(/fail|pass/g, '') + className; + }); + + // failure toggle + on(failuresLink, 'click', function () { + var className = /fail/.test(report.className) ? '' : ' fail'; + report.className = report.className.replace(/fail|pass/g, '') + className; + }); + root.appendChild(stat); root.appendChild(report); if (progress) progress.size(40); @@ -1732,21 +1815,20 @@ el.appendChild(fragment('<pre class="error">%e</pre>', str)); } // toggle code - var h2 = el.getElementsByTagName('h2')[0]; - - on(h2, 'click', function(){ - pre.style.display = 'none' == pre.style.display - ? 'block' - : 'none'; - }); - - // code // TODO: defer if (!test.pending) { + var h2 = el.getElementsByTagName('h2')[0]; + + on(h2, 'click', function(){ + pre.style.display = 'none' == pre.style.display + ? 'inline-block' + : 'none'; + }); + var pre = fragment('<pre><code>%e</code></pre>', utils.clean(test.fn.toString())); el.appendChild(pre); pre.style.display = 'none'; } @@ -1802,10 +1884,11 @@ el.addEventListener(event, fn, false); } else { el.attachEvent('on' + event, fn); } } + }); // module: reporters/html.js require.register("reporters/index.js", function(module, exports, require){ exports.Base = require('./base'); @@ -2192,18 +2275,18 @@ plane = color('plane crash', '✈'); crashed = col; } // render landing strip - stream.write('\033[4F\n\n'); + stream.write('\u001b[4F\n\n'); 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('\033[0m'); + stream.write('\u001b[0m'); }); runner.on('end', function(){ cursor.show(); console.log(); @@ -2409,13 +2492,13 @@ function Min(runner) { Base.call(this, runner); runner.on('start', function(){ // clear screen - process.stdout.write('\033[2J'); + process.stdout.write('\u001b[2J'); // set cursor position - process.stdout.write('\033[1;3H'); + process.stdout.write('\u001b[1;3H'); }); runner.on('end', this.epilogue.bind(this)); } @@ -2516,11 +2599,11 @@ var stats = this.stats; var colors = Base.colors; function draw(color, n) { write(' '); - write('\033[' + color + 'm' + n + '\033[0m'); + write('\u001b[' + color + 'm' + n + '\u001b[0m'); write('\n'); } draw(colors.green, stats.passes); draw(colors.fail, stats.failures); @@ -2555,11 +2638,11 @@ NyanCat.prototype.drawRainbow = function(){ var self = this; this.trajectories.forEach(function(line, index) { - write('\033[' + self.scoreboardWidth + 'C'); + write('\u001b[' + self.scoreboardWidth + 'C'); write(line.join('')); write('\n'); }); this.cursorUp(this.numberOfLines); @@ -2575,11 +2658,11 @@ NyanCat.prototype.drawNyanCat = function(status) { var self = this; var startWidth = this.scoreboardWidth + this.trajectories[0].length; [0, 1, 2, 3].forEach(function(index) { - write('\033[' + startWidth + 'C'); + write('\u001b[' + startWidth + 'C'); switch (index) { case 0: write('_,------,'); write('\n'); @@ -2623,22 +2706,22 @@ * @param {Number} n * @api private */ NyanCat.prototype.cursorUp = function(n) { - write('\033[' + n + 'A'); + write('\u001b[' + n + 'A'); }; /** * Move cursor down `n`. * * @param {Number} n * @api private */ NyanCat.prototype.cursorDown = function(n) { - write('\033[' + n + 'B'); + write('\u001b[' + n + 'B'); }; /** * Generate rainbow colors. * @@ -2670,11 +2753,11 @@ */ NyanCat.prototype.rainbowify = function(str){ var color = this.rainbowColors[this.colorIndex % this.rainbowColors.length]; this.colorIndex += 1; - return '\033[38;5;' + color + 'm' + str + '\033[0m'; + return '\u001b[38;5;' + color + 'm' + str + '\u001b[0m'; }; /** * Stdout helper. */ @@ -2754,11 +2837,11 @@ , percent = complete / total , n = width * percent | 0 , i = width - n; cursor.CR(); - process.stdout.write('\033[J'); + 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) { @@ -3051,13 +3134,17 @@ Base.call(this, runner); var stats = this.stats , tests = [] , self = this; - runner.on('test end', function(test){ + runner.on('pass', function(test){ tests.push(test); }); + + runner.on('fail', function(test){ + tests.push(test); + }); runner.on('end', function(){ console.log(tag('testsuite', { name: 'Mocha Tests' , tests: stats.tests @@ -3136,11 +3223,11 @@ /** * Module dependencies. */ var EventEmitter = require('browser/events').EventEmitter - , debug = require('browser/debug')('runnable'); + , debug = require('browser/debug')('mocha:runnable'); /** * Save timer references to avoid Sinon interfering (see GH-237). */ @@ -3332,11 +3419,11 @@ /** * Module dependencies. */ var EventEmitter = require('browser/events').EventEmitter - , debug = require('browser/debug')('runner') + , debug = require('browser/debug')('mocha:runner') , Test = require('./test') , utils = require('./utils') , filter = utils.filter , keys = utils.keys , noop = function(){}; @@ -3741,13 +3828,13 @@ * @param {Error} err * @api private */ Runner.prototype.uncaught = function(err){ - debug('uncaught exception'); + debug('uncaught exception %s', err.message); var runnable = this.currentRunnable; - if ('failed' == runnable.state) return; + if (!runnable || 'failed' == runnable.state) return; runnable.clearTimeout(); err.uncaught = true; this.fail(runnable, err); // recover from test @@ -3825,11 +3912,11 @@ /** * Module dependencies. */ var EventEmitter = require('browser/events').EventEmitter - , debug = require('browser/debug')('suite') + , debug = require('browser/debug')('mocha:suite') , utils = require('./utils') , Hook = require('./hook'); /** * Expose `Suite`. @@ -3851,10 +3938,11 @@ */ exports.create = function(parent, title){ var suite = new Suite(title, parent.ctx); suite.parent = parent; + if (parent.pending) suite.pending = true; title = suite.fullTitle(); parent.addSuite(suite); return suite; }; @@ -3870,10 +3958,11 @@ function Suite(title, ctx) { this.title = title; this.ctx = ctx; this.suites = []; this.tests = []; + this.pending = false; this._beforeEach = []; this._beforeAll = []; this._afterEach = []; this._afterAll = []; this.root = !title; @@ -3943,10 +4032,11 @@ * @return {Suite} for chaining * @api private */ Suite.prototype.beforeAll = function(fn){ + if (this.pending) return this; var hook = new Hook('"before all" hook', fn); hook.parent = this; hook.timeout(this.timeout()); hook.ctx = this.ctx; this._beforeAll.push(hook); @@ -3961,10 +4051,11 @@ * @return {Suite} for chaining * @api private */ Suite.prototype.afterAll = function(fn){ + if (this.pending) return this; var hook = new Hook('"after all" hook', fn); hook.parent = this; hook.timeout(this.timeout()); hook.ctx = this.ctx; this._afterAll.push(hook); @@ -3979,10 +4070,11 @@ * @return {Suite} for chaining * @api private */ Suite.prototype.beforeEach = function(fn){ + if (this.pending) return this; var hook = new Hook('"before each" hook', fn); hook.parent = this; hook.timeout(this.timeout()); hook.ctx = this.ctx; this._beforeEach.push(hook); @@ -3997,10 +4089,11 @@ * @return {Suite} for chaining * @api private */ Suite.prototype.afterEach = function(fn){ + if (this.pending) return this; var hook = new Hook('"after each" hook', fn); hook.parent = this; hook.timeout(this.timeout()); hook.ctx = this.ctx; this._afterEach.push(hook); @@ -4136,10 +4229,10 @@ */ var fs = require('browser/fs') , path = require('browser/path') , join = path.join - , debug = require('browser/debug')('watch'); + , debug = require('browser/debug')('mocha:watch'); /** * Ignored directories. */ \ No newline at end of file