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

Ban mixing of promise and async APIs in it handler. #1735

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/runnable.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ Runnable.prototype.run = function(fn){
this.resetTimeout();

try {
this.fn.call(ctx, function(err){
var ret = this.fn.call(ctx, function(err){
if (err instanceof Error || toString.call(err) === "[object Error]") return done(err);
if (null != err) {
if (Object.prototype.toString.call(err) === '[object Object]') {
Expand All @@ -238,6 +238,9 @@ Runnable.prototype.run = function(fn){
}
done();
});
if (ret && typeof ret.then === 'function') {
done(new Error('runnable accepted "done" but returned promise'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs different language.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about Supply a "done" parameter or return a Promise, but not both

}
} catch (err) {
done(utils.getError(err));
}
Expand Down
13 changes: 13 additions & 0 deletions test/runnable.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,5 +406,18 @@ describe('Runnable(title, fn)', function(){
test.run(done);
})
})

describe('when fn had a done argument and returns a promise', function(){
it('should consider this an error', function(done){
var test = new Runnable('foo', function(done){
return { then: function(){} };
});

test.run(function(err) {
err.should.be.ok;
done();
});
})
})
})
})