I am currently developing a Next.js project in Typescript and using the SWC compiler. For testing, I have integrated @swc/jest. Although all my tests are passing successfully, the coverage report appears empty. Below is an excerpt from my jest.config.js
:
module.exports = {
'roots': ['<rootDir>/../src'],
'moduleDirectories': ['node_modules', 'src'],
'setupFilesAfterEnv': ['<rootDir>/setup-tests.js'],
'coverageDirectory': '<rootDir>/../coverage',
'verbose': true,
'collectCoverage': true,
'transform': {
'^.+\\.(t|j)sx?$': [
'@swc/jest',
{
'jsc': {
target: 'es2021',
},
'sourceMaps': true,
},
],
},
'collectCoverageFrom': [
'<rootDir>/../src/**.{ts,js,tsx,jsx}',
'!**/node_modules/**',
],
}
Here is how my file structure looks:
.
├── coverage
├── jest
│ ├── jest.config.js
│ ├── setup-tests.js
├── src/
├── tsconfig.json
The generated output displays as follows:
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
Test Suites: 11 passed, 11 total
Tests: 25 passed, 25 total
Snapshots: 0 total
Time: 1.307 s
Ran all test suites.
I have raised an issue on @swc/jest's repository but considering other possibilities, I would like to seek advice here as well.