Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(karma-webpack): handle multiple outputs correctly #357

Merged
merged 4 commits into from
Sep 14, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/karma-webpack.js
Original file line number Diff line number Diff line change
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ensured that this.outputs[file][0] points to the 'correct' file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try it it with e.g source maps enabled and/or extracting CSS ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it with both cases, it works very well :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright :), I need to rely upon you here since this module has no test 😥

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, It seems that it is not always the case for some webpack config :(
So i had to fix this in #360

}else{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- }else{
+ } 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 @@ -254,7 +258,11 @@ Plugin.prototype.readFile = function(file, callback) {
})
} else {
try {
var fileContents = middleware.fileSystem.readFileSync(path.join(os.tmpdir(), '_karma_webpack_', this.outputs[file]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var fileContents = ''

if (condition) {
  fileContents = ...
} else {
  fileContents = ...
}

if (Array.isArray(this.outputs[file])) {
var fileContents = middleware.fileSystem.readFileSync(path.join(os.tmpdir(), '_karma_webpack_', this.outputs[file][0]));
} else {
var fileContents = middleware.fileSystem.readFileSync(path.join(os.tmpdir(), '_karma_webpack_', this.outputs[file]));
}

callback(undefined, fileContents)
} catch (e) {
Expand Down Expand Up @@ -297,7 +305,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