Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

Webpack istanbul-instrumenter-loader does not load all source files

Writer Emily Wong

I have a project that is large but currently has very few tests in it. The coverage is surprisingly high. The reason the coverage is high is because coverage is only reported for files that have tests!!

My coverage actually goes down as I add more tests. When I add a new test file it pulls in more sources and the statement / branches / functions / lines totals go up.

On the coverage html reports large numbers of classes are not listed at all.

How do I include ALL source files in my coverage report even if they are not referenced by my tests?

I've spent a bit of time looking into this but I can't figure out why on earth they are not being reported.

(unfortunately I do not have access to SO from my work computer so I can't directly copy / paste anything in here - I am having to type out the examples)

The main config area of interest for this seems to be the instrument loader. It's my understanding that istanbul-instrumenter-loader adds extra code to my javascript (transpiled from Typescript). The tests are then run and coverage information is captured. The coverage-istanbul reporter then reports on the captured data.

My loader config:

{ test: /\.ts$/, use: { loader: "istanbul-instrumenter-loader", options: { esModules: true, produceSourceMap: true } }, enforce: "post", include: path.resolve("main"), // main is my src folder exclude: /.spec.ts$/
}

I have tried messing with the include statement here by changing it to a glob or a regular expression but nothing I tried improved the situation.

Just to confirm that my tsconfig.spec.json file was including all the sources I wanted coverage for I deliberately caused a compile error on one of the files that was not included in the coverage report and confirmed that this error showed up in the test compilation.

1 Answer

You need to configure nyc to load all files via a nycrc file. Specifically, you need to set all: true. This is discussed in the docs here

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.