Skip to content

Commit

Permalink
Merge commit '7657cb11d960cf2cd8407b256019b2e34dc93328' into v2.3.0
Browse files Browse the repository at this point in the history
* commit '7657cb11d960cf2cd8407b256019b2e34dc93328':
  Allow --async-only to be satisfied by returning a promise
  • Loading branch information
Christopher Hiller committed Mar 31, 2015
2 parents d9a8192 + 7657cb1 commit 7be4891
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/_mocha
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var images = {
program
.version(JSON.parse(fs.readFileSync(__dirname + '/../package.json', 'utf8')).version)
.usage('[debug] [options] [files]')
.option('-A, --async-only', "force all tests to take a callback (async)")
.option('-A, --async-only', "force all tests to take a callback (async) or return a promise")
.option('-c, --colors', 'force enabling of colors')
.option('-C, --no-colors', 'force disabling of colors')
.option('-G, --growl', 'enable growl notification support')
Expand Down
8 changes: 4 additions & 4 deletions lib/runnable.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,6 @@ Runnable.prototype.run = function(fn){
return;
}

if (this.asyncOnly) {
return done(new Error('--async-only option in use without declaring `done()`'));
}

// sync or promise-returning
try {
if (this.pending) {
Expand All @@ -274,6 +270,10 @@ Runnable.prototype.run = function(fn){
done(reason || new Error('Promise rejected with no or falsy reason'))
});
} else {
if (self.asyncOnly) {
return done(new Error('--async-only option in use without declaring `done()` or returning a promise'));
}

done();
}
}
Expand Down
19 changes: 19 additions & 0 deletions test/acceptance/misc/asyncOnly.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,23 @@ describe('asyncOnly', function(){
it('should pass', function(done){
done();
})

it('should ignore pending tests')

it('should fail when test throws an error', function(){
// the async warning only applies if the test would have otherwise passed
throw Error('you should see this error');
})

describe('with a function that returns a promise', function() {
it('should pass', function(){
var fulfilledPromise = {
then: function (fulfilled, rejected) {
process.nextTick(fulfilled);
}
};

return fulfilledPromise;
})
})
})

0 comments on commit 7be4891

Please sign in to comment.