2019-05-07 13:12:54 +00:00
|
|
|
// Copyright IBM Corp. 2016,2019. All Rights Reserved.
|
|
|
|
// Node module: loopback-boot
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
2017-05-08 21:48:48 +00:00
|
|
|
'use strict';
|
|
|
|
|
2019-11-17 19:19:25 +00:00
|
|
|
const path = require('path');
|
|
|
|
const loopback = require('loopback');
|
2016-04-27 22:55:57 +00:00
|
|
|
|
2019-11-17 19:19:25 +00:00
|
|
|
const chai = require('chai');
|
|
|
|
const dirtyChai = require('dirty-chai');
|
|
|
|
const expect = chai.expect;
|
2016-04-27 22:55:57 +00:00
|
|
|
chai.use(dirtyChai);
|
|
|
|
|
2019-11-17 19:19:25 +00:00
|
|
|
const Bootstrapper = require('../lib/bootstrapper');
|
2016-04-27 22:55:57 +00:00
|
|
|
|
|
|
|
describe('Bootstrapper', function() {
|
2019-11-17 19:19:25 +00:00
|
|
|
let app;
|
2016-04-27 22:55:57 +00:00
|
|
|
beforeEach(function() {
|
|
|
|
app = loopback();
|
|
|
|
process.bootFlags = [];
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should honor options.phases', function(done) {
|
2019-11-17 19:19:25 +00:00
|
|
|
const options = {
|
2016-04-27 22:55:57 +00:00
|
|
|
app: app,
|
|
|
|
appRootDir: path.join(__dirname, './fixtures/simple-app'),
|
|
|
|
phases: ['load'],
|
|
|
|
};
|
|
|
|
|
2019-11-17 19:19:25 +00:00
|
|
|
const bootstrapper = new Bootstrapper(options);
|
2016-04-27 22:55:57 +00:00
|
|
|
|
2019-11-17 19:19:25 +00:00
|
|
|
const context = {
|
2016-04-27 22:55:57 +00:00
|
|
|
app: app,
|
|
|
|
};
|
|
|
|
|
|
|
|
bootstrapper.run(context, function(err) {
|
|
|
|
if (err) return done(err);
|
2019-11-17 19:19:25 +00:00
|
|
|
const configs = context.configurations;
|
2016-04-27 22:55:57 +00:00
|
|
|
expect(configs.application, 'application').to.be.an('object');
|
|
|
|
expect(configs.bootScripts, 'bootScripts').to.be.an('array');
|
|
|
|
expect(configs.middleware, 'middleware').to.be.an('object');
|
|
|
|
expect(configs.models, 'models').to.be.an('object');
|
|
|
|
expect(configs.tracker, 'tracker').to.eql('load');
|
|
|
|
expect(context.instructions, 'instructions').to.be.undefined();
|
|
|
|
expect(process.bootFlags.length).to.eql(0);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should honor options.plugins', function(done) {
|
2019-11-17 19:19:25 +00:00
|
|
|
const options = {
|
2016-04-27 22:55:57 +00:00
|
|
|
app: app,
|
|
|
|
appRootDir: path.join(__dirname, './fixtures/simple-app'),
|
|
|
|
plugins: ['application', 'boot-script'],
|
|
|
|
};
|
|
|
|
|
2019-11-17 19:19:25 +00:00
|
|
|
const bootstrapper = new Bootstrapper(options);
|
2016-04-27 22:55:57 +00:00
|
|
|
|
2019-11-17 19:19:25 +00:00
|
|
|
const context = {
|
2016-04-27 22:55:57 +00:00
|
|
|
app: app,
|
|
|
|
};
|
|
|
|
|
|
|
|
bootstrapper.run(context, function(err) {
|
|
|
|
if (err) return done(err);
|
2019-11-17 19:19:25 +00:00
|
|
|
const configs = context.configurations;
|
|
|
|
const instructions = context.instructions;
|
2016-04-27 22:55:57 +00:00
|
|
|
expect(configs.application, 'application').to.be.an('object');
|
|
|
|
expect(configs.middleware, 'middleware').to.be.undefined();
|
|
|
|
expect(configs.models, 'models').to.be.undefined();
|
|
|
|
expect(configs.bootScripts, 'bootScripts').to.be.an('array');
|
|
|
|
expect(instructions.application, 'application').to.be.an('object');
|
|
|
|
expect(instructions.tracker, 'instruction: tracker').to.eql('compile');
|
|
|
|
expect(context.executions.tracker, 'execution: tracker').to.eql('start');
|
2018-07-23 18:26:47 +00:00
|
|
|
expect(process.bootFlags, 'process: bootFlags').to.eql([
|
|
|
|
'barLoaded',
|
2016-04-27 22:55:57 +00:00
|
|
|
'barSyncLoaded',
|
|
|
|
'fooLoaded',
|
2018-07-23 18:26:47 +00:00
|
|
|
'promiseLoaded',
|
|
|
|
'thenableLoaded',
|
2016-04-27 22:55:57 +00:00
|
|
|
'barStarted',
|
|
|
|
'barFinished',
|
|
|
|
'barSyncExecuted',
|
2018-07-23 18:26:47 +00:00
|
|
|
'promiseStarted',
|
|
|
|
'promiseFinished',
|
|
|
|
'thenableStarted',
|
|
|
|
'thenableFinished',
|
2018-06-17 16:14:52 +00:00
|
|
|
'umdLoaded',
|
2016-04-27 22:55:57 +00:00
|
|
|
]);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-08 09:29:59 +00:00
|
|
|
it('searches boot file extensions specified in options.scriptExtensions',
|
2018-07-23 18:26:47 +00:00
|
|
|
function(done) {
|
2019-11-17 19:19:25 +00:00
|
|
|
const options = {
|
2018-07-23 18:26:47 +00:00
|
|
|
app: app,
|
|
|
|
appRootDir: path.join(__dirname, './fixtures/simple-app'),
|
|
|
|
scriptExtensions: ['.customjs', '.customjs2'],
|
|
|
|
};
|
|
|
|
|
2019-11-17 19:19:25 +00:00
|
|
|
const bootstrapper = new Bootstrapper(options);
|
2018-07-23 18:26:47 +00:00
|
|
|
|
2019-11-17 19:19:25 +00:00
|
|
|
const context = {
|
2018-07-23 18:26:47 +00:00
|
|
|
app: app,
|
|
|
|
};
|
|
|
|
|
|
|
|
bootstrapper.run(context, function(err) {
|
|
|
|
if (err) return done(err);
|
|
|
|
expect(process.bootFlags, 'process: bootFlags').to.eql([
|
|
|
|
'customjs',
|
|
|
|
'customjs2',
|
|
|
|
]);
|
|
|
|
done();
|
|
|
|
});
|
2017-03-08 09:29:59 +00:00
|
|
|
});
|
|
|
|
|
2016-04-27 22:55:57 +00:00
|
|
|
afterEach(function() {
|
|
|
|
delete process.bootFlags;
|
|
|
|
});
|
|
|
|
});
|