Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow --async-only to be satisfied by returning a promise #1490

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -232,10 +232,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 @@ -259,6 +255,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;
})
})
})