Comparing version 1.6.0 to 1.7.0
1.7.0 / 2012-11-07 | ||
================== | ||
* add `--async-only` support to prevent false positives for missing `done()` | ||
* add sorting by filename in code coverage | ||
* add HTML 5 doctype to browser template. | ||
* add play button to html reporter to rerun a single test | ||
* add `this.timeout(ms)` as Suite#timeout(ms). Closes #599 | ||
* update growl dependency to 1.6.x | ||
* fix encoding of test-case ?grep. Closes #637 | ||
* fix unicode chars on windows | ||
* fix dom globals in Opera/IE. Closes #243 | ||
* fix markdown reporter a tags | ||
* fix `this.timeout("5s")` support | ||
1.6.0 / 2012-10-02 | ||
@@ -3,0 +18,0 @@ ================== |
@@ -72,3 +72,3 @@ | ||
suites.unshift(suite); | ||
fn(); | ||
fn.call(suite); | ||
suites.shift(); | ||
@@ -88,3 +88,3 @@ return suite; | ||
suites.unshift(suite); | ||
fn(); | ||
fn.call(suite); | ||
suites.shift(); | ||
@@ -91,0 +91,0 @@ }; |
@@ -80,3 +80,3 @@ | ||
suites.unshift(suite); | ||
fn(); | ||
fn.call(suite); | ||
suites.shift(); | ||
@@ -115,3 +115,11 @@ return suite; | ||
}; | ||
/** | ||
* Pending test case. | ||
*/ | ||
context.test.skip = function(title){ | ||
context.test(title); | ||
}; | ||
}); | ||
}; |
@@ -270,2 +270,14 @@ /*! | ||
/** | ||
* Makes all tests async (accepting a callback) | ||
* | ||
* @return {Mocha} | ||
* @api public | ||
*/ | ||
Mocha.prototype.asyncOnly = function(){ | ||
this.options.asyncOnly = true; | ||
return this; | ||
}; | ||
/** | ||
* Run tests and invoke `fn()` when complete. | ||
@@ -285,2 +297,3 @@ * | ||
runner.ignoreLeaks = options.ignoreLeaks; | ||
runner.asyncOnly = options.asyncOnly; | ||
if (options.grep) runner.grep(options.grep, options.invert); | ||
@@ -287,0 +300,0 @@ if (options.globals) runner.globals(options.globals); |
@@ -72,11 +72,11 @@ | ||
function format(ms) { | ||
if (ms == d) return (ms / d) + ' day'; | ||
if (ms > d) return (ms / d) + ' days'; | ||
if (ms == h) return (ms / h) + ' hour'; | ||
if (ms > h) return (ms / h) + ' hours'; | ||
if (ms == m) return (ms / m) + ' minute'; | ||
if (ms > m) return (ms / m) + ' minutes'; | ||
if (ms == s) return (ms / s) + ' second'; | ||
if (ms > s) return (ms / s) + ' seconds'; | ||
if (ms == d) return Math.round(ms / d) + ' day'; | ||
if (ms > d) return Math.round(ms / d) + ' days'; | ||
if (ms == h) return Math.round(ms / h) + ' hour'; | ||
if (ms > h) return Math.round(ms / h) + ' hours'; | ||
if (ms == m) return Math.round(ms / m) + ' minute'; | ||
if (ms > m) return Math.round(ms / m) + ' minutes'; | ||
if (ms == s) return Math.round(ms / s) + ' second'; | ||
if (ms > s) return Math.round(ms / s) + ' seconds'; | ||
return ms + ' ms'; | ||
} |
@@ -65,2 +65,19 @@ | ||
/** | ||
* Default symbol map. | ||
*/ | ||
exports.symbols = { | ||
ok: '✔', | ||
err: '✖', | ||
dot: '․' | ||
}; | ||
// With node.js on Windows: use symbols available in terminal default fonts | ||
if ('win32' == process.platform) { | ||
exports.symbols.ok = '\u221A'; | ||
exports.symbols.err = '\u00D7'; | ||
exports.symbols.dot = '.'; | ||
} | ||
/** | ||
* Color `str` with the given `type`, | ||
@@ -215,2 +232,4 @@ * allowing colors to be disabled, | ||
runner.stats = stats; | ||
runner.on('start', function(){ | ||
@@ -280,3 +299,3 @@ stats.start = new Date; | ||
if (stats.failures) { | ||
fmt = color('bright fail', ' ✖') | ||
fmt = color('bright fail', ' ' + exports.symbols.err) | ||
+ color('fail', ' %d of %d %s failed') | ||
@@ -296,3 +315,3 @@ + color('light', ':') | ||
// pass | ||
fmt = color('bright pass', ' ✔') | ||
fmt = color('bright pass', ' ' + exports.symbols.ok) | ||
+ color('green', ' %d %s complete') | ||
@@ -299,0 +318,0 @@ + color('light', ' (%s)'); |
@@ -39,3 +39,3 @@ | ||
++indents; | ||
console.log('%s<h1>%s</h1>', indent(), suite.title); | ||
console.log('%s<h1>%s</h1>', indent(), utils.escape(suite.title)); | ||
console.log('%s<dl>', indent()); | ||
@@ -53,3 +53,3 @@ }); | ||
runner.on('pass', function(test){ | ||
console.log('%s <dt>%s</dt>', indent(), test.title); | ||
console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title)); | ||
var code = utils.escape(utils.clean(test.fn.toString())); | ||
@@ -56,0 +56,0 @@ console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code); |
@@ -28,3 +28,2 @@ | ||
, width = Base.window.width * .75 | 0 | ||
, c = '․' | ||
, n = 0; | ||
@@ -37,3 +36,3 @@ | ||
runner.on('pending', function(test){ | ||
process.stdout.write(color('pending', c)); | ||
process.stdout.write(color('pending', Base.symbols.dot)); | ||
}); | ||
@@ -44,5 +43,5 @@ | ||
if ('slow' == test.speed) { | ||
process.stdout.write(color('bright yellow', c)); | ||
process.stdout.write(color('bright yellow', Base.symbols.dot)); | ||
} else { | ||
process.stdout.write(color(test.speed, c)); | ||
process.stdout.write(color(test.speed, Base.symbols.dot)); | ||
} | ||
@@ -53,3 +52,3 @@ }); | ||
if (++n % width == 0) process.stdout.write('\n '); | ||
process.stdout.write(color('fail', c)); | ||
process.stdout.write(color('fail', Base.symbols.dot)); | ||
}); | ||
@@ -56,0 +55,0 @@ |
@@ -31,3 +31,3 @@ | ||
var statsTemplate = '<ul id="stats">' | ||
var statsTemplate = '<ul id="mocha-stats">' | ||
+ '<li class="progress"><canvas width="40" height="40"></canvas></li>' | ||
@@ -60,3 +60,3 @@ + '<li class="passes"><a href="#">passes:</a> <em>0</em></li>' | ||
, canvas = stat.getElementsByTagName('canvas')[0] | ||
, report = fragment('<ul id="report"></ul>') | ||
, report = fragment('<ul id="mocha-report"></ul>') | ||
, stack = [report] | ||
@@ -128,3 +128,3 @@ , progress | ||
// TODO: add to stats | ||
var percent = stats.tests / total * 100 | 0; | ||
var percent = stats.tests / this.total * 100 | 0; | ||
if (progress) progress.update(percent).draw(ctx); | ||
@@ -140,7 +140,7 @@ | ||
if ('passed' == test.state) { | ||
var el = fragment('<li class="test pass %e"><h2>%e<span class="duration">%ems</span></h2></li>', test.speed, test.title, test.duration); | ||
var el = fragment('<li class="test pass %e"><h2>%e<span class="duration">%ems</span> <a href="?grep=%e" class="replay">‣</a></h2></li>', test.speed, test.title, test.duration, encodeURIComponent(test.fullTitle())); | ||
} else if (test.pending) { | ||
var el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title); | ||
} else { | ||
var el = fragment('<li class="test fail"><h2>%e</h2></li>', test.title); | ||
var el = fragment('<li class="test fail"><h2>%e <a href="?grep=%e" class="replay">‣</a></h2></li>', test.title, encodeURIComponent(test.fullTitle())); | ||
var str = test.err.stack || test.err.toString(); | ||
@@ -181,3 +181,4 @@ | ||
stack[0].appendChild(el); | ||
// Don't call .appendChild if #mocha-report was already .shift()'ed off the stack. | ||
if (stack[0]) stack[0].appendChild(el); | ||
}); | ||
@@ -191,3 +192,3 @@ } | ||
function error(msg) { | ||
document.body.appendChild(fragment('<div id="error">%s</div>', msg)); | ||
document.body.appendChild(fragment('<div id="mocha-error">%s</div>', msg)); | ||
} | ||
@@ -194,0 +195,0 @@ |
@@ -83,2 +83,6 @@ | ||
ret.files.sort(function(a, b) { | ||
return a.filename.localeCompare(b.filename); | ||
}); | ||
if (ret.sloc > 0) { | ||
@@ -85,0 +89,0 @@ ret.coverage = (ret.hits / ret.sloc) * 100; |
@@ -45,3 +45,3 @@ | ||
runner.on('pass', function(test){ | ||
var fmt = color('checkmark', ' ✓') | ||
var fmt = color('checkmark', ' '+Base.symbols.dot) | ||
+ color('pass', ' %s: ') | ||
@@ -48,0 +48,0 @@ + color(test.speed, '%dms'); |
@@ -71,3 +71,3 @@ /** | ||
var slug = utils.slug(suite.fullTitle()); | ||
buf += '<a name="' + slug + '" />' + '\n'; | ||
buf += '<a name="' + slug + '"></a>' + '\n'; | ||
buf += title(suite.title) + '\n'; | ||
@@ -74,0 +74,0 @@ }); |
@@ -44,3 +44,3 @@ | ||
options.complete = options.complete || '▬'; | ||
options.incomplete = options.incomplete || '⋅'; | ||
options.incomplete = options.incomplete || Base.symbols.dot; | ||
options.close = options.close || ']'; | ||
@@ -47,0 +47,0 @@ options.verbose = false; |
@@ -61,3 +61,3 @@ | ||
var fmt = indent() | ||
+ color('checkmark', ' ✓') | ||
+ color('checkmark', ' ' + Base.symbols.ok) | ||
+ color('pass', ' %s '); | ||
@@ -68,3 +68,3 @@ cursor.CR(); | ||
var fmt = indent() | ||
+ color('checkmark', ' ✓') | ||
+ color('checkmark', ' ' + Base.symbols.ok) | ||
+ color('pass', ' %s ') | ||
@@ -71,0 +71,0 @@ + color(test.speed, '(%dms)'); |
@@ -7,3 +7,4 @@ | ||
var EventEmitter = require('events').EventEmitter | ||
, debug = require('debug')('mocha:runnable'); | ||
, debug = require('debug')('mocha:runnable') | ||
, milliseconds = require('./ms'); | ||
@@ -53,3 +54,3 @@ /** | ||
* | ||
* @param {Number} ms | ||
* @param {Number|String} ms | ||
* @return {Runnable|Number} ms or self | ||
@@ -61,2 +62,3 @@ * @api private | ||
if (0 == arguments.length) return this._timeout; | ||
if ('string' == typeof ms) ms = milliseconds(ms); | ||
debug('timeout %d', ms); | ||
@@ -71,3 +73,3 @@ this._timeout = ms; | ||
* | ||
* @param {Number} ms | ||
* @param {Number|String} ms | ||
* @return {Runnable|Number} ms or self | ||
@@ -79,2 +81,3 @@ * @api private | ||
if (0 === arguments.length) return this._slow; | ||
if ('string' == typeof ms) ms = milliseconds(ms); | ||
debug('timeout %d', ms); | ||
@@ -202,3 +205,7 @@ this._slow = ms; | ||
} | ||
if (this.asyncOnly) { | ||
return done(new Error('--async-only option in use without declaring `done()`')); | ||
} | ||
// sync | ||
@@ -205,0 +212,0 @@ try { |
@@ -15,2 +15,15 @@ | ||
/** | ||
* Non-enumerable globals. | ||
*/ | ||
var globals = [ | ||
'setTimeout', | ||
'clearTimeout', | ||
'setInterval', | ||
'clearInterval', | ||
'XMLHttpRequest', | ||
'Date' | ||
]; | ||
/** | ||
* Expose `Runner`. | ||
@@ -49,3 +62,3 @@ */ | ||
this.grep(/.*/); | ||
this.globals(utils.keys(global).concat(['errno'])); | ||
this.globals(this.globalProps().concat(['errno'])); | ||
} | ||
@@ -100,2 +113,21 @@ | ||
/** | ||
* Return a list of global properties. | ||
* | ||
* @return {Array} | ||
* @api private | ||
*/ | ||
Runner.prototype.globalProps = function() { | ||
var props = utils.keys(global); | ||
// non-enumerables | ||
for (var i = 0; i < globals.length; ++i) { | ||
if (~props.indexOf(globals[i])) continue; | ||
props.push(globals[i]); | ||
} | ||
return props; | ||
}; | ||
/** | ||
* Allow the given `arr` of globals. | ||
@@ -126,3 +158,3 @@ * | ||
var ok = this._globals; | ||
var globals = keys(global); | ||
var globals = this.globalProps(); | ||
var isNode = process.kill; | ||
@@ -307,2 +339,4 @@ var leaks; | ||
if (this.asyncOnly) test.asyncOnly = true; | ||
try { | ||
@@ -329,3 +363,3 @@ test.on('error', function(err){ | ||
var self = this | ||
, tests = suite.tests | ||
, tests = suite.tests.slice() | ||
, test; | ||
@@ -498,2 +532,4 @@ | ||
if (~ok.indexOf('*')) return 0 == key.indexOf(ok.split('*')[0]); | ||
// Opera and IE expose global variables for HTML element IDs (issue #243) | ||
if (/^mocha-/.test(key)) return true; | ||
return key == ok; | ||
@@ -500,0 +536,0 @@ }); |
{ | ||
"name": "mocha" | ||
, "version": "1.6.0" | ||
, "version": "1.7.0" | ||
, "description": "simple, flexible, fun test framework" | ||
@@ -16,3 +16,3 @@ , "keywords": ["test", "bdd", "tdd", "tap"] | ||
"commander": "0.6.1" | ||
, "growl": "1.5.x" | ||
, "growl": "1.6.x" | ||
, "jade": "0.26.3" | ||
@@ -19,0 +19,0 @@ , "diff": "1.0.2" |
@@ -38,2 +38,3 @@ [![Build Status](https://secure.travis-ci.org/visionmedia/mocha.png)](http://travis-ci.org/visionmedia/mocha) | ||
- [Konacha](https://github.com/jfirebaugh/konacha) -- for testing Rails applications with Mocha | ||
- [Chai](https://github.com/chaijs/chai) - BDD, TDD, and assert for node & the browser | ||
@@ -40,0 +41,0 @@ - [Should.js](http://github.com/visionmedia/should.js) - BDD style assertions for node |
18
test.js
describe('test', function(){ | ||
it('should work with objects', function(){ | ||
var a = { name: 'tobi', age: 2, species: 'ferret' }; | ||
var b = { name: 'jane', age: 8, species: 'ferret' }; | ||
a.should.eql(b); | ||
describe('foo', function(){ | ||
before(function(){ | ||
console.log('foo'); | ||
}) | ||
it('should work with arrays', function(){ | ||
var a = [1,2,{ name: 'tobi' },4,5] | ||
var b = [1,2,{ name: 'jane' },4,4, 'extra stuff', 'more extra'] | ||
a.should.eql(b); | ||
it('should bar', function(){ | ||
}) | ||
it('should work with strings', function(){ | ||
'some\nfoo\nbar'.should.equal('some\nbar\nbaz'); | ||
}) | ||
}) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
345376
12047
42
+ Addedgrowl@1.6.1(transitive)
- Removedgrowl@1.5.1(transitive)
Updatedgrowl@1.6.x