Collecting coverage on e2e test results in no files covered.
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
Code coverage should be shown from app.controller.ts and app.service.ts.
It seems as the module fixture is not being imported for tracking by jest.
Nest version: 6.10.1
For Tooling issues:
- Node version: v12.10.0
- Platform: Mac
Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.
This was solved by switching over jest to mocha and using yarn instead of npm.
I solved this as follows:
Move jest-e2e.json from the test directory to the root directory of the project (where package.json is located)
Change the contents of jest-e2e.json to the following:
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testMatch": ["<rootDir>/test/**/*.e2e-spec.{ts,js}"],
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"coverageDirectory": "./coverage-e2e"
}
test:e2e script inside package.json to:"test:e2e": "jest --config ./jest-e2e.json"
Now running the test:e2e script with the --coverage flag should generate the required coverage inside the coverage-e2e directory.
Most helpful comment
I solved this as follows:
Move
jest-e2e.jsonfrom thetestdirectory to the root directory of the project (wherepackage.jsonis located)Change the contents of
jest-e2e.jsonto the following:test:e2escript insidepackage.jsonto:Now running the
test:e2escript with the--coverageflag should generate the required coverage inside thecoverage-e2edirectory.