Reputation: 83
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
.
{
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
*.spec.ts
files.collectCoverageFrom
to make sure that the config is being loaded (it is).collectCoverageFrom
, such as **/*.service.ts
, **/*.controller.ts
as well as absolute paths to specific files.forceCoverageMatch
Nothing has worked thus far.
Upvotes: 0
Views: 6948
Reputation: 46
Same problem here. I solved by clearing jest cache (--clearcache
).
Upvotes: 2
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