Path errors on windows
See original GitHub issueDescribe the bug
Getting the following error messages when running in a test environment when doing server.use(rest.get(…)) after setting up. Works first but throws error when trying to change a route to return something else after initialization.
Invalid URI "c:/Users/..projectdir../services/web/src/util/toastr.js"
at Request.init (node_modules/request/request.js:273:31)
at new Request (node_modules/request/request.js:127:8)
at request (node_modules/request/index.js:53:10)
at Object.createClient (node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:358:29)
at XMLHttpRequestImpl.send (node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:642:31)
at XMLHttpRequest.send (node_modules/jsdom/lib/jsdom/living/generated/XMLHttpRequest.js:309:34)
at node_modules/node-request-interceptor/src/interceptors/XMLHttpRequest/XMLHttpRequestOverride.ts:387:29
and the same error for /node_modules/stacktrace-js/stacktrace.js, node_modules/jquery/dist/jquery.js, /node_modules/node-request-interceptor/src/interceptors/XMLHttpRequest/XMLHttpRequestOverride.ts etc.
Environment
- OS: windows 10
msw: 0.26.2
nodejs: 12.13.0
npm: 6.14.11
Please also provide your browser version. Using on CL
To Reproduce
Steps to reproduce the behavior:
- setup server
- after setting up and listen() , do server.use(rest.get(…))
Expected behavior
it should work, works on coworkers machine with everything the same (node version, npm, lib version (same repo)). Only difference is he is using OSX and me windows 10. Works in the pipeline as well running linux.
Screenshots
If applicable, add screenshots to help explain your problem.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
I’ve tried this on Windows 10 and din’t experience the issue. Here’s the test file:
The test passes successfully. It must have been something in your configuration that made relative request URLs in tests resolve against your
process.cwd()
.I can give it a try on a Windows machine and update this issue. From the error message, it seems that there was an attempt to create a URL instance from a relative path that was resolved against your
process.cwd
or similar. MSW doesn’t handle relative URL paths in Node.js, JSDOM (or another DOM-like environment) does. Since Jest polyfillswindow.location
, relative URLs get resolved against the stub, which I believe ishttp://localhost
. In pure Node.js relative URLs cannot exist (nothing to be relative to).Most likely the issue was indeed somewhere in your setup. @sebwalle thank you for looking into it. Could you please update us on what caused this issue? It’d be useful for posterity.