question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Code coverage in e2e tests

See original GitHub issue

Bug 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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

20reactions
velutcommented, Feb 19, 2020

I solved this as follows:

  1. Move jest-e2e.json from the test directory to the root directory of the project (where package.json is located)

  2. 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"
}
  1. Change the 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.

15reactions
ghostcommented, Oct 20, 2019

This was solved by switching over jest to mocha and using yarn instead of npm.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found