connor4312 / nodejs-testing

VS Code integration for node:test native tests
MIT License
43 stars 6 forks source link

No branch coverage #40

Open coder-mike opened 1 month ago

coder-mike commented 1 month ago

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:

image

If I hover over it, it says "0/0" branches covered:

image

connor4312 commented 1 month ago

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.

vsDizzy commented 2 weeks ago

Should the 100% value be green?

image