ts-jest
is a well-liked package deal whenever you attempt to use typescript
with jest
.
However one difficulty that’s bugging me not too long ago is, the uncovered traces stat isn’t appropriate, my check protection dropped by 10+%.
After googling, nothing helpful come up, and after some troubleshooting, I discovered that it was ts-jest
that inflicting the difficulty
so I made a decision to make use of babel for compilation as a substitute
set up dependencies
npm i -D @babel/preset-env @babel/preset-typescript typescript jest
setup npm script
"scripts": {
"check": "jest",
}
create a jest.config.js
/** @kind {import('ts-jest/dist/varieties').InitialOptionsTsJest} */
module.exports = {
testEnvironment: 'node',
roots: ['<rootDir>/src'],
testMatch: ['**/__tests__/**/*.+(ts|js)', '**/?(*.)+(spec|test).+(ts|js)'],
remodel: ts)$': 'babel-jest',
,
moduleDirectories: ['node_modules', 'src'],
collectCoverage: true,
collectCoverageFrom: ['**/*.{js,ts}', '!**/*.d.ts'],
}
create a babel.config.js
module.exports = {
presets: [
'@babel/preset-typescript',
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
],
}
you need not set up babel-jest
, it comes with jest
lastly npm check
and increase, your 100% check protection is again.