nodejs-testing
nodejs-testing copied to clipboard
No branch coverage
I'm unable to see any branch coverage in the "test coverage" pane. I only see statement and function coverage.
I've created a minimal example to reproduce this.
// main.mjs
export function foo(arg) {
return arg ? 1 : 2; // Two branches
}
// main.test.mjs
import { test } from 'node:test';
import { strict as assert } from 'node:assert';
import { foo } from './main.mjs';
test('test', () => {
assert.equal(foo(true), 1); // Only one branch tested
});
I click "run tests with coverage" in the testing panel.
The coverage breakdown doesn't show branches:
If I hover over it, it says "0/0" branches covered:
This is kind of a limitation of V8's coverage format. Under the hood we use v8-to-istanbul, but I plan to do away with that. I'm thinking of doing some AST smartness with that refactoring in order to accurately identify branches.
Should the 100% value be green?
@connor4312 I created a tool MCR, which can convert native V8 coverage data into Statements, Branches and Functions (Similar to Istanbul), unlike v8-to-istanbul, it can analyze the AST to generate more accurate coverage data.
see demo: https://cenfun.github.io/monocart-coverage-reports/v8/
However, I am not very familiar with the test coverage interface of VSCode. Are there any documents or examples? Perhaps MCR can easily generate coverage data in VSCode format from V8, just like istanbul-to-vscode
Actually, c8 has integrated MCR as an experimental feature since v10.1.0
c8 --experimental-monocart --reporter=v8 --reporter=console-details node foo.js