From fc2fd6102a1c6ed2972ab5bdec29d8747f1b8e64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20O=C3=9Fwald?= <1410947+matz3@users.noreply.github.com> Date: Mon, 10 Aug 2020 23:28:27 +0200 Subject: [PATCH] fix(server): log error when file loading or preprocessing fails (#3540) --- 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 597404ce0..e8089ca46 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 () => {