From dfaa4449455eb1ca2c5cca5a57a0c67278da30e3 Mon Sep 17 00:00:00 2001 From: Romain Lanz Date: Fri, 23 Aug 2019 21:20:13 +0200 Subject: [PATCH] feat(ignitor): add loadOnlyOnHttp file list --- src/Ignitor/index.js | 24 ++++++++++++++++++++++-- test/ignitor.spec.js | 10 ++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/Ignitor/index.js b/src/Ignitor/index.js index 59d1f90..f5a6903 100644 --- a/src/Ignitor/index.js +++ b/src/Ignitor/index.js @@ -49,6 +49,7 @@ class Ignitor { this._appRoot = null this._modulesRoot = null this._loadCommands = false + this.environment = null /** * Files to be preloaded @@ -58,8 +59,16 @@ class Ignitor { this._preLoadFiles = [ 'start/routes', 'start/events', + 'start/kernel' + ] + + /** + * Files to be preloaded only on Http + * + * @type {Array} + */ + this._preLoadOnHttpOnly = [ 'start/socket', - 'start/kernel', 'start/wsKernel' ] @@ -365,7 +374,11 @@ class Ignitor { debug('preloading files %j', this._preLoadFiles) debug('optional set %j', this._optionals) - this._preLoadFiles.forEach((file) => { + const isHttp = this.environment === 'http' + const isTesting = process.env.NODE_ENV === 'testing' + const filesToPreload = this._preLoadFiles.concat(isHttp || isTesting ? this._preLoadOnHttpOnly : []) + + filesToPreload.forEach((file) => { const filePath = path.isAbsolute(file) ? file : path.join(this._appRoot, file) /** @@ -807,6 +820,8 @@ class Ignitor { * @return {void} */ async fireHttpServer (httpServerCallback) { + this.environment = 'http' + try { await this.fire() await this._startHttpServer(httpServerCallback) @@ -836,6 +851,11 @@ class Ignitor { process.env.NODE_ENV = 'testing' } + /** + * Setting the environment + */ + this.environment = 'ace' + /** * Load database/factory.js file when loading * ace commands diff --git a/test/ignitor.spec.js b/test/ignitor.spec.js index 15b2c54..8065bfc 100644 --- a/test/ignitor.spec.js +++ b/test/ignitor.spec.js @@ -239,6 +239,16 @@ test.group('Ignitor', (group) => { await ignitor.fireHttpServer() }) + test('do not load http only files when firing ace', async (assert) => { + const ignitor = new Ignitor(fold) + ignitor.appRoot(path.join(__dirname, './')) + ignitor._preLoadOnHttpOnly = ['start/emitsError'] + ignitor._startHttpServer = function () {} + ignitor._gracefullyShutDown = function () {} + + await ignitor.fireAce() + }) + test('call preloading hooks', async (assert) => { const ignitor = new Ignitor(fold) const events = []