Initialize with Google Typescript Style (gts)
npx gts init
npm i
npm i -D jest ts-jest @types/jest
In package.json
add the scripts for test and coverage:
"scripts": {
"test": "jest",
"coverage": "jest --coverage",
...
}
Add a jest.config.js
file:
module.exports = {
transform: {'^.+\\.ts?$': 'ts-jest'},
testEnvironment: 'node',
testRegex: '/tests/.*\\.(test|spec)?\\.(ts|tsx)$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node']
};
In .vscode/launch.json
add configuration to debug tests:
{
"type": "node",
"request": "launch",
"name": "Jest Current File",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["${relativeFile}"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
}
}
Add the Jest Text Explorer extension.
Add Coverage badge