Istanbul Code coverage – TypeScript with Express on Node js

Needed pacakges:

npm install mocha chai istanbul remap-istanbul typescript


Config in package.json :

“name”: “express”,
“version”: “0.0.0”,
“private”: true,
“scripts”: {
“start”: “node ./dist/www”,
“build”: “tsc -w -p .”,
“build:ubuntu”: “sudo tsc -w -p .”,
“build:CI”: “sudo tsc -p .”,
“install:global:dependencies”: “npm install -g typescript && npm install -g nodemon && npm install -g typedoc && npm install apidoc-swagger -g”,
“docs:all”: “npm run docs:typedoc && npm run docs:swagger”,
“docs:typedoc”: “typedoc –out ./docs/typedoc/ app.ts”,
“docs:swagger”: “apidoc-swagger -i ./ -o ./docs/docs_swagger/”,
“aws_server”: “npm run aws_server:install:global:dependencies && npm run build:CI && npm start”,
“aws_server:install:global:dependencies”: “npm install -g typescript && npm install”,
“test”: “echo \”Mock: All tests passed(no tests for now)\” && exit 0″
“description”: “ExpressApp2”,
“author”: {
“name”: “customer”
“main”: “app.js”,
“dependencies”: {
“body-parser”: “^1.17.1”,
“cors”: “^2.8.3”,
“debug”: “^2.2.0”,
“express”: “^4.14.0”,
“jsonwebtoken”: “^7.4.0”,
“mongo-querystring”: “^4.1.0”,
“mongoose”: “^4.9.6”,
“node-rest-client”: “^3.1.0”,
“object-mapper”: “^3.0.1”,
“promise”: “^7.1.1”,
“reflect-metadata”: “0.1.3”,
“request”: “^2.81.0”,
“request-promise”: “^4.2.0”,
“serializer.ts”: “0.0.12”
“devDependencies”: {
“jsonwebtoken”: “^7.4.0”,
“mongo-querystring”: “^4.1.0”,
“mongodb”: “^2.2.26”,
“mongoose”: “^4.9.8”,
“nodemon”: “^1.11.0”
In tsconfig.json:
“compilerOptions”: {
“target”: “es5”,
//”lib”: [“es2015″,”es2016″,”dom”,”es2017″,”es6″,”es5″],
“outDir”: “./dist/build”,
“module”: “commonjs”,
“declaration”: false,
“noImplicitAny”: false,
“strictNullChecks”: false,
“removeComments”: true,
//”noUnused”: false,
“noUnusedLocals”: false,
“noUnusedParameters”: false,
“moduleResolution”: “node”,
“sourceMap”: true,
“inlineSources”: true,
   “experimentalDecorators”: true
“include”: [
“exclude”: [
“typeRoots” : [“./typings”]

Run Unit Test

Run : npm run test to run test with mocha

Show code coverage

Step 1: Run npm run test-cov to run web page to see the result in console

Step 2: Open new command line Run npm run coverage:show and see result on web view (Chrome)

Or short way just npm run coverage


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s