A repo to help you with code coverage + cypress
the strategy is:
- instrument your app code so that coverage is generated on
window.__coverage__
- after cypress spec runs, use
cy.writeFile
to save the report to.nyc_output
- and generate the report with
cy.exec('nyc report --reporter=html')
you should then be able the view the html coverage report in the coverage/
directory
Example to show the fix for this specific stackoverflow question
cypress with code coverage set up on a newly-ejected create-react-app
uses:
@babel/preset-typescript
@cypress/webpack-preprocessor
@cypress/webpack-preprocessor
babel-plugin-istanbul
code coverage on a vanilla typescript & webpack project
uses:
@babel/preset-typescript
@cypress/webpack-preprocessor
babel-loader
babel-plugin-istanbul
- example with
ts-loader
- example with bundlers besides webpack
- more tests for edge cases in cypress tests
MIT