Skip to content

Commit

Permalink
fix(server): exit with code 1 when failing due to missing browser
Browse files Browse the repository at this point in the history
Closes #2403
  • Loading branch information
maksimr authored and dignifiedquire committed Dec 2, 2016
1 parent 7d2c1ae commit 86e2ef2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ Server.prototype._start = function (config, launcher, preprocess, fileList,
var noLoadErrors = self.loadErrors.length
if (noLoadErrors > 0) {
self.log.error('Found %d load error%s', noLoadErrors, noLoadErrors === 1 ? '' : 's')
process.exitCode = 1
process.kill(process.pid, 'SIGINT')
}
})
Expand Down Expand Up @@ -392,7 +393,9 @@ Server.prototype._start = function (config, launcher, preprocess, fileList,
})
}

processWrapper.on('SIGINT', disconnectBrowsers)
processWrapper.on('SIGINT', function () {
disconnectBrowsers(process.exitCode)
})
processWrapper.on('SIGTERM', disconnectBrowsers)

// Handle all unhandled exceptions, so we don't just exit but
Expand Down
18 changes: 17 additions & 1 deletion test/unit/server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('server', () => {
callback && callback()
}),
removeAllListeners: () => {},
close: () => {}
close: sinon.spy(callback => callback && callback())
}

sinon.stub(server._injector, 'get')
Expand Down Expand Up @@ -195,6 +195,22 @@ describe('server', () => {
server.emit('browser_register', {})
expect(browsersReady).to.have.been.called
})

it('should exit with error exit code on load errors', (done) => {
mockProcess(process)

server._start(mockConfig, mockLauncher, null, mockFileList, browserCollection, mockExecutor, (exitCode) => {
expect(exitCode).to.have.equal(1)
done()
})

server.loadErrors.push(['TestError', 'Test'])
fileListOnResolve()

function mockProcess (process) {
sinon.stub(process, 'kill', (pid, ev) => process.emit(ev))
}
})
})

describe.skip('singleRun', () => {
Expand Down

0 comments on commit 86e2ef2

Please sign in to comment.