Skip to content

Commit

Permalink
fix(karma-webpack): Do not unify "colors" property if webpack "stats"…
Browse files Browse the repository at this point in the history
… is a string (#376)

Fixes a regression introduced in 9559306
Fixes #375
  • Loading branch information
matthieu-foucault authored Nov 30, 2018
1 parent c7d6ca1 commit 840dea2
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/karma-webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 840dea2

Please sign in to comment.