Here are some notes that I gathered when trying to get code coverage for typescript.
proj
|__ package.json
|__ tsconfig.json
|__ src/lib.ts
|__ tests/test1.spec.ts
npm install mocha chai istanbul remap-istanbul typescript
package.json:
"scripts: {
"build-ts": "rm -rf build && tsc",
"test-spec": "mocha build/tests/**/*.spec.js -R spec --bail",
"test-cov": "istanbul cover --include-all-sources --dir ./build/coverage node_modules/mocha/bin/_mocha -- build/tests/**/*.spec.js -R spec --bail",
"test-remap": "remap-istanbul -i build/coverage/coverage.json -o coverage -t html",
"build": "npm run build-ts",
"test": "npm run build && npm run test-cov"
}
tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noImplicitAny": false,
"sourceMap": true,
"jsx": "react",
"moduleResolution": "node",
"outDir": "build"
},
"exclude": [
"node_modules",
"typings"
]
}
npm run test
npm run test-remap
open coverage/index.html
It's good idea to run the tests and remap steps separately so the remap step is run even if tests fail.
Awesome