Skip to content

Commit

Permalink
Make'd mocha.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Imrie-Situnayake committed Nov 20, 2012
1 parent 0ae96d2 commit 9d0d868
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions mocha.js
Expand Up @@ -1408,7 +1408,7 @@ exports.colors = {
*/

exports.symbols = {
ok: '',
ok: '',
err: '✖',
dot: '․'
};
Expand Down Expand Up @@ -1651,7 +1651,7 @@ Base.prototype.epilogue = function(){
}

// pass
fmt = color('bright pass', ' ' + exports.symbols.ok)
fmt = color('bright pass', ' ')
+ color('green', ' %d %s complete')
+ color('light', ' (%s)');

Expand All @@ -1662,7 +1662,7 @@ Base.prototype.epilogue = function(){

// pending
if (stats.pending) {
fmt = color('pending', ' ')
fmt = color('pending', ' ')
+ color('pending', ' %d %s pending');

console.log(fmt, stats.pending, pluralize(stats.pending));
Expand Down Expand Up @@ -3518,6 +3518,12 @@ var Date = global.Date
, clearTimeout = global.clearTimeout
, clearInterval = global.clearInterval;

/**
* Object#toString().
*/

var toString = Object.prototype.toString;

/**
* Expose `Runnable`.
*/
Expand Down Expand Up @@ -3691,7 +3697,7 @@ Runnable.prototype.run = function(fn){
if (this.async) {
try {
this.fn.call(ctx, function(err){
if (err instanceof Error) return done(err);
if (toString.call(err) === "[object Error]") return done(err);
if (null != err) return done(new Error('done() invoked with non-Error: ' + err));
done();
});
Expand Down Expand Up @@ -3912,10 +3918,10 @@ Runner.prototype.fail = function(test, err){
/**
* Fail the given `hook` with `err`.
*
* Hook failures (currently) hard-end due
* to that fact that a failing hook will
* surely cause subsequent tests to fail,
* causing jumbled reporting.
* Hook failures should emit a `fail`
* and `hook end`.
* Subsequent tests in the current suite
* will not be run.
*
* @param {Hook} hook
* @param {Error} err
Expand All @@ -3924,7 +3930,7 @@ Runner.prototype.fail = function(test, err){

Runner.prototype.failHook = function(hook, err){
this.fail(hook, err);
this.emit('end');
this.emit('hook end', hook);
};

/**
Expand All @@ -3950,13 +3956,17 @@ Runner.prototype.hook = function(name, fn){

hook.on('error', function(err){
self.failHook(hook, err);
return fn(err);
});

hook.run(function(err){
hook.removeAllListeners('error');
var testError = hook.error();
if (testError) self.fail(self.test, testError);
if (err) return self.failHook(hook, err);
if (err) {
self.failHook(hook, err);
return fn(err);
}
self.emit('hook end', hook);
next(++i);
});
Expand Down Expand Up @@ -4104,7 +4114,10 @@ Runner.prototype.runTests = function(suite, fn){

// execute test and hook(s)
self.emit('test', self.test = test);
self.hookDown('beforeEach', function(){
self.hookDown('beforeEach', function(err){
if(err){
return fn();
}
self.currentRunnable = self.test;
self.runTest(function(err){
test = self.test;
Expand Down Expand Up @@ -4161,7 +4174,10 @@ Runner.prototype.runSuite = function(suite, fn){
});
}

this.hook('beforeAll', function(){
this.hook('beforeAll', function(err){
if(err){
return done();
}
self.runTests(suite, next);
});
};
Expand Down

0 comments on commit 9d0d868

Please sign in to comment.