Skip to content
Merged
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
4 changes: 2 additions & 2 deletions lib/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,11 @@ function runScripts(app, list, callback) {
async.eachSeries(functions, function(f, done) {
debug('Running script %s', f.path);
var cb = function(err) {
debug('Async function finished %s', f.path);
debug('Async function %s %s', err ? 'failed' : 'finished', f.path);
done(err);
// Make sure done() isn't called twice, e.g. if a script returns a
// thenable object and also calls the passed callback.
cb = null;
cb = function() {};
};
try {
var result = f.func(app, cb);
Expand Down
17 changes: 17 additions & 0 deletions test/executor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,23 @@ describe('executor', function() {
});
});

describe('with boot script returning a promise and calling callback',
function() {
before(function() {
process.promiseAndCallback = true;
});

after(function() {
delete process.promiseAndCallback;
});

it('should only call the callback once', function(done) {
// Note: Mocha will fail this test if done() is called twice
boot.execute(app, simpleAppInstructions(), done);
});
}
);

describe('for mixins', function() {
var options;
beforeEach(function() {
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/simple-app/boot/promise-callback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright IBM Corp. 2017. All Rights Reserved.
// Node module: loopback-boot
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

var Promise = require('bluebird');

module.exports = function(app, callback) {
callback();
if (process.promiseAndCallback) {
return Promise.reject();
}
};