|
;(function(){ |
|
|
|
|
|
|
|
|
|
function require(p){ |
|
var path = require.resolve(p) |
|
, mod = require.modules[path]; |
|
if (!mod) throw new Error('failed to require "' + p + '"'); |
|
if (!mod.exports) { |
|
mod.exports = {}; |
|
mod.call(mod.exports, mod, mod.exports, require.relative(path)); |
|
} |
|
return mod.exports; |
|
} |
|
|
|
require.modules = {}; |
|
|
|
require.resolve = function (path){ |
|
var orig = path |
|
, reg = path + '.js' |
|
, index = path + '/index.js'; |
|
return require.modules[reg] && reg |
|
|| require.modules[index] && index |
|
|| orig; |
|
}; |
|
|
|
require.register = function (path, fn){ |
|
require.modules[path] = fn; |
|
}; |
|
|
|
require.relative = function (parent) { |
|
return function(p){ |
|
if ('.' != p[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(); |
|
else if ('.' != seg) path.push(seg); |
|
} |
|
|
|
return require(path.join('/')); |
|
}; |
|
}; |
|
|
|
|
|
require.register("browser/debug.js", function(module, exports, require){ |
|
|
|
module.exports = function(type){ |
|
return function(){ |
|
|
|
} |
|
}; |
|
}); |
|
|
|
require.register("browser/events.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
exports.EventEmitter = EventEmitter; |
|
|
|
|
|
|
|
|
|
|
|
function isArray(obj) { |
|
return '[object Array]' == {}.toString.call(obj); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function EventEmitter(){}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EventEmitter.prototype.on = function (name, fn) { |
|
if (!this.$events) { |
|
this.$events = {}; |
|
} |
|
|
|
if (!this.$events[name]) { |
|
this.$events[name] = fn; |
|
} else if (isArray(this.$events[name])) { |
|
this.$events[name].push(fn); |
|
} else { |
|
this.$events[name] = [this.$events[name], fn]; |
|
} |
|
|
|
return this; |
|
}; |
|
|
|
EventEmitter.prototype.addListener = EventEmitter.prototype.on; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EventEmitter.prototype.once = function (name, fn) { |
|
var self = this; |
|
|
|
function on () { |
|
self.removeListener(name, on); |
|
fn.apply(this, arguments); |
|
}; |
|
|
|
on.listener = fn; |
|
this.on(name, on); |
|
|
|
return this; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EventEmitter.prototype.removeListener = function (name, fn) { |
|
if (this.$events && this.$events[name]) { |
|
var list = this.$events[name]; |
|
|
|
if (isArray(list)) { |
|
var pos = -1; |
|
|
|
for (var i = 0, l = list.length; i < l; i++) { |
|
if (list[i] === fn || (list[i].listener && list[i].listener === fn)) { |
|
pos = i; |
|
break; |
|
} |
|
} |
|
|
|
if (pos < 0) { |
|
return this; |
|
} |
|
|
|
list.splice(pos, 1); |
|
|
|
if (!list.length) { |
|
delete this.$events[name]; |
|
} |
|
} else if (list === fn || (list.listener && list.listener === fn)) { |
|
delete this.$events[name]; |
|
} |
|
} |
|
|
|
return this; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EventEmitter.prototype.removeAllListeners = function (name) { |
|
if (name === undefined) { |
|
this.$events = {}; |
|
return this; |
|
} |
|
|
|
if (this.$events && this.$events[name]) { |
|
this.$events[name] = null; |
|
} |
|
|
|
return this; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EventEmitter.prototype.listeners = function (name) { |
|
if (!this.$events) { |
|
this.$events = {}; |
|
} |
|
|
|
if (!this.$events[name]) { |
|
this.$events[name] = []; |
|
} |
|
|
|
if (!isArray(this.$events[name])) { |
|
this.$events[name] = [this.$events[name]]; |
|
} |
|
|
|
return this.$events[name]; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EventEmitter.prototype.emit = function (name) { |
|
if (!this.$events) { |
|
return false; |
|
} |
|
|
|
var handler = this.$events[name]; |
|
|
|
if (!handler) { |
|
return false; |
|
} |
|
|
|
var args = [].slice.call(arguments, 1); |
|
|
|
if ('function' == typeof handler) { |
|
handler.apply(this, args); |
|
} else if (isArray(handler)) { |
|
var listeners = handler.slice(); |
|
|
|
for (var i = 0, l = listeners.length; i < l; i++) { |
|
listeners[i].apply(this, args); |
|
} |
|
} else { |
|
return false; |
|
} |
|
|
|
return true; |
|
}; |
|
}); |
|
|
|
require.register("browser/fs.js", function(module, exports, require){ |
|
|
|
}); |
|
|
|
require.register("browser/progress.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
module.exports = Progress; |
|
|
|
|
|
|
|
|
|
|
|
function Progress() { |
|
this.percent = 0; |
|
this.size(0); |
|
this.fontSize(12); |
|
this.font('helvetica, arial, sans-serif'); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Progress.prototype.size = function(n){ |
|
this._size = n; |
|
return this; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Progress.prototype.text = function(str){ |
|
this._text = str; |
|
return this; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Progress.prototype.fontSize = function(n){ |
|
this._fontSize = n; |
|
return this; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Progress.prototype.font = function(family){ |
|
this._font = family; |
|
return this; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Progress.prototype.update = function(n){ |
|
this.percent = n; |
|
return this; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Progress.prototype.draw = function(ctx){ |
|
var percent = Math.min(this.percent, 100) |
|
, size = this._size |
|
, half = size / 2 |
|
, x = half |
|
, y = half |
|
, rad = half - 1 |
|
, fontSize = this._fontSize; |
|
|
|
ctx.font = fontSize + 'px ' + this._font; |
|
|
|
var angle = Math.PI * 2 * (percent / 100); |
|
ctx.clearRect(0, 0, size, size); |
|
|
|
|
|
ctx.strokeStyle = '#9f9f9f'; |
|
ctx.beginPath(); |
|
ctx.arc(x, y, rad, 0, angle, false); |
|
ctx.stroke(); |
|
|
|
|
|
ctx.strokeStyle = '#eee'; |
|
ctx.beginPath(); |
|
ctx.arc(x, y, rad - 1, 0, angle, true); |
|
ctx.stroke(); |
|
|
|
|
|
var text = this._text || (percent | 0) + '%' |
|
, w = ctx.measureText(text).width; |
|
|
|
ctx.fillText( |
|
text |
|
, x - w / 2 + 1 |
|
, y + fontSize / 2 - 1); |
|
|
|
return this; |
|
}; |
|
|
|
}); |
|
|
|
require.register("browser/tty.js", function(module, exports, require){ |
|
|
|
exports.isatty = function(){ |
|
return true; |
|
}; |
|
|
|
exports.getWindowSize = function(){ |
|
return [window.innerHeight, window.innerWidth]; |
|
}; |
|
}); |
|
|
|
require.register("hook.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
var Runnable = require('./runnable'); |
|
|
|
|
|
|
|
|
|
|
|
module.exports = Hook; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Hook(title, fn) { |
|
Runnable.call(this, title, fn); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
Hook.prototype = new Runnable; |
|
Hook.prototype.constructor = Hook; |
|
|
|
|
|
}); |
|
|
|
require.register("interfaces/bdd.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
var Suite = require('../suite') |
|
, Test = require('../test'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = function(suite){ |
|
var suites = [suite]; |
|
|
|
suite.on('pre-require', function(context){ |
|
|
|
|
|
|
|
|
|
|
|
context.before = function(fn){ |
|
suites[0].beforeAll(fn); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
context.after = function(fn){ |
|
suites[0].afterAll(fn); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
context.beforeEach = function(fn){ |
|
suites[0].beforeEach(fn); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
context.afterEach = function(fn){ |
|
suites[0].afterEach(fn); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.describe = function(title, fn){ |
|
var suite = Suite.create(suites[0], title); |
|
suites.unshift(suite); |
|
fn(); |
|
suites.shift(); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.it = function(title, fn){ |
|
suites[0].addTest(new Test(title, fn)); |
|
}; |
|
}); |
|
}; |
|
|
|
}); |
|
|
|
require.register("interfaces/exports.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
var Suite = require('../suite') |
|
, Test = require('../test'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = function(suite){ |
|
var suites = [suite]; |
|
|
|
suite.on('require', visit); |
|
|
|
function visit(obj) { |
|
var suite; |
|
for (var key in obj) { |
|
if ('function' == typeof obj[key]) { |
|
var fn = obj[key]; |
|
switch (key) { |
|
case 'before': |
|
suites[0].beforeAll(fn); |
|
break; |
|
case 'after': |
|
suites[0].afterAll(fn); |
|
break; |
|
case 'beforeEach': |
|
suites[0].beforeEach(fn); |
|
break; |
|
case 'afterEach': |
|
suites[0].afterEach(fn); |
|
break; |
|
default: |
|
suites[0].addTest(new Test(key, fn)); |
|
} |
|
} else { |
|
var suite = Suite.create(suites[0], key); |
|
suites.unshift(suite); |
|
visit(obj[key]); |
|
suites.shift(); |
|
} |
|
} |
|
} |
|
}; |
|
}); |
|
|
|
require.register("interfaces/index.js", function(module, exports, require){ |
|
|
|
exports.bdd = require('./bdd'); |
|
exports.tdd = require('./tdd'); |
|
exports.exports = require('./exports'); |
|
}); |
|
|
|
require.register("interfaces/tdd.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
var Suite = require('../suite') |
|
, Test = require('../test'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = function(suite){ |
|
var suites = [suite]; |
|
|
|
suite.on('pre-require', function(context){ |
|
|
|
|
|
|
|
|
|
|
|
context.setup = function(fn){ |
|
suites[0].beforeEach(fn); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
context.teardown = function(fn){ |
|
suites[0].afterEach(fn); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
context.suiteSetup = function(fn){ |
|
suites[0].beforeAll(fn); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
context.suiteTeardown = function(fn){ |
|
suites[0].afterAll(fn); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.suite = function(title, fn){ |
|
var suite = Suite.create(suites[0], title); |
|
suites.unshift(suite); |
|
fn(); |
|
suites.shift(); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.test = function(title, fn){ |
|
suites[0].addTest(new Test(title, fn)); |
|
}; |
|
}); |
|
}; |
|
|
|
}); |
|
|
|
require.register("mocha.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.version = '0.3.6'; |
|
|
|
exports.interfaces = require('./interfaces'); |
|
exports.reporters = require('./reporters'); |
|
exports.Runnable = require('./runnable'); |
|
exports.Runner = require('./runner'); |
|
exports.Suite = require('./suite'); |
|
exports.Hook = require('./hook'); |
|
exports.Test = require('./test'); |
|
exports.watch = require('./watch'); |
|
}); |
|
|
|
require.register("reporters/base.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
var tty = require('browser/tty'); |
|
|
|
|
|
|
|
|
|
|
|
var isatty = tty.isatty(1) && tty.isatty(2); |
|
|
|
|
|
|
|
|
|
|
|
exports = module.exports = Base; |
|
|
|
|
|
|
|
|
|
|
|
exports.useColors = isatty; |
|
|
|
|
|
|
|
|
|
|
|
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 |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var color = exports.color = function(type, str) { |
|
if (!exports.useColors) return str; |
|
return '\033[' + exports.colors[type] + 'm' + str + '\033[0m'; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.window = { |
|
width: isatty |
|
? process.stdout.getWindowSize |
|
? process.stdout.getWindowSize(1)[0] |
|
: tty.getWindowSize()[1] |
|
: 75 |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.cursor = { |
|
hide: function(){ |
|
process.stdout.write('\033[?25l'); |
|
}, |
|
|
|
show: function(){ |
|
process.stdout.write('\033[?25h'); |
|
} |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.slow = 75; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.list = function(failures){ |
|
console.error(); |
|
failures.forEach(function(test, i){ |
|
|
|
var fmt = color('error title', ' %s) %s:\n') |
|
+ color('error message', ' %s') |
|
+ color('error stack', '\n%s\n'); |
|
|
|
|
|
var err = test.err |
|
, stack = err.stack |
|
, message = err.message || '' |
|
, index = stack.indexOf(message) + message.length |
|
, msg = stack.slice(0, index); |
|
|
|
|
|
stack = stack.slice(index + 1) |
|
.replace(/^/gm, ' '); |
|
|
|
console.error(fmt, i, test.fullTitle(), msg, stack); |
|
}); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Base(runner) { |
|
var self = this |
|
, stats = this.stats = { suites: 0, tests: 0, passes: 0, failures: 0 } |
|
, failures = this.failures = []; |
|
|
|
if (!runner) return; |
|
this.runner = runner; |
|
|
|
runner.on('start', function(){ |
|
stats.start = new Date; |
|
}); |
|
|
|
runner.on('suite', function(suite){ |
|
stats.suites = stats.suites || 0; |
|
stats.suites++; |
|
}); |
|
|
|
runner.on('test end', function(test){ |
|
stats.tests = stats.tests || 0; |
|
stats.tests++; |
|
}); |
|
|
|
runner.on('pass', function(test){ |
|
stats.passes = stats.passes || 0; |
|
|
|
var medium = exports.slow / 2; |
|
test.speed = test.duration > exports.slow |
|
? 'slow' |
|
: test.duration > medium |
|
? 'medium' |
|
: 'fast'; |
|
|
|
stats.passes++; |
|
}); |
|
|
|
runner.on('fail', function(test, err){ |
|
stats.failures = stats.failures || 0; |
|
stats.failures++; |
|
test.err = err; |
|
failures.push(test); |
|
}); |
|
|
|
runner.on('end', function(){ |
|
stats.end = new Date; |
|
stats.duration = new Date - stats.start; |
|
}); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Base.prototype.epilogue = function(){ |
|
var stats = this.stats |
|
, fmt; |
|
|
|
console.log(); |
|
|
|
|
|
if (stats.failures) { |
|
fmt = color('bright fail', ' ✖') |
|
+ color('fail', ' %d of %d tests failed') |
|
+ color('light', ':') |
|
|
|
console.error(fmt, stats.failures, this.runner.total); |
|
Base.list(this.failures); |
|
console.error(); |
|
return; |
|
} |
|
|
|
|
|
fmt = color('bright pass', ' ✔') |
|
+ color('green', ' %d tests complete') |
|
+ color('light', ' (%dms)'); |
|
|
|
console.log(fmt, stats.tests || 0, stats.duration); |
|
console.log(); |
|
}; |
|
|
|
}); |
|
|
|
require.register("reporters/doc.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
var Base = require('./base') |
|
, utils = require('../utils'); |
|
|
|
|
|
|
|
|
|
|
|
exports = module.exports = Doc; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Doc(runner) { |
|
Base.call(this, runner); |
|
|
|
var self = this |
|
, stats = this.stats |
|
, total = runner.total |
|
, indents = 2; |
|
|
|
function indent() { |
|
return Array(indents).join(' '); |
|
} |
|
|
|
runner.on('suite', function(suite){ |
|
if (suite.root) return; |
|
++indents; |
|
console.log('%s<section class="suite">', indent()); |
|
++indents; |
|
console.log('%s<h1>%s</h1>', indent(), suite.title); |
|
console.log('%s<dl>', indent()); |
|
}); |
|
|
|
runner.on('suite end', function(suite){ |
|
if (suite.root) return; |
|
console.log('%s</dl>', indent()); |
|
--indents; |
|
console.log('%s</section>', indent()); |
|
--indents; |
|
}); |
|
|
|
runner.on('pass', function(test){ |
|
console.log('%s <dt>%s</dt>', indent(), test.title); |
|
var code = utils.escape(clean(test.fn.toString())); |
|
console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code); |
|
}); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
function clean(str) { |
|
str = str |
|
.replace(/^function *\(.*\) *{/, '') |
|
.replace(/\s+\}$/, ''); |
|
|
|
var spaces = str.match(/^\n?( *)/)[1].length |
|
, re = new RegExp('^ {' + spaces + '}', 'gm'); |
|
|
|
str = str.replace(re, ''); |
|
|
|
return str; |
|
} |
|
}); |
|
|
|
require.register("reporters/dot.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
var Base = require('./base') |
|
, color = Base.color; |
|
|
|
|
|
|
|
|
|
|
|
exports = module.exports = Dot; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Dot(runner) { |
|
Base.call(this, runner); |
|
|
|
var self = this |
|
, stats = this.stats |
|
, width = Base.window.width * .75 | 0 |
|
, n = 0; |
|
|
|
runner.on('start', function(){ |
|
process.stdout.write('\n '); |
|
}); |
|
|
|
runner.on('pending', function(test){ |
|
process.stdout.write(color('pending', '.')); |
|
}); |
|
|
|
runner.on('pass', function(test){ |
|
if (++n % width == 0) process.stdout.write('\n '); |
|
if ('slow' == test.speed) { |
|
process.stdout.write(color('bright yellow', '.')); |
|
} else { |
|
process.stdout.write(color(test.speed, '.')); |
|
} |
|
}); |
|
|
|
runner.on('fail', function(test, err){ |
|
if (++n % width == 0) process.stdout.write('\n '); |
|
process.stdout.write(color('fail', '.')); |
|
}); |
|
|
|
runner.on('end', function(){ |
|
console.log(); |
|
self.epilogue(); |
|
}); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
Dot.prototype = new Base; |
|
Dot.prototype.constructor = Dot; |
|
|
|
}); |
|
|
|
require.register("reporters/html.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
var Base = require('./base') |
|
, utils = require('../utils') |
|
, Progress = require('../browser/progress'); |
|
|
|
|
|
|
|
|
|
|
|
exports = module.exports = HTML; |
|
|
|
|
|
|
|
|
|
|
|
var statsTemplate = '<ul id="stats">' |
|
+ '<li class="progress"><canvas width="50" height="50"></canvas></li>' |
|
+ '<li class="passes">passes: <em>0</em></li>' |
|
+ '<li class="failures">failures: <em>0</em></li>' |
|
+ '<li class="duration">duration: <em>0</em>s</li>' |
|
+ '</ul>'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function HTML(runner) { |
|
Base.call(this, runner); |
|
|
|
|
|
|
|
var self = this |
|
, stats = this.stats |
|
, total = runner.total |
|
, root = $('#mocha') |
|
, stack = [root] |
|
, stat = $(statsTemplate).appendTo(root) |
|
, canvas = stat.find('canvas').get(0) |
|
, ctx = canvas.getContext('2d') |
|
, progress = new Progress; |
|
|
|
if (!root.length) return error('#mocha div missing, add it to your document'); |
|
progress.size(50); |
|
|
|
runner.on('suite', function(suite){ |
|
if (suite.root) return; |
|
|
|
|
|
var el = $('<div class="suite"><h1>' + suite.title + '</h1></div>'); |
|
|
|
|
|
stack[0].append(el); |
|
stack.unshift($('<div>')); |
|
el.append(stack[0]); |
|
}); |
|
|
|
runner.on('suite end', function(suite){ |
|
if (suite.root) return; |
|
stack.shift(); |
|
}); |
|
|
|
runner.on('test end', function(test){ |
|
|
|
var percent = stats.tests / total * 100 | 0; |
|
|
|
|
|
progress.update(percent).draw(ctx); |
|
|
|
|
|
var ms = new Date - stats.start; |
|
stat.find('.passes em').text(stats.passes); |
|
stat.find('.failures em').text(stats.failures); |
|
stat.find('.duration em').text((ms / 1000).toFixed(2)); |
|
|
|
|
|
if (test.passed) { |
|
var el = $('<div class="test pass"><h2>' + test.title + '</h2></div>') |
|
} else if (test.pending) { |
|
var el = $('<div class="test pass pending"><h2>' + test.title + '</h2></div>') |
|
} else { |
|
var el = $('<div class="test fail"><h2>' + test.title + '</h2></div>'); |
|
var str = test.err.stack || test.err; |
|
var err = $('<pre class="error">' + str + '</pre>'); |
|
el.append(err); |
|
} |
|
|
|
|
|
el.find('h2').toggle(function(){ |
|
pre.slideDown('fast'); |
|
}, function(){ |
|
pre.slideUp('fast'); |
|
}); |
|
|
|
|
|
|
|
if (!test.pending) { |
|
var code = utils.escape(clean(test.fn.toString())); |
|
var pre = $('<pre><code>' + code + '</code></pre>'); |
|
pre.appendTo(el).hide(); |
|
} |
|
stack[0].append(el); |
|
}); |
|
} |
|
|
|
function error(msg) { |
|
$('<div id="error">' + msg + '</div>').appendTo('body'); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
function clean(str) { |
|
str = str |
|
.replace(/^function *\(.*\) *{/, '') |
|
.replace(/\s+\}$/, ''); |
|
|
|
var spaces = str.match(/^\n?( *)/)[1].length |
|
, re = new RegExp('^ {' + spaces + '}', 'gm'); |
|
|
|
str = str |
|
.replace(re, '') |
|
.replace(/^\s+/, ''); |
|
|
|
return str; |
|
} |
|
}); |
|
|
|
require.register("reporters/index.js", function(module, exports, require){ |
|
|
|
exports.Base = require('./base'); |
|
exports.Dot = require('./dot'); |
|
exports.Doc = require('./doc'); |
|
exports.TAP = require('./tap'); |
|
exports.JSON = require('./json'); |
|
exports.HTML = require('./html'); |
|
exports.List = require('./list'); |
|
exports.Spec = require('./spec'); |
|
exports.Progress = require('./progress'); |
|
exports.Landing = require('./landing'); |
|
exports.JSONStream = require('./json-stream'); |
|
|
|
}); |
|
|
|
require.register("reporters/json-stream.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
var Base = require('./base') |
|
, color = Base.color; |
|
|
|
|
|
|
|
|
|
|
|
exports = module.exports = List; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function List(runner) { |
|
Base.call(this, runner); |
|
|
|
var self = this |
|
, stats = this.stats |
|
, total = runner.total; |
|
|
|
runner.on('start', function(){ |
|
console.log(JSON.stringify(['start', { total: total }])); |
|
}); |
|
|
|
runner.on('pass', function(test){ |
|
console.log(JSON.stringify(['pass', clean(test)])); |
|
}); |
|
|
|
runner.on('fail', function(test, err){ |
|
console.log(JSON.stringify(['fail', clean(test)])); |
|
}); |
|
|
|
runner.on('end', function(){ |
|
process.stdout.write(JSON.stringify(['end', self.stats])); |
|
}); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function clean(test) { |
|
return { |
|
title: test.title |
|
, fullTitle: test.fullTitle() |
|
, duration: test.duration |
|
} |
|
} |
|
}); |
|
|
|
require.register("reporters/json.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
var Base = require('./base') |
|
, cursor = Base.cursor |
|
, color = Base.color; |
|
|
|
|
|
|
|
|
|
|
|
exports = module.exports = JSONReporter; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function JSONReporter(runner) { |
|
var self = this; |
|
Base.call(this, runner); |
|
|
|
var tests = [] |
|
, failures = [] |
|
, passes = []; |
|
|
|
runner.on('test end', function(test){ |
|
tests.push(test); |
|
}); |
|
|
|
runner.on('pass', function(test){ |
|
passes.push(test); |
|
}); |
|
|
|
runner.on('fail', function(test){ |
|
failures.push(test); |
|
}); |
|
|
|
runner.on('end', function(){ |
|
var obj = { |
|
stats: self.stats |
|
, tests: tests.map(clean) |
|
, failures: failures.map(clean) |
|
, passes: passes.map(clean) |
|
}; |
|
|
|
process.stdout.write(JSON.stringify(obj)); |
|
}); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function clean(test) { |
|
return { |
|
title: test.title |
|
, fullTitle: test.fullTitle() |
|
, duration: test.duration |
|
} |
|
} |
|
}); |
|
|
|
require.register("reporters/landing.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
var Base = require('./base') |
|
, cursor = Base.cursor |
|
, color = Base.color; |
|
|
|
|
|
|
|
|
|
|
|
exports = module.exports = Landing; |
|
|
|
|
|
|
|
|
|
|
|
Base.colors.plane = 0; |
|
|
|
|
|
|
|
|
|
|
|
Base.colors['plane crash'] = 31; |
|
|
|
|
|
|
|
|
|
|
|
Base.colors.runway = 90; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Landing(runner) { |
|
Base.call(this, runner); |
|
|
|
var self = this |
|
, stats = this.stats |
|
, width = Base.window.width * .75 | 0 |
|
, total = runner.total |
|
, stream = process.stdout |
|
, plane = color('plane', '✈') |
|
, crashed = -1 |
|
, n = 0; |
|
|
|
function runway() { |
|
var buf = Array(width).join('-'); |
|
return ' ' + color('runway', buf); |
|
} |
|
|
|
runner.on('start', function(){ |
|
stream.write('\n '); |
|
cursor.hide(); |
|
}); |
|
|
|
runner.on('test end', function(test){ |
|
|
|
var col = -1 == crashed |
|
? width * ++n / total | 0 |
|
: crashed; |
|
|
|
|
|
if (test.failed) { |
|
plane = color('plane crash', '✈'); |
|
crashed = col; |
|
} |
|
|
|
|
|
stream.write('\033[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'); |
|
}); |
|
|
|
runner.on('end', function(){ |
|
cursor.show(); |
|
console.log(); |
|
self.epilogue(); |
|
}); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
Landing.prototype = new Base; |
|
Landing.prototype.constructor = Landing; |
|
|
|
}); |
|
|
|
require.register("reporters/list.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
var Base = require('./base') |
|
, color = Base.color; |
|
|
|
|
|
|
|
|
|
|
|
exports = module.exports = List; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function List(runner) { |
|
Base.call(this, runner); |
|
|
|
var self = this |
|
, stats = this.stats |
|
, n = 0; |
|
|
|
runner.on('start', function(){ |
|
console.log(); |
|
}); |
|
|
|
runner.on('test', function(test){ |
|
process.stdout.write(color('pass', ' ' + test.fullTitle() + ': ')); |
|
}); |
|
|
|
runner.on('pending', function(test){ |
|
var fmt = color('checkmark', ' -') |
|
+ color('pending', ' %s'); |
|
console.log(fmt, test.fullTitle()); |
|
}); |
|
|
|
runner.on('pass', function(test){ |
|
var fmt = color('checkmark', ' ✓') |
|
+ color('pass', ' %s: ') |
|
+ color(test.speed, '%dms'); |
|
console.log('\r' + fmt, test.fullTitle(), test.duration); |
|
}); |
|
|
|
runner.on('fail', function(test, err){ |
|
console.log('\r' + color('fail', ' %d) %s'), n++, test.fullTitle()); |
|
}); |
|
|
|
runner.on('end', self.epilogue.bind(self)); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
List.prototype = new Base; |
|
List.prototype.constructor = List; |
|
|
|
}); |
|
|
|
require.register("reporters/progress.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
var Base = require('./base') |
|
, cursor = Base.cursor |
|
, color = Base.color; |
|
|
|
|
|
|
|
|
|
|
|
exports = module.exports = Progress; |
|
|
|
|
|
|
|
|
|
|
|
Base.colors.progress = 90; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Progress(runner, options) { |
|
Base.call(this, runner); |
|
|
|
var self = this |
|
, options = options || {} |
|
, stats = this.stats |
|
, width = Base.window.width * .50 | 0 |
|
, total = runner.total |
|
, complete = 0 |
|
, max = Math.max; |
|
|
|
|
|
options.open = options.open || '['; |
|
options.complete = options.complete || '▬'; |
|
options.incomplete = options.incomplete || '⋅'; |
|
options.close = options.close || ']'; |
|
options.verbose = false; |
|
|
|
|
|
runner.on('start', function(){ |
|
console.log(); |
|
cursor.hide(); |
|
}); |
|
|
|
|
|
runner.on('test end', function(){ |
|
var incomplete = total - complete |
|
, percent = complete++ / total |
|
, n = width * percent | 0 |
|
, i = width - n; |
|
|
|
process.stdout.write('\r\033[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) { |
|
process.stdout.write(color('progress', ' ' + complete + ' of ' + total)); |
|
} |
|
}); |
|
|
|
|
|
|
|
runner.on('end', function(){ |
|
cursor.show(); |
|
console.log(); |
|
self.epilogue(); |
|
}); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
Progress.prototype = new Base; |
|
Progress.prototype.constructor = Progress; |
|
|
|
}); |
|
|
|
require.register("reporters/spec.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
var Base = require('./base') |
|
, color = Base.color; |
|
|
|
|
|
|
|
|
|
|
|
exports = module.exports = Spec; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Spec(runner) { |
|
Base.call(this, runner); |
|
|
|
var self = this |
|
, stats = this.stats |
|
, indents = 0 |
|
, n = 0; |
|
|
|
function indent() { |
|
return Array(indents).join(' ') |
|
} |
|
|
|
runner.on('start', function(){ |
|
console.log(); |
|
}); |
|
|
|
runner.on('suite', function(suite){ |
|
++indents; |
|
console.log(color('suite', '%s%s'), indent(), suite.title); |
|
}); |
|
|
|
runner.on('suite end', function(suite){ |
|
--indents; |
|
if (1 == indents) console.log(); |
|
}); |
|
|
|
runner.on('test', function(test){ |
|
process.stdout.write(indent() + color('pass', ' ◦ ' + test.title + ': ')); |
|
}); |
|
|
|
runner.on('pending', function(test){ |
|
var fmt = indent() + color('pending', ' - %s'); |
|
console.log(fmt, test.title); |
|
}); |
|
|
|
runner.on('pass', function(test){ |
|
if ('fast' == test.speed) { |
|
var fmt = indent() |
|
+ color('checkmark', ' ✓') |
|
+ color('pass', ' %s '); |
|
console.log('\r' + fmt, test.title); |
|
} else { |
|
var fmt = indent() |
|
+ color('checkmark', ' ✓') |
|
+ color('pass', ' %s ') |
|
+ color(test.speed, '(%dms)'); |
|
console.log('\r' + fmt, test.title, test.duration); |
|
} |
|
}); |
|
|
|
runner.on('fail', function(test, err){ |
|
console.log('\r' + indent() + color('fail', ' %d) %s'), n++, test.title); |
|
}); |
|
|
|
runner.on('end', self.epilogue.bind(self)); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
Spec.prototype = new Base; |
|
Spec.prototype.constructor = Spec; |
|
|
|
}); |
|
|
|
require.register("reporters/tap.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
var Base = require('./base') |
|
, cursor = Base.cursor |
|
, color = Base.color; |
|
|
|
|
|
|
|
|
|
|
|
exports = module.exports = TAP; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function TAP(runner) { |
|
Base.call(this, runner); |
|
|
|
var self = this |
|
, stats = this.stats |
|
, total = runner.total |
|
, n = 1; |
|
|
|
runner.on('start', function(){ |
|
console.log('%d..%d', 1, total); |
|
}); |
|
|
|
runner.on('test end', function(){ |
|
++n; |
|
}); |
|
|
|
runner.on('pass', function(test){ |
|
console.log('ok %d %s', n, test.fullTitle()); |
|
}); |
|
|
|
runner.on('fail', function(test, err){ |
|
console.log('not ok %d %s', n, test.fullTitle()); |
|
console.log(err.stack.replace(/^/gm, ' ')); |
|
}); |
|
} |
|
}); |
|
|
|
require.register("runnable.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
var EventEmitter = require('browser/events').EventEmitter |
|
, debug = require('browser/debug')('runnable'); |
|
|
|
|
|
|
|
|
|
|
|
module.exports = Runnable; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Runnable(title, fn) { |
|
this.title = title; |
|
this.fn = fn; |
|
this.async = fn && fn.length; |
|
this.sync = ! this.async; |
|
this._timeout = 2000; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
Runnable.prototype = new EventEmitter; |
|
Runnable.prototype.constructor = Runnable; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Runnable.prototype.timeout = function(ms){ |
|
if (0 == arguments.length) return this._timeout; |
|
debug('timeout %d', ms); |
|
this._timeout = ms; |
|
return this; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Runnable.prototype.fullTitle = function(){ |
|
return this.parent.fullTitle() + ' ' + this.title; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Runnable.prototype.clearTimeout = function(){ |
|
clearTimeout(this.timer); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Runnable.prototype.run = function(fn){ |
|
var self = this |
|
, ms = this.timeout() |
|
, start = new Date |
|
, finished |
|
, emitted; |
|
|
|
|
|
if (this.async) { |
|
this.timer = setTimeout(function(){ |
|
done(new Error('timeout of ' + ms + 'ms exceeded')); |
|
}, ms); |
|
} |
|
|
|
|
|
function multiple() { |
|
if (emitted) return; |
|
emitted = true; |
|
self.emit('error', new Error('done() called multiple times')); |
|
} |
|
|
|
|
|
function done(err) { |
|
if (finished) return multiple(); |
|
self.clearTimeout(); |
|
self.duration = new Date - start; |
|
finished = true; |
|
fn(err); |
|
} |
|
|
|
|
|
if (this.async) { |
|
try { |
|
this.fn(function(err){ |
|
if (err instanceof Error) return done(err); |
|
done(); |
|
}); |
|
} catch (err) { |
|
done(err); |
|
} |
|
return; |
|
} |
|
|
|
|
|
try { |
|
if (!this.pending) this.fn(); |
|
this.duration = new Date - start; |
|
fn(); |
|
} catch (err) { |
|
fn(err); |
|
} |
|
}; |
|
|
|
}); |
|
|
|
require.register("runner.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
var EventEmitter = require('browser/events').EventEmitter |
|
, debug = require('browser/debug')('runner') |
|
, Test = require('./test') |
|
, noop = function(){}; |
|
|
|
|
|
|
|
|
|
|
|
module.exports = Runner; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Runner(suite) { |
|
var self = this; |
|
this._globals = []; |
|
this.suite = suite; |
|
this.total = suite.total(); |
|
this.failures = 0; |
|
this.on('test end', function(test){ self.checkGlobals(test); }); |
|
this.on('hook end', function(hook){ self.checkGlobals(hook); }); |
|
this.grep(/.*/); |
|
this.globals(Object.keys(global).concat(['errno'])); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
Runner.prototype = new EventEmitter; |
|
Runner.prototype.constructor = Runner; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Runner.prototype.grep = function(re){ |
|
debug('grep %s', re); |
|
this._grep = re; |
|
return this; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Runner.prototype.globals = function(arr){ |
|
debug('globals %j', arr); |
|
arr.forEach(function(arr){ |
|
this._globals.push(arr); |
|
}, this); |
|
return this; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Runner.prototype.checkGlobals = function(test){ |
|
if (this.ignoreLeaks) return; |
|
|
|
var leaks = Object.keys(global).filter(function(key){ |
|
return !~this._globals.indexOf(key); |
|
}, this); |
|
|
|
this._globals = this._globals.concat(leaks); |
|
|
|
if (leaks.length > 1) { |
|
this.fail(test, new Error('global leaks detected: ' + leaks.join(', ') + '')); |
|
} else if (leaks.length) { |
|
this.fail(test, new Error('global leak detected: ' + leaks[0])); |
|
} |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Runner.prototype.fail = function(test, err){ |
|
++this.failures; |
|
test.failed = true; |
|
this.emit('fail', test, err); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Runner.prototype.failHook = function(hook, err){ |
|
++this.failures; |
|
this.fail(hook, err); |
|
this.emit('end'); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Runner.prototype.hook = function(name, fn){ |
|
var suite = this.suite |
|
, hooks = suite['_' + name] |
|
, ms = suite._timeout |
|
, self = this |
|
, timer; |
|
|
|
function next(i) { |
|
var hook = hooks[i]; |
|
if (!hook) return fn(); |
|
self.currentRunnable = hook; |
|
|
|
self.emit('hook', hook); |
|
|
|
hook.on('error', function(err){ |
|
self.failHook(hook, err); |
|
}); |
|
|
|
hook.run(function(err){ |
|
hook.removeAllListeners('error'); |
|
if (err) return self.failHook(hook, err); |
|
self.emit('hook end', hook); |
|
next(++i); |
|
}); |
|
} |
|
|
|
process.nextTick(function(){ |
|
next(0); |
|
}); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Runner.prototype.hooks = function(name, suites, fn){ |
|
var self = this |
|
, orig = this.suite; |
|
|
|
function next(suite) { |
|
self.suite = suite; |
|
|
|
if (!suite) { |
|
self.suite = orig; |
|
return fn(); |
|
} |
|
|
|
self.hook(name, function(err){ |
|
if (err) { |
|
self.suite = orig; |
|
return fn(err); |
|
} |
|
|
|
next(suites.pop()); |
|
}); |
|
} |
|
|
|
next(suites.pop()); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Runner.prototype.hookUp = function(name, fn){ |
|
var suites = [this.suite].concat(this.parents()).reverse(); |
|
this.hooks(name, suites, fn); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Runner.prototype.hookDown = function(name, fn){ |
|
var suites = [this.suite].concat(this.parents()); |
|
this.hooks(name, suites, fn); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Runner.prototype.parents = function(){ |
|
var suite = this.suite |
|
, suites = []; |
|
while (suite = suite.parent) suites.push(suite); |
|
return suites; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Runner.prototype.runTest = function(fn){ |
|
var test = this.test |
|
, self = this; |
|
|
|
try { |
|
test.on('error', function(err){ |
|
self.fail(test, err); |
|
}); |
|
test.run(fn); |
|
} catch (err) { |
|
fn(err); |
|
} |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Runner.prototype.runTests = function(suite, fn){ |
|
var self = this |
|
, tests = suite.tests |
|
, test; |
|
|
|
function next(err) { |
|
|
|
test = tests.shift(); |
|
|
|
|
|
if (!test) return fn(); |
|
|
|
|
|
if (!self._grep.test(test.fullTitle())) return next(); |
|
|
|
|
|
if (test.pending) { |
|
self.emit('pending', test); |
|
self.emit('test end', test); |
|
return next(); |
|
} |
|
|
|
|
|
self.emit('test', self.test = self.currentRunnable = test); |
|
self.hookDown('beforeEach', function(){ |
|
self.runTest(function(err){ |
|
if (err) { |
|
self.fail(test, err); |
|
self.emit('test end', test); |
|
return self.hookUp('afterEach', next); |
|
} |
|
|
|
self.emit('pass', test); |
|
test.passed = true; |
|
self.emit('test end', test); |
|
self.hookUp('afterEach', next); |
|
}); |
|
}); |
|
} |
|
|
|
next(); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Runner.prototype.runSuite = function(suite, fn){ |
|
var self = this |
|
, i = 0; |
|
|
|
debug('run suite %s', suite.fullTitle()); |
|
this.emit('suite', this.suite = suite); |
|
|
|
function next() { |
|
var curr = suite.suites[i++]; |
|
if (!curr) return done(); |
|
self.runSuite(curr, next); |
|
} |
|
|
|
function done() { |
|
self.suite = suite; |
|
self.hook('afterAll', function(){ |
|
self.emit('suite end', suite); |
|
fn(); |
|
}); |
|
} |
|
|
|
this.hook('beforeAll', function(){ |
|
self.runTests(suite, next); |
|
}); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Runner.prototype.run = function(fn){ |
|
var self = this |
|
, fn = fn || function(){}; |
|
|
|
debug('start'); |
|
|
|
|
|
self.on('end', function(){ |
|
debug('end'); |
|
process.removeListener('uncaughtException', uncaught); |
|
fn(self.failures); |
|
}); |
|
|
|
|
|
this.emit('start'); |
|
this.runSuite(this.suite, function(){ |
|
debug('finished running'); |
|
self.emit('end'); |
|
}); |
|
|
|
|
|
function uncaught(err){ |
|
debug('uncaught exception'); |
|
self.currentRunnable.clearTimeout(); |
|
self.fail(self.currentRunnable, err); |
|
self.emit('test end', self.test); |
|
self.emit('end'); |
|
} |
|
|
|
process.on('uncaughtException', uncaught); |
|
|
|
return this; |
|
}; |
|
|
|
}); |
|
|
|
require.register("suite.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
var EventEmitter = require('browser/events').EventEmitter |
|
, debug = require('browser/debug')('suite') |
|
, Hook = require('./hook'); |
|
|
|
|
|
|
|
|
|
|
|
exports = module.exports = Suite; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.create = function(parent, title){ |
|
var suite = new Suite(title); |
|
suite.parent = parent; |
|
title = suite.fullTitle(); |
|
parent.addSuite(suite); |
|
return suite; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Suite(title) { |
|
this.title = title; |
|
this.suites = []; |
|
this.tests = []; |
|
this._beforeEach = []; |
|
this._beforeAll = []; |
|
this._afterEach = []; |
|
this._afterAll = []; |
|
this.root = !title; |
|
this._timeout = 2000; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
Suite.prototype = new EventEmitter; |
|
Suite.prototype.constructor = Suite; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Suite.prototype.clone = function(){ |
|
var suite = new Suite(this.title); |
|
debug('clone'); |
|
suite.timeout(this.timeout()); |
|
return suite; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Suite.prototype.timeout = function(ms){ |
|
if (0 == arguments.length) return this._timeout; |
|
if (String(ms).match(/s$/)) ms = parseFloat(ms) * 1000; |
|
debug('timeout %d', ms); |
|
this._timeout = parseInt(ms, 10); |
|
return this; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Suite.prototype.beforeAll = function(fn){ |
|
var hook = new Hook('"before all" hook', fn); |
|
hook.parent = this; |
|
hook.timeout(this.timeout()); |
|
this._beforeAll.push(hook); |
|
this.emit('beforeAll', hook); |
|
return this; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Suite.prototype.afterAll = function(fn){ |
|
var hook = new Hook('"after all" hook', fn); |
|
hook.parent = this; |
|
hook.timeout(this.timeout()); |
|
this._afterAll.push(hook); |
|
this.emit('afterAll', hook); |
|
return this; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Suite.prototype.beforeEach = function(fn){ |
|
var hook = new Hook('"before each" hook', fn); |
|
hook.parent = this; |
|
hook.timeout(this.timeout()); |
|
this._beforeEach.push(hook); |
|
this.emit('beforeEach', hook); |
|
return this; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Suite.prototype.afterEach = function(fn){ |
|
var hook = new Hook('"after each" hook', fn); |
|
hook.parent = this; |
|
hook.timeout(this.timeout()); |
|
this._afterEach.push(hook); |
|
this.emit('afterEach', hook); |
|
return this; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Suite.prototype.addSuite = function(suite){ |
|
suite.parent = this; |
|
suite.timeout(this.timeout()); |
|
this.suites.push(suite); |
|
this.emit('suite', suite); |
|
return this; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Suite.prototype.addTest = function(test){ |
|
test.parent = this; |
|
test.timeout(this.timeout()); |
|
this.tests.push(test); |
|
this.emit('test', test); |
|
return this; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Suite.prototype.fullTitle = function(){ |
|
if (this.parent) { |
|
var full = this.parent.fullTitle(); |
|
if (full) return full + ' ' + this.title; |
|
} |
|
return this.title; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Suite.prototype.total = function(){ |
|
return this.suites.reduce(function(sum, suite){ |
|
return sum + suite.total(); |
|
}, 0) + this.tests.length; |
|
}; |
|
|
|
}); |
|
|
|
require.register("test.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
var Runnable = require('./runnable'); |
|
|
|
|
|
|
|
|
|
|
|
module.exports = Test; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Test(title, fn) { |
|
Runnable.call(this, title, fn); |
|
this.pending = !fn; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
Test.prototype = new Runnable; |
|
Test.prototype.constructor = Test; |
|
|
|
|
|
}); |
|
|
|
require.register("utils.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.escape = function(html) { |
|
return String(html) |
|
.replace(/&/g, '&') |
|
.replace(/"/g, '"') |
|
.replace(/</g, '<') |
|
.replace(/>/g, '>'); |
|
}; |
|
}); |
|
|
|
require.register("watch.js", function(module, exports, require){ |
|
|
|
|
|
|
|
|
|
|
|
var fs = require('browser/fs') |
|
, debug = require('browser/debug')('watch'); |
|
|
|
module.exports = function(paths, fn){ |
|
var options = { interval: 100 }; |
|
paths.forEach(function(path){ |
|
debug('watch %s', path); |
|
fs.watchFile(path, options, function(curr, prev){ |
|
if (prev.mtime < curr.mtime) fn(path); |
|
}); |
|
}); |
|
}; |
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
process = {}; |
|
process.exit = function(status){}; |
|
process.stdout = {}; |
|
global = this; |
|
|
|
process.nextTick = function(fn){ fn(); }; |
|
|
|
process.removeListener = function(ev){ |
|
if ('uncaughtException' == ev) { |
|
window.onerror = null; |
|
} |
|
}; |
|
|
|
process.on = function(ev, fn){ |
|
if ('uncaughtException' == ev) { |
|
window.onerror = fn; |
|
} |
|
}; |
|
|
|
mocha = require('mocha'); |
|
|
|
|
|
;(function(){ |
|
var suite = new mocha.Suite; |
|
var Reporter = mocha.reporters.HTML; |
|
|
|
function parse(qs) { |
|
return qs |
|
.replace('?', '') |
|
.split('&') |
|
.reduce(function(obj, pair){ |
|
var i = pair.indexOf('=') |
|
, key = pair.slice(0, i) |
|
, val = pair.slice(++i); |
|
|
|
obj[key] = decodeURIComponent(val); |
|
return obj; |
|
}, {}); |
|
} |
|
|
|
mocha.setup = function(ui){ |
|
ui = mocha.interfaces[ui]; |
|
if (!ui) throw new Error('invalid mocha interface "' + ui + '"'); |
|
ui(suite); |
|
suite.emit('pre-require', global); |
|
}; |
|
|
|
mocha.run = function(){ |
|
suite.emit('run'); |
|
var runner = new mocha.Runner(suite); |
|
var reporter = new Reporter(runner); |
|
var query = parse(window.location.search || ""); |
|
if (query.grep) runner.grep(new RegExp(query.grep)); |
|
return runner.run(); |
|
}; |
|
})(); |
|
})(); |