loopback-boot/test/bootstrapper.test.js

123 lines
3.5 KiB
JavaScript
Raw Normal View History

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');
2019-11-17 19:19:25 +00:00
const chai = require('chai');
const dirtyChai = require('dirty-chai');
const expect = chai.expect;
chai.use(dirtyChai);
2019-11-17 19:19:25 +00:00
const Bootstrapper = require('../lib/bootstrapper');
describe('Bootstrapper', function() {
2019-11-17 19:19:25 +00:00
let app;
beforeEach(function() {
app = loopback();
process.bootFlags = [];
});
it('should honor options.phases', function(done) {
2019-11-17 19:19:25 +00:00
const options = {
app: app,
appRootDir: path.join(__dirname, './fixtures/simple-app'),
phases: ['load'],
};
2019-11-17 19:19:25 +00:00
const bootstrapper = new Bootstrapper(options);
2019-11-17 19:19:25 +00:00
const context = {
app: app,
};
bootstrapper.run(context, function(err) {
if (err) return done(err);
2019-11-17 19:19:25 +00:00
const configs = context.configurations;
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 = {
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);
2019-11-17 19:19:25 +00:00
const context = {
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;
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',
'barSyncLoaded',
'fooLoaded',
2018-07-23 18:26:47 +00:00
'promiseLoaded',
'thenableLoaded',
'barStarted',
'barFinished',
'barSyncExecuted',
2018-07-23 18:26:47 +00:00
'promiseStarted',
'promiseFinished',
'thenableStarted',
'thenableFinished',
'umdLoaded',
]);
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
});
afterEach(function() {
delete process.bootFlags;
});
});