nx: Cypress Component testing not able to load assets
I originally posted this issue on Cypress with Cypress component tests not being able to load assets, which is working now for Cypress and Angular CLI projects. However, it breaks with Nx and the Nx Cypress runner + component test config.
Current Behavior
Can’t load assets eg. icons from Angular material registry loader.
This works for a Cypress component test project without Nx though: https://github.com/lydemann/cypress-assets-bug/tree/master
Expected Behavior
Should be able to load assets
Steps to Reproduce
- Create Nx Angular project
- Set up Cypress component testing with Nx component test config for app
- Create a test that loads a custom Angular material icon
- Run the test and see that it fails
Demo repo: https://github.com/lydemann/cypress-assets-bug/tree/nx
This issue may not be prioritized if details are not provided to help us reproduce the issue.
Failure Logs
Environment
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 16 (5 by maintainers)
Okay folks I think we got the root issue. I still have a handful of things I need to test, but I at least understand what the issues is.
Basically cypress opens in the Nx project root. but when in an angular cli project it opens in the
workspaceRoot(root of the repo). The component-testing preset for angular provides the path offsets to correctly resolve paths which seem to have only been kind of working. As within the@cypress/webpack-dev-serverpackage the pathing causes the angular webpack utils to use the project root as the workspace root so while it’s able to build the webpack config the assets get mapped to a different url where they aren’t getting proxied as expected. i.e.__cypress/src/assetsinstead ofassetsI’ll make a PR to Cypress that will allow nx to provide it’s own workspace root to use which should fix the issue. I still have a bunch of testing I need to do to make sure this will in fact fix the issues for both app and lib project component testing without breaking existing angular cli workspace testing. This fix also requires some change on the Nx side so all of that will be get coordinated and I’ll keep y’all updated on where everything lands.
Please retry with latest Nx and Cypress. I believe the issue has been resolved as I cannot reproduce the issue any more. Things I’ve tried is using stylePreprocessorOptions/img tag asset loading, HttpClient asset load all work across libs/apps.
Here is the repo I used for reference. https://github.com/barbados-clemens/cy-asset-style-demo
I’m going to mark the issue as blocked until there is a repro that shows this not working on Nx v15.6+ and Cypres v12.3+.
Odds are this was an issue in cypress v10/v11 but was fixed in v12 and/or in combination with angular v15.
I’ll still work on making some e2e tests in the Nx repo to make sure this doesn’t regress and to fix a couple other smaller issues like
you might see when using component testing but major issues of asset loading look to be resolved.
@barbados-clemens i can send you zipped code on slack if you want?
do you have a repo I can look at @jerkovicl?
I think I’ve tracked down to the actual values angular uses and working on understanding more of the problem.
from what i’ve seen the default
"apps/demo/src/assets"turns intoand
is turning into
under the hood in the angular builder.
so when running Cypress CT the path to assets is mapped to
src/assetsinstead of justassetsOr at least that’s where I ended yesterday off and working on debugging more today to see what exactly is happening.