BaconBad
BaconBad

Reputation: 83

Jest --coverage ignores Nest.js controller and service files

I have written tests for a Nest.js project for all controller and service files (which are adhering to the usual myApp.service.ts | myApp.controller.ts naming convention).

I can successfully run all tests for the files, however, when I attempt to generate a coverage report with jest --coverage, controller and service files are omitted (regardless of them being tested or not), while all other files are included, including files following similar naming convention, i.e. myApp.module.ts.

My Jest configuration:

{
  "moduleFileExtensions": [
    "js",
    "json",
    "ts"
],
  "rootDir": "src",
  "testRegex": ".*\\.spec\\.ts$",
  "transform": {
    "^.+\\.(t|j)s$": "ts-jest"
},
  "collectCoverageFrom": [
    "**/*.(t|j)s"
],
  "coverageDirectory": "../coverage",
  "testEnvironment": "node"
}

Things I've tried:

Nothing has worked thus far.

Upvotes: 0

Views: 6948

Answers (2)

Yago Tomé
Yago Tomé

Reputation: 46

Same problem here. I solved by clearing jest cache (--clearcache).

Upvotes: 2

BaconBad
BaconBad

Reputation: 83

I solved the problem by deleting node_modlues, dist and package-lock.json and reinstalled dependencies with yarn. Doing the same with npm didn't work.

Still not quite sure what the cause was.

Upvotes: 0

Related Questions