From 840dea2f24594b9fbc813e89a4c59837fdc0fb33 Mon Sep 17 00:00:00 2001 From: Matthieu Foucault Date: Fri, 30 Nov 2018 10:05:53 -0800 Subject: [PATCH] fix(karma-webpack): Do not unify "colors" property if webpack "stats" is a string (#376) Fixes a regression introduced in 9559306 Fixes #375 --- src/karma-webpack.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/karma-webpack.js b/src/karma-webpack.js index e01bd44..b047da3 100644 --- a/src/karma-webpack.js +++ b/src/karma-webpack.js @@ -21,16 +21,16 @@ let isBlocked = false; const normalize = (file) => file.replace(/\\/g, '/'); const getOutputPath = (outputPath) => { - for (var i = 0; i < outputPath.length; i++) { + for (let i = 0; i < outputPath.length; i++) { if ( - outputPath[i].indexOf(".js") !== -1 && - outputPath[i].indexOf(".js.map") === -1 + outputPath[i].indexOf('.js') !== -1 && + outputPath[i].indexOf('.js.map') === -1 ) { return outputPath[i]; } } return null; -} +}; const escapeRegExp = function(str) { // See details here https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex @@ -181,7 +181,7 @@ function Plugin( if (this.entries.has(entry)) { const entryPath = this.entries.get(entry); let outputPath = stats.assetsByChunkName[entry]; - + if (Array.isArray(outputPath)) { outputPath = getOutputPath(outputPath); } @@ -229,8 +229,11 @@ function Plugin( webpackMiddlewareOptions.publicPath = '/_karma_webpack_/'; // Set webpack's color config to value specified in Karma's config for consistency - webpackMiddlewareOptions.stats = webpackMiddlewareOptions.stats || {}; - webpackMiddlewareOptions.stats.colors = colors; + if (typeof webpackMiddlewareOptions.stats !== 'string') { + // stats can be either a string or an object + webpackMiddlewareOptions.stats = webpackMiddlewareOptions.stats || {}; + webpackMiddlewareOptions.stats.colors = colors; + } const middleware = new WebpackDevMiddleware( compiler,