Code coverage in e2e tests
See original GitHub issueBug Report
Current behavior
Collecting coverage on e2e test results in no files covered.
Input Code
By using
nest new project-name
Then in test/jest-e2e.json add key “collectCoverage”: true
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverage": true
}
Then run
npm run test:e2e
Expected behavior
Code coverage should be shown from app.controller.ts and app.service.ts.
Possible Solution
It seems as the module fixture is not being imported for tracking by jest.
Environment
Nest version: 6.10.1
For Tooling issues:
- Node version: v12.10.0
- Platform: Mac
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Measuring code coverage in end-to-end tests?
Knowing code coverage for unit tests is very valuable, because we can see what code is not covered by tests & design tests...
Read more >Measuring (code / feature) coverage from your e2e tests (Talk ...
In computer science, test coverage is a measure used to describe the degree to which the source code of a program is executed...
Read more >Code Coverage - Cypress Documentation
E2E code coverage ... To handle code coverage collected during each test, we created a @cypress/code-coverage Cypress plugin. It merges coverage from each...
Read more >Code coverage of E2E tests with Playwright | by Luděk Nový
The code coverage metric is widely connected with unit tests. Primarily because it is easy to measure it for unit tests and every...
Read more >Test Coverage Demystified: A Complete Introductory Guide
Unit tests won't help you verify that the application integrates correctly with external systems. · E2E tests don't lend themselves easily to ...
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 Free
Top 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
I solved this as follows:
Move
jest-e2e.json
from thetest
directory to the root directory of the project (wherepackage.json
is located)Change the contents of
jest-e2e.json
to the following:test:e2e
script insidepackage.json
to:Now running the
test:e2e
script with the--coverage
flag should generate the required coverage inside thecoverage-e2e
directory.This was solved by switching over jest to mocha and using yarn instead of npm.