-
Notifications
You must be signed in to change notification settings - Fork 109
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
Component tests with create-react-app (react-scripts-v4) don't instrument #461
Comments
UPDATE: After a bit of digging, I've found that the window.coverage object is missing from the output of the |
I've tried using the
Same goes for the webpack pre-processor with |
Okay, I've resolved my issue! Following the docs, you most likely end up with a
The file:preprocessor step does not work. Instead, I found that spinning up a custom webpack dev server using the Cypress presets and loading the Here is my current
|
@twhoff thank you so much for this post! Just got coverage working for my component tests using your strat here :) |
Glad I could help! |
Another thank you here @twhoff! Spent all morning trying to get this to work before coming across your config file. |
@twhoff, your resource was the most relevant and best one in an internet scattered with loose solutions on this problem. I took some ideas and tried them out but could not get it working in my repro (small differences in that it's not a CRA and just a component library using Cypress for unit tests). I know you are busy, but if there are any similarities and your deeper experience on the problem, could you point me on what else I may have to do to get my minimal repro working in #472? Thanks a lot! |
@twhoff Thank you for example, it works like a charm. |
Thank you @twhoff I have wasted so much time and this worked perfectly - I should have checked the issues as soon as it didn't work! |
I've been trying to get code coverage working for the last few days using the fragments of documentation I can find throughout the Cypress offical site and code repos...
App is CRA
Using @cypress/instrument-cra@latest
Using example react-scripts-v4
Simple test using Card.js
Card.test.js
cypress.json
plugins/index.js
support/index.js
package.json
Basically I do this:
The out.json in
.nyc_output/out.json
just contains an empty object{}
I should also note that when I do
yarn start
and checkwindow.__coverage__
in the web console, it shows the expected output. The issue is when I run the component tests, the nyc output doesn't have any coverage info.The text was updated successfully, but these errors were encountered: