Cypress rewrites window.top.location during test and causes issues
See original GitHub issueCurrent behavior
While running our test, we encounter the following cypress error. We have searched the issues for a solution and we have encountered this one. We made use of cypress version 7.3.0 as seen in the stack trace but it seems that we still encounter this issue.
Error: Webpack Compilation Error
multi .
Module not found: Error: Can't resolve 'C:\Users\User\Desktop\automation-myProjectName' in 'C:\Users\User\Desktop\automation-myProjectName'
Looked for and couldn't find the file at the following paths:
[C:\Users\User\Desktop\automation-myProjectName]
[C:\Users\User\Desktop\automation-myProjectName.js]
[C:\Users\User\Desktop\automation-myProjectName.json]
[C:\Users\User\Desktop\automation-myProjectName.jsx]
[C:\Users\User\Desktop\automation-myProjectName.mjs]
[C:\Users\User\Desktop\automation-myProjectName.coffee]
[C:\Users\User\Desktop\automation-myProjectName.ts]
[C:\Users\User\Desktop\automation-myProjectName.tsx]
[C:\Users\User\Desktop\automation-myProjectName\index.js]
[C:\Users\User\Desktop\automation-myProjectName\index.js.js]
[C:\Users\User\Desktop\automation-myProjectName\index.js.json]
[C:\Users\User\Desktop\automation-myProjectName\index.js.jsx]
[C:\Users\User\Desktop\automation-myProjectName\index.js.mjs]
[C:\Users\User\Desktop\automation-myProjectName\index.js.coffee]
[C:\Users\User\Desktop\automation-myProjectName\index.js.ts]
[C:\Users\User\Desktop\automation-myProjectName\index.js.tsx]
[C:\Users\User\Desktop\automation-myProjectName\index]
[C:\Users\User\Desktop\automation-myProjectName\index.json]
[C:\Users\User\Desktop\automation-myProjectName\index.jsx]
[C:\Users\User\Desktop\automation-myProjectName\index.mjs]
[C:\Users\User\Desktop\automation-myProjectName\index.coffee]
[C:\Users\User\Desktop\automation-myProjectName\index.ts]
[C:\Users\User\Desktop\automation-myProjectName\index.tsx]
at Watching.handle [as handler] (C:\Users\User\AppData\Local\Cypress\Cache\7.3.0\Cypress\resources\app\packages\server\node_modules\@cypress\webpack-preprocessor\dist\index.js:172:23)
at C:\Users\User\AppData\Local\Cypress\Cache\7.3.0\Cypress\resources\app\packages\server\node_modules\webpack\lib\Watching.js:99:9
at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\User\AppData\Local\Cypress\Cache\7.3.0\Cypress\resources\app\packages\server\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (C:\Users\User\AppData\Local\Cypress\Cache\7.3.0\Cypress\resources\app\packages\server\node_modules\tapable\lib\Hook.js:154:20)
at Watching._done (C:\Users\User\AppData\Local\Cypress\Cache\7.3.0\Cypress\resources\app\packages\server\node_modules\webpack\lib\Watching.js:98:28)
at C:\Users\User\AppData\Local\Cypress\Cache\7.3.0\Cypress\resources\app\packages\server\node_modules\webpack\lib\Watching.js:73:19
at Compiler.emitRecords (C:\Users\User\AppData\Local\Cypress\Cache\7.3.0\Cypress\resources\app\packages\server\node_modules\webpack\lib\Compiler.js:499:39)
at C:\Users\User\AppData\Local\Cypress\Cache\7.3.0\Cypress\resources\app\packages\server\node_modules\webpack\lib\Watching.js:54:20
at C:\Users\User\AppData\Local\Cypress\Cache\7.3.0\Cypress\resources\app\packages\server\node_modules\webpack\lib\Compiler.js:485:14
at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\User\AppData\Local\Cypress\Cache\7.3.0\Cypress\resources\app\packages\server\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (C:\Users\User\AppData\Local\Cypress\Cache\7.3.0\Cypress\resources\app\packages\server\node_modules\tapable\lib\Hook.js:154:20)
at C:\Users\User\AppData\Local\Cypress\Cache\7.3.0\Cypress\resources\app\packages\server\node_modules\webpack\lib\Compiler.js:482:27
at C:\Users\User\AppData\Local\Cypress\Cache\7.3.0\Cypress\resources\app\packages\server\node_modules\neo-async\async.js:2818:7
at done (C:\Users\User\AppData\Local\Cypress\Cache\7.3.0\Cypress\resources\app\packages\server\node_modules\neo-async\async.js:3522:9)
at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\User\AppData\Local\Cypress\Cache\7.3.0\Cypress\resources\app\packages\server\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (C:\Users\User\AppData\Local\Cypress\Cache\7.3.0\Cypress\resources\app\packages\server\node_modules\tapable\lib\Hook.js:154:20)
Desired behavior
We do not want cypress to redirect on window.top.location.hash changes.
Test code to reproduce
var loc = window.location;
hash = hash.replace(hashRe, me.hashbang ? '#!' : '#');
if (replace) {
loc.replace(hash);
} else {
loc.hash = hash;
}
Our test does the following:
cy.visit("https://localhost");
Versions
We started having this issue while using cypress 5.3.0 and Chrome 89. We have upgraded to cypress 7.3.0 and Chrome 91, but we still encounter the same, albeit the stack trace has some more data. We also just upgraded to cypress 7.5.0 and Chrome 91, but the issue is still there.
Operating System: Windows 10
Issue Analytics
- State:
- Created 2 years ago
- Reactions:20
- Comments:11 (1 by maintainers)
Top Results From Across the Web
testing - document.location.href in my code behaves differently ...
This is a cypress command, but I'm talking about application code, not test code. I don't think that I should call cypress command...
Read more >Best Practices - Cypress Documentation
In February 2018 we gave a "Best Practices" conference talk at AssertJS. This video demonstrates how to approach writing fast, scalable tests.
Read more >click - Cypress Documentation
The position where the click should be issued. The center position is the default position. Valid positions are topLeft , top , topRight...
Read more >Using Cypress - Cypress Documentation
Can I test the HTML <head> element? Yes, you sure can. While executing tests, you can view the entire window.document object in your...
Read more >Troubleshooting | Cypress Documentation
In some cases the Command Log, responsible for displaying test commands, assertions, and statuses in the Cypress Test Runner, may cause performance issues...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
+1 this happens to me as well it seems like cypress is having troubles sometimes wrapping location during the runner and it redirects outside of the app/test.
I am also getting the same “Error: Webpack Compilation Error” posted above in an ExtJS application as soon as I click on anything within the application.
If I turn on both
modifyObstructiveCode
andexperimentalSourceRewriting
in my cypress.json file as per a suggestion in #8507 I can get past the above error for one click but then I receive a different error (below) if I subsequently click anything else. If I only turn on one flag or the other then I still end up with the same Webpack error above on the first click within the app.Second error with
modifyObstructiveCode
andexperimentalSourceRewriting
both set to true and clicking a second target:TypeError The following error originated from your application code, not from Cypress. Uncaught TypeError: globalThis.top.Cypress.resolveWindowReference(...).on is not a function cypress_runner.js:141919
Unfortunately, I also cannot provide a reproducible sample because my app is not public. As hiezust mentioned, this appears to be an issue with the way ExtJS uses window.top.location.hash for routing not playing well with Cypress rewriting those attributes.