Add "booting" flag and emit "booted" event

This commit is contained in:
Simon Ho 2014-12-03 00:31:40 -08:00
parent 1ef2616979
commit 1f7d8e56e8
2 changed files with 39 additions and 1 deletions

View File

@ -16,6 +16,10 @@ var path = require('path');
*/ */
module.exports = function execute(app, instructions, callback) { module.exports = function execute(app, instructions, callback) {
callback = callback || function() {};
app.booting = true;
patchAppLoopback(app); patchAppLoopback(app);
assertLoopBackVersion(app); assertLoopBackVersion(app);
@ -37,7 +41,15 @@ module.exports = function execute(app, instructions, callback) {
function(done) { function(done) {
enableAnonymousSwagger(app, instructions); enableAnonymousSwagger(app, instructions);
done(); done();
}], callback); }], function(err) {
app.booting = false;
if (err) return callback(err);
app.emit('booted');
callback();
});
}; };
function patchAppLoopback(app) { function patchAppLoopback(app) {

View File

@ -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() { it('configures models', function() {
boot.execute(app, dummyInstructions); boot.execute(app, dummyInstructions);
assert(app.models); assert(app.models);