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
14 changes: 13 additions & 1 deletion lib/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ var path = require('path');
*/

module.exports = function execute(app, instructions, callback) {
callback = callback || function() {};

app.booting = true;

patchAppLoopback(app);
assertLoopBackVersion(app);

Expand All @@ -37,7 +41,15 @@ module.exports = function execute(app, instructions, callback) {
function(done) {
enableAnonymousSwagger(app, instructions);
done();
}], callback);
}], function(err) {
app.booting = false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

app.booting should be reset before calling callback(err).


if (err) return callback(err);

app.emit('booted');

callback();
});
};

function patchAppLoopback(app) {
Expand Down
26 changes: 26 additions & 0 deletions test/executor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,32 @@ describe('executor', function() {
}
});

describe('when booting', function() {
it('should set the booting status', function(done) {
expect(app.booting).to.be.undefined();
boot.execute(app, dummyInstructions, function(err) {
expect(err).to.be.undefined();
expect(app.booting).to.be.false();
done();
});
});

it('should emit the `booted` event', function(done) {
app.on('booted', function() {
// This test fails with a timeout when the `booted` event has not been
// emitted correctly
done();
});
boot.execute(app, dummyInstructions, function(err) {
expect(err).to.be.undefined();
});
});

it('should work when called synchronously', function() {
boot.execute(app, dummyInstructions);
});
});

it('configures models', function() {
boot.execute(app, dummyInstructions);
assert(app.models);
Expand Down