Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Merge dfaa444 into 602ac6f
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainLanz committed Aug 23, 2019
2 parents 602ac6f + dfaa444 commit 5152e8b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/Ignitor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Ignitor {
this._appRoot = null
this._modulesRoot = null
this._loadCommands = false
this.environment = null

/**
* Files to be preloaded
Expand All @@ -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'
]

Expand Down Expand Up @@ -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)

/**
Expand Down Expand Up @@ -807,6 +820,8 @@ class Ignitor {
* @return {void}
*/
async fireHttpServer (httpServerCallback) {
this.environment = 'http'

try {
await this.fire()
await this._startHttpServer(httpServerCallback)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/ignitor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down

0 comments on commit 5152e8b

Please sign in to comment.