Merge pull request #77 from strongloop/feature/add-boot-completion-check

Add "booting" flag and emit "booted" event
This commit is contained in:
Miroslav Bajtoš 2015-01-07 16:41:29 +01:00
commit c47bde9281
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) {
callback = callback || function() {};
app.booting = true;
patchAppLoopback(app);
assertLoopBackVersion(app);
@ -38,7 +42,15 @@ module.exports = function execute(app, instructions, callback) {
function(done) {
enableAnonymousSwagger(app, instructions);
done();
}], callback);
}], function(err) {
app.booting = false;
if (err) return callback(err);
app.emit('booted');
callback();
});
};
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() {
boot.execute(app, dummyInstructions);
assert(app.models);