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): normalize paths (windows) #351

Merged
merged 2 commits into from
Sep 7, 2018

Conversation

Teamop
Copy link
Contributor

@Teamop Teamop commented Sep 3, 2018

With #347 changes, now get error: TypeError: Path must be a string. Received undefined. After my research, there are 3 places will throw this error:

  1. Two in the readFile, L311, L337, both are this.outputs.get(file)
    --- the changes I made here is to map the file path to the entry path, so that can getting the file from the outputs. Example, changes from test\unit\karma-test-shim to test/unit/karma-test-shim

  2. One in the createPreprocesor L386, this line webpackPlugin.outputs.get(filename);
    --- for this one, the file is already the real file path, if replaced with the webpack stats one, the karma web server cannot find the file 404.
    Example here, changes from C:/project/test/unit/karma-test-shim.js to C:\project\test\unit\karma-test-shim.js

Type

  • Fix

Issues

SemVer

  • Patch

@@ -383,9 +387,6 @@ function createPreprocesor(/* config.basePath */ basePath, webpackPlugin) {
throw err;
}

const outputPath = webpackPlugin.outputs.get(filename);
file.path = path.join(basePath, outputPath);
Copy link
Collaborator

Choose a reason for hiding this comment

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

How comes you removed this? It's needed to rewrite the asset path for karma to point to .js if the file extension was .ts for example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, but with this, just for simple js file, the karma web server will not find the file and throw 404

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 to rewrite the file path like the above, but failed, so what do you think here should to do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @rynclark , I tried to add this code back when testing with .ts file, but there's a problem, here path.join(basePath, outputPath) refers to the absolute path in the file system, so that 404, because .js doesn't exist at this basePath, so when replacing with path same aswebpackOptions.output.path = path.join(os.tmpdir(), '_karma_webpack_', indexPath, '/');, still cannot find the compiled .js file

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we move discussion about this into another PR and first of all fix the file path normalization issue as this seems to be critical?

Copy link
Contributor Author

@Teamop Teamop Sep 7, 2018

Choose a reason for hiding this comment

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

I tried with v3.0.3, still needs this L393 changes which normalizes the path again. I have opened a PR #354 for 3.0. @michael-ciniawsky

This comment was marked as resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this PR is ready, with this changs, I have no issues.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

np, thanks @michael-ciniawsky

@thijstriemstra
Copy link

Seeing similar error after upgrading to RC1:

03 09 2018 20:55:24.766:ERROR [karma]: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string
    at assertPath (path.js:39:11)
    at Object.join (path.js:1158:7)
    at Plugin.<anonymous> (/home/foo/projects/bar/node_modules/karma-webpack/lib/karma-webpack.js:284:70)
    at Plugin.readFile (/home/foo/projects/bar/node_modules/karma-webpack/lib/karma-webpack.js:303:5)
    at process._tickCallback (internal/process/next_tick.js:176:11)

@@ -308,7 +308,7 @@ Plugin.prototype.readFile = function(file, callback) {
os.tmpdir(),
'_karma_webpack_',
String(idx),
this.outputs.get(file)
this.outputs.get(file.replace(/\\/g, '/'))
Copy link
Contributor

@michael-ciniawsky michael-ciniawsky Sep 6, 2018

Choose a reason for hiding this comment

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

Please move this into it's own helper

const normalize = (file) => file.replace(/\\/g, '/')

@@ -383,9 +387,6 @@ function createPreprocesor(/* config.basePath */ basePath, webpackPlugin) {
throw err;
}

const outputPath = webpackPlugin.outputs.get(filename);
file.path = path.join(basePath, outputPath);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we move discussion about this into another PR and first of all fix the file path normalization issue as this seems to be critical?

@michael-ciniawsky michael-ciniawsky changed the title fix(karma-webpack): fix output assets path fix(karma-webpack): normalize asset paths Sep 6, 2018
@michael-ciniawsky michael-ciniawsky added this to the 4.0.0 milestone Sep 6, 2018
@michael-ciniawsky michael-ciniawsky changed the title fix(karma-webpack): normalize asset paths fix(karma-webpack): normalize paths (windows) Sep 7, 2018
Copy link
Contributor

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

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

@Teamop 👍 Thx

@@ -383,9 +387,6 @@ function createPreprocesor(/* config.basePath */ basePath, webpackPlugin) {
throw err;
}

const outputPath = webpackPlugin.outputs.get(filename);
file.path = path.join(basePath, outputPath);

This comment was marked as resolved.

@michael-ciniawsky
Copy link
Contributor

Released in 4.0.0-rc.2 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants