Skip to content

Commit

Permalink
fix(karma-webpack): handle multiple outputs correctly (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
alabbas-ali authored and michael-ciniawsky committed Sep 14, 2018
1 parent 9807b06 commit 59de62c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/karma-webpack.js
Expand Up @@ -237,7 +237,11 @@ Plugin.prototype.readFile = function(file, callback) {
var doRead = function() {
if (optionsCount > 1) {
async.times(optionsCount, function(idx, callback) {
middleware.fileSystem.readFile(path.join(os.tmpdir(), '_karma_webpack_', String(idx), this.outputs[file]), callback)
if (Array.isArray(this.outputs[file])) {
middleware.fileSystem.readFile(path.join(os.tmpdir(), '_karma_webpack_', String(idx), this.outputs[file][0]), callback);
} else {
middleware.fileSystem.readFile(path.join(os.tmpdir(), '_karma_webpack_', String(idx), this.outputs[file]), callback);
}
}.bind(this), function(err, contents) {
if (err) {
return callback(err)
Expand All @@ -253,8 +257,13 @@ Plugin.prototype.readFile = function(file, callback) {
callback(null, Buffer.concat(contents))
})
} else {
try {
var fileContents = middleware.fileSystem.readFileSync(path.join(os.tmpdir(), '_karma_webpack_', this.outputs[file]))
try {
var fileContents = ''
if (Array.isArray(this.outputs[file])) {
fileContents = middleware.fileSystem.readFileSync(path.join(os.tmpdir(), '_karma_webpack_', this.outputs[file][0]));
} else {
fileContents = middleware.fileSystem.readFileSync(path.join(os.tmpdir(), '_karma_webpack_', this.outputs[file]));
}

callback(undefined, fileContents)
} catch (e) {
Expand Down Expand Up @@ -297,7 +306,11 @@ function createPreprocesor(/* config.basePath */ basePath, webpackPlugin) {
}

var outputPath = webpackPlugin.outputs[normalize(filename)]
file.path = normalize(path.join(basePath, outputPath))
if( Array.isArray(outputPath)){
file.path = normalize(path.join(basePath, outputPath[0]));
} else {
file.path = normalize(path.join(basePath, outputPath));
}

done(err, content && content.toString())
})
Expand Down

0 comments on commit 59de62c

Please sign in to comment.