0
votes

I am using Jest to unit test my backend. I made a dummy file for jest to test and it works fine, but none of my other files are read in the coverage report. The coverage report is just empty. Am I doing something wrong with the configuration of jest?

Here is my package JSON file:

"name": "backend",
"version": "1.0.0",
"description": "",
"main": "seeder.js",
"scripts": {
    "test": "jest",
    "start": "node server.js",
    "coverage": "npm test -- --coverage"
},
"author": "",
"license": "ISC",
"dependencies": {
    "jest": "^26.6.3",
    "supertest": "^6.1.3"
},
"jest": {
    "testEnvironment": "node",
    "coveragePathIgnorePatterns": [
        "/node_modules"
    ]
  }
}

Below is the way I have my folders set up with files inside of them. enter image description here

1

1 Answers

1
votes

I added the collectCoverageFrom settings in the Jest config. I even have different configurations for normal unit tests, e2e tests, etc., which all collect coverage:

collectCoverageFrom: [
    '<rootDir>/**/*.ts',
    '!<rootDir>/**/*.interface.ts',
    '!<rootDir>/**/*.mock.ts',
    '!<rootDir>/**/__mock__/*',
    '!<rootDir>/src/main.ts'
],
coverageProvider: 'v8',