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 786 forks source link

istanbul doesn't cover files that have been proxyquire'd in #492

Open Dakuan opened 8 years ago

Dakuan commented 8 years ago

Having some bother getting istanbul and proxyquire to play nicely.

If I import a module into my test normally:

import subject from "../src/foo.es6"

Then istanbul covers the module as expected.

Importing with proxyquire works, in that I can stub the things, but istanbul says that file is no longer covered, when it definitely is.

let subject = proxyquire("../src/foo.es6", { /** stubs **/}).default;
tandrewnichols commented 8 years ago

That's because they both duck-punch module.extensions to implement their magic when files are loaded via require. About the only real solution is to save your instrumented files and run your tests against those. It's not awesome.

jamestalmage commented 8 years ago

nyc provides istanbul based coverage reports, and uses append-transform to wrap require extensions in a way that is compatible with proxyquire and almost any other correctly executed require extension.

https://github.com/jamestalmage/__demo-nyc-with-proxyquire

alestiago commented 1 year ago

I found myself having the same problem, instead of using nyc I used c8 and configured it. The c8's README is clear and it worked like a charm.

AbGrS commented 7 months ago

This issue still persists. Is there any update on this?