Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): log error when file loading or preprocessing fails #3540

Merged
merged 1 commit into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ class Server extends KarmaEventEmitter {
})
}

fileList.refresh().then(afterPreprocess, afterPreprocess)
fileList.refresh().then(afterPreprocess, (err) => {
this.log.error('Error during file loading or preprocessing\n' + err.stack || err)
afterPreprocess()
})

this.on('browsers_change', () => socketServer.sockets.emit('info', capturedBrowsers.serialize()))

Expand Down
7 changes: 6 additions & 1 deletion test/unit/server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const BundleUtils = require('../../lib/utils/bundle-utils')
const NetUtils = require('../../lib/utils/net-utils')
const BrowserCollection = require('../../lib/browser_collection')
const Browser = require('../../lib/browser')
const logger = require('../../lib/logger')

describe('server', () => {
let mockConfig
Expand All @@ -16,6 +17,7 @@ describe('server', () => {
let mockBoundServer
let mockExecutor
let doneSpy
let logErrorSpy
let server = mockConfig = browserCollection = webServerOnError = null
let fileListOnResolve = fileListOnReject = mockLauncher = null
let mockFileList = mockWebServer = mockSocketServer = mockExecutor = doneSpy = null
Expand All @@ -27,6 +29,7 @@ describe('server', () => {
this.timeout(4000)
browserCollection = new BrowserCollection()
doneSpy = sinon.spy()
logErrorSpy = sinon.spy(logger.create('karma-server'), 'error')

fileListOnResolve = fileListOnReject = null

Expand Down Expand Up @@ -213,10 +216,12 @@ describe('server', () => {
expect(mockWebServer.listen).not.to.have.been.called
expect(server._injector.invoke).not.to.have.been.calledWith(mockLauncher.launch, mockLauncher)

fileListOnReject()
const fileListRefreshError = new Error('file-list refresh error')
fileListOnReject(fileListRefreshError)
expect(mockWebServer.listen).to.have.been.calledWith(mockBoundServer, sinon.match.func)
expect(webServerOnError).not.to.be.null
expect(server._injector.invoke).to.have.been.calledWith(mockLauncher.launch, mockLauncher)
expect(logErrorSpy).to.have.been.calledWith('Error during file loading or preprocessing\n' + fileListRefreshError.stack)
})

it('should launch browsers after the web server has started', async () => {
Expand Down