{
"scripts": {
"test": "jest --config .jestrc.json --passWithNoTests"
},
"devDependencies": {
"@jest/globals": "x.x.x",
"@types/jest": "x.x.x",
"jest": "x.x.x",
"jest-extended": "x.x.x",
"jest-when": "x.x.x",
"ts-jest": "x.x.x"
}
}
.jestrc.json
{
"coverageProvider": "v8"
}
.jestrc.json
{
"coverageReporters": ["lcov", "text"]
}
.jestrc.json
{
"transform": {
"^.+\\.m?[jt]sx?$": [
"ts-jest",
{
"diagnostics": {
"warnOnly": true
}
}
]
}
}
Jest supports configuration defined either in package.json
or in a jest.config.js
file by default.
To keep dependency specific configuration out of the way, it should be kept in its own file.
The default jest.config.js
means the configuration is stored as code, but this is unnecessary.
To minimise complexity, store it as a data object following standard naming conventions, .jestrc.json
.
Pass this file when executing jest
.
Explicitly import Jest methods from @jest/globals
.
Follow ES Module syntax for consistency and allow smoother migration in the future.
Avoid relying on "magic" globals.
IDE-agnostic solution.
V8's built-in code coverage is faster and less memory-intensive than the default babel-plugin-istanbul
.
Jest introduced the ability to configure coverageProvider
in version 25.
The default coverage reporters include a lot of outputs which may not be needed.
Restricting reporters to lcov
(which also includes html
) and text
(to output to the console) based on istanbul's reporters.
Report diagnostics, but don't block compilation during development.