rewire icon indicating copy to clipboard operation
rewire copied to clipboard

Code coverage does not work with VS Code extension development

Open Pasu4 opened this issue 6 months ago • 3 comments

I am currently working on a VS Code extension in which I am using rewire for unit tests. The problem: Code that is executed only with rewire during unit tests is not detected as being covered by vscode-test.

I have set up a minimal example that demonstrates this (setup instructions are in the README): https://github.com/Pasu4/Rewire-Coverage-Example

Pasu4 avatar Jun 28 '25 11:06 Pasu4

I don't see how it would. Nor rewire, nor mocha collects any coverage info on its own. You need nyc/istanbul for this, or some other than mocha test runner able to collect coverage info from v8. I had no issues with collecting coverage with nyc from mocha + rewire from rewire'd code. Yet coverage was collected by nyc, not by mocha... Maybe some other runtime, like bun/deno, would collect coverage using embedded runner. Maybe even Node would, if you run it properly https://nodejs.org/en/learn/test-runner/collecting-code-coverage . In any case, mocha needs some help from external tools, and rewire has nothing to do with this

pietrovich avatar Aug 15 '25 18:08 pietrovich

I don't see how it would. Nor rewire, nor mocha collects any coverage info on its own. You need nyc/istanbul for this, or some other than mocha test runner able to collect coverage info from v8. I had no issues with collecting coverage with nyc from mocha + rewire from rewire'd code. Yet coverage was collected by nyc, not by mocha... Maybe some other runtime, like bun/deno, would collect coverage using embedded runner. Maybe even Node would, if you run it properly https://nodejs.org/en/learn/test-runner/collecting-code-coverage . In any case, mocha needs some help from external tools, and rewire has nothing to do with this

Mocha does have code coverage reporters, by default vscode-test sets Mocha to use the html code reporter. Though I can't imagine nyc/istanbul hurting to use instead if this isn't patchable.

KTrain5169 avatar Sep 17 '25 22:09 KTrain5169

Should probably clarify: it turns out vscode-test uses Istanbul (or some variant of it?) to report code coverage, sorry for the confusion. JS unit testing is pretty new to me as well 😅

That being said Mocha does also come with a couple built-in options? I'm not entirely sure from looking at their page.

KTrain5169 avatar Sep 18 '25 12:09 KTrain5169