nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
105.28k stars 28.52k forks source link

Exclude test files from coverage report #53508

Open rozzilla opened 3 weeks ago

rozzilla commented 3 weeks ago

What is the problem this feature will solve?

Hey folks! 👋🏼 I know that as by doc it's currently not possible to exclude specific files or directories from the coverage report.

The problem I face right now is that the coverage includes all of the test files.

For instance, if I have the following file:

// index.js
export function sum(val1, val2) {
  return val1 + val2;
}

and the test:

// index.test.js
import { strictEqual } from "node:assert";
import { it, describe } from "node:test";
import { sum } from "./index.js";

describe("test", () => {
  it("should pass", () => {
    strictEqual(sum(40, 2), 42);
  });
});

Once I run node --experimental-test-coverage --test I get:


> test@1.0.0 no
> node --experimental-test-coverage --test

▶ test
  ✔ should pass (0.155709ms)
▶ test (1.117417ms)

ℹ tests 1
ℹ suites 1
ℹ pass 1
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 47.674834
ℹ start of coverage report
ℹ --------------------------------------------------------------
ℹ file          | line % | branch % | funcs % | uncovered lines
ℹ --------------------------------------------------------------
ℹ index.js      | 100.00 |   100.00 |  100.00 | 
ℹ index.test.js | 100.00 |   100.00 |  100.00 | 
ℹ --------------------------------------------------------------
ℹ all files     | 100.00 |   100.00 |  100.00 |
ℹ --------------------------------------------------------------
ℹ end of coverage report

What is the feature you are proposing to solve the problem?

Ideally, .test.* should be excluded from the coverage report

What alternatives have you considered?

No response

RedYetiDev commented 3 weeks ago

Seems simple enough. The same logic for --test-skip-pattern can be used.

--coverage-exclude-glob ... --coverage-include-glob ...

RedYetiDev commented 3 weeks ago

I'm happy to work on this :-).

RedYetiDev commented 2 weeks ago

Hey! Sorry for the delay, I've been out-of-town, but I'll begin work on this ASAP.