From 94a226dffc729e110ff6b89b50f8ff5db55f81bd Mon Sep 17 00:00:00 2001 From: Matthias Osswald Date: Thu, 16 Jul 2020 12:57:18 +0200 Subject: [PATCH] fix(server): log error when file loading or preprocessing fails --- lib/server.js | 5 ++++- test/unit/server.spec.js | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/server.js b/lib/server.js index e79a2aa22..9a9a5b7c3 100644 --- a/lib/server.js +++ b/lib/server.js @@ -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())) diff --git a/test/unit/server.spec.js b/test/unit/server.spec.js index a7761bdd8..b66c9ab37 100644 --- a/test/unit/server.spec.js +++ b/test/unit/server.spec.js @@ -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 @@ -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 @@ -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 @@ -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 () => {