Upgrading to 27 breaks coverage with ts-jest preset
See original GitHub issue🐛 Bug Report
This issue is a follow-up to the kulshekhar/ts-jest#2790
Recently I’ve upgraded to jest: 27.0.6 and ts-jest: 27.0.4 and discovered that test runs with --coverage fail because of syntax errors. Downgrading to jest: 26.6.3 and ts-jest: 26.5.6 fixes the issue. Regular test runs without coverage collection work good in both versions.
It looks like jest --coverage
ignores preset and tries to use babel.
To Reproduce
Run jest --coverage
in a typescript project using ts-jest preset
Here is my jest config:
jest.config.js
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
coverageThreshold: {
global: {
lines: 90,
statements: 90,
functions: 90,
branches: 70,
},
},
testMatch: ['**/*.test.ts'],
setupFilesAfterEnv: ['./tests/jest.setup.ts'],
collectCoverageFrom: [
`**/src/**/*.ts`,
`!**/src/server.ts`,
`!**/src/gracefulShutdown.ts`,
],
coverageReporters: ['text', 'cobertura'],
};
and package.json
{
"name": "name",
"version": "1.0.0",
"description": "description",
"engines": {
"node": "^14.15.0"
},
"scripts": {
"prestart": "yarn build",
"start": "node ./dist/src/server.js",
"start:dev": "nodemon ./src/server.ts",
"build": "tsc",
"lint": "eslint --quiet .",
"test": "jest",
"test:ci": "yarn test --coverage --reporters=default --reporters=jest-junit"
},
"keywords": [],
"author": "misha@fibery.io",
"license": "ISC",
"private": true,
"dependencies": {
"date-fns": "2.23.0",
"dotenv": "10.0.0",
"envalid": "7.1.1",
"got": "11.8.2"
},
"devDependencies": {
"@types/jest": "26.0.24",
"@types/node": "16.4.7",
"@typescript-eslint/eslint-plugin": "4.28.5",
"@typescript-eslint/parser": "4.28.5",
"eslint": "7.31.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-jest": "24.4.0",
"eslint-plugin-node": "11.1.0",
"husky": "4.3.8",
"jest": "27.0.6",
"jest-junit": "12.2.0",
"lint-staged": ">=11.0.0",
"nock": "13.1.1",
"prettier": "2.3.2",
"ts-jest": "27.0.4",
"ts-node": "10.1.0",
"typescript": "4.3.5"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{ts,js}": "eslint --cache --fix",
"*.{ts,js,css,md}": "prettier --write"
}
}
Expected behavior
Coverage collection should not throw syntax errors
Link to repl or repo (highly encouraged)
envinfo
System:
OS: macOS 11.2.3
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Binaries:
Node: 14.17.0 - /usr/local/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 7.20.2 - /usr/local/bin/npm
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Jest 27: New Defaults for Jest, 2021 edition
This gives us the opportunity to remove some packages from the default distribution of Jest 28 and publish them as separately installable and ......
Read more >From v27 to v28
Upgrading Jest from v27 to v28? This guide aims to help refactoring your configuration and tests.
Read more >Configuring Jest
To read TypeScript configuration files Jest requires ts-node . ... Jest ships with two coverage providers: babel (default) and v8 .
Read more >Jest 25: 🚀 Laying foundations for the future
Jest 25 is laying the groundwork for many major changes in the future. As such, we kept breaking changes to a minimum, but...
Read more >Jest 28: Shedding weight and improving compatibility
Hopefully this makes the upgrade experience as frictionless as possible! Main breaking changes likely to impact your migration are dropped ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
it is because the value for
collectCoverageFrom
is wrong. If I putwill also work.
hmm we did change the construction of cache key in v27 for
ts-jest
comparing to v26, that is the only change which is related to code coverage IMO. The repo from @MikeYermolayev I cannot reproduce the issue.The repo from @TrejGun needs to remove the
collectCoverageFrom
in jest config to make it work. I think he specified the wrongcollectCoverageFrom
value, which isn’t related tots-jest