How do I setup code coverage on my Express based API? How do I setup code coverage on my Express based API? node.js node.js

How do I setup code coverage on my Express based API?


I just had this same exact situation and I found it has to do the way I was using supertest:

  • Before I was testing my app directly against my running server, like this.

    var request = require('supertest')var api = request('http://127.0.0.1:3000')
  • I fix it by requiring my express app instead:

    var request = require('supertest')var app = require('../../../')var api = request(app)


Based on my experience with istanbul, I think there might be a logic error in terms of what route is actually being used. Please set that test to use it.only and then look at the istanbul coverage. (There's no need to use the istanbul middleware, since your developers have access to the html output being written to the local filesystem.)

Please show what route is actually being covered, because istanbul is very clever in how it follows if statements.

If you have found a bug in istanbul, I encourage you to post a bug there.