Monday, 18 November 2019

Jest passing tests but --covering option not picking up files

Problem description:
I have written two tests for a typescript class. Those two tests pass so jest successfully retrieves the test files. I then use the --coverage option but it appears jest is not picking the covered files here.
Here is the output I am getting:

api_jester    | PASS src/tests/repositories/user.test.ts
api_jester    |   User Repository
api_jester    |     ✓ it should return an empty array (18ms)
api_jester    |     ✓ should successfully create a user and return its data (7ms)
api_jester    | 
api_jester    | ----------|----------|----------|----------|----------|-------------------|
api_jester    | File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
api_jester    | ----------|----------|----------|----------|----------|-------------------|
api_jester    | All files |        0 |        0 |        0 |        0 |                   |
api_jester    | ----------|----------|----------|----------|----------|-------------------|
api_jester    | Test Suites: 1 passed, 1 total
api_jester    | Tests:       2 passed, 2 total
api_jester    | Snapshots:   0 total
api_jester    | Time:        3.208s
api_jester    | Ran all test suites.

I have tried playing with the collectCoverageFrom option but without any success. I have tested covering with some simple examples found on github and those were working so the problem is not from my environment. I am guessing I somehow missed something in my configuration but I have spend so much time on this I am getting kind of frustrated so maybe some fresh looks could help..

Project architecture :

config
|__ jest.config.js
|__ tsconfig.json
src
|__tests
|  |__repositories
|     |__user.test.ts
|__repositories
   |___ userRepository
        |__User.ts

Jest.config.js :

module.exports = {
  preset: "ts-jest",
  testEnvironment: "node",
  roots: ["../src/tests/"],
  transform: {
    "^.+\\.tsx?$": "ts-jest"
  },
  collectCoverageFrom: ["../src/"],
  moduleFileExtensions: ["ts", "js", "json"],
  coverageDirectory: "../coverage"
};


from Jest passing tests but --covering option not picking up files

No comments:

Post a Comment