gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 787 forks source link

Accuracy in question #711

Closed ORESoftware closed 7 years ago

ORESoftware commented 7 years ago

I have a Loopback server, which is similar to Express

There are certain routes that I simply know get hit by Loopback, for example, everything in the boot directory.

I am running a child_process like this:

              if (useIstanbul) {

                node = cp.spawn('istanbul', ['cover', 'server/server.js'], {
                  cwd: cwd,
                  env: Object.assign({}, process.env, {
                    NODE_ENV: 'prod', //will use server/config.local.js file in project, according to Loopback
                    // NODE_ENV: 'prod',
                    port: designatedPort,
                    DEBUG: 'loopback:datasource'
                  })
                });
              }
              else {
                node = cp.spawn('node', ['.'], {
                  cwd: cwd,
                  env: Object.assign({}, process.env, {
                    NODE_ENV: 'prod', //will use server/config.local.js file in project, according to Loopback
                    // NODE_ENV: 'prod',
                    port: designatedPort,
                    DEBUG: 'loopback:datasource'
                  })
                });
              }

but using Istanbul in this way, does not seem to generate accurate coverage reports.

Any idea why this might be?

For example, I know this file would have been run by Loopback and I can log it to be sure:

screenshot 2016-10-20 14 22 06

(because the above screenshot is from a file in server/boot

ORESoftware commented 7 years ago

Turns out, it looks like Istanbul is 100% correct about this :) How bizarre.