-
Notifications
You must be signed in to change notification settings - Fork 222
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
fix(karma-webpack): handle multiple outputs correctly #357
Conversation
I do wonder if it'd make more sense to do the check when populating the If you can safely assume that the first entry is always the one we want, i would consider just adding the first one to the map and leave the existing code as is. Are we sure that the first entry will always be right, too? |
the first entry is always the js file, the second entry may be the map file or CSS file etc.. depending on the configuration of webpack. but the first entry is always the chank JS file. I think this is what we want to test. If I am not mistaken |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 One clearification and two nits
src/karma-webpack.js
Outdated
@@ -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])) |
There was a problem hiding this comment.
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 = ...
}
@@ -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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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 😥
There was a problem hiding this comment.
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
src/karma-webpack.js
Outdated
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{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- }else{
+ } else {
src/karma-webpack.js
Outdated
@@ -254,7 +258,13 @@ Plugin.prototype.readFile = function(file, callback) { | |||
}) | |||
} else { | |||
try { | |||
var fileContents = middleware.fileSystem.readFileSync(path.join(os.tmpdir(), '_karma_webpack_', this.outputs[file])) | |||
|
|||
var fileContents = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent seems to be off here :)
@alabbas-ali Would you mind sending a PR with these changes for |
src/karma-webpack.js
Outdated
|
||
var fileContents = '' | ||
try { | ||
var fileContents = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still off 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe my editor is off 🔢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alabbas-ali Thx
Released in |
I did more testing, with different config, unfortunately, I found out that the assumption "that the first file is the JS" is not the case always, So I had to fix this please check out #360 |
Could we also uplift this to the 4.x branch too? |
Ping? This is blocking us updating to 4.x, since otherwise we get:
|
I create a pull request out of it #361. but please review #360 before. |
Is this going to be included in the next 4.x release? |
Can this be released? |
Thank you, it works for me now! +1 |
When configuring Webpack to compile ts, the output is array and karma-webpack throw Exception like
Type
Issues
SemVer