Repository navigation
test_runner: lcov reporter for test coverage #49626
Description
Activity
- addedfeature requestIssues requesting new Node.js features.Issues requesting new Node.js features.
on Sep 12, 2023 - addedtest_runnerIssues and PRs related to the test runner subsystem.Issues and PRs related to the test runner subsystem.
on Sep 12, 2023 I think this is a good idea, my only concern is source map support
VSCode, as well as many extensions (e.g.
ryanluker.vscode-coverage-gutters) also need lcov reports in order to annotate files. Same for bots that post coverage results to PRs.I support and want this.
Reacted by Phil NashI think this is a good idea, my only concern is source map support
That's certainly important. But should that be handled before the
test:coverageevent is fired? That is, should the data that comes in thetest:coverageevent already have been augmented with data from the source map? It shouldn't be on each reporter to do that work, right?And if that is the case, a reporter can be built independently of source map support. And the feature only graduates from experimental when it has source map support.
Reacted by Moshe Atlow and GuilhermeMGBRmy comment wasn't made to block or object to this feature - just to raise this as something to think about before the feature is implemented. if it is possible to map lcov format after it is generated to its source that works as well
Thanks @MoLow, I will certainly keep it in mind.
This is a fantastic feature to have in node!
As a workaround I've used this for now
https://github.com/bcoe/c8NODE_V8_COVERAGE=./coverage c8 -r html node --test --experimental-test-coverage src/**/*.spec.ts
Reacted by Ivo von Putzer Reibegg, Prentece and Luciano Mammino- added a commit that references this issue
on Oct 23, 2023 - added a commit that references this issue
on Oct 25, 2023 - added a commit that references this issue
on Nov 11, 2023 - added a commit that references this issue
on Dec 11, 2023 @philnash thank you for adding lcov support!
Would it make sense to raise a feature request to generate the html coverage report too?@fernandopasik there's certainly nothing wrong with raising a feature request for an HTML coverage report.
The only issue I see with it is that it wouldn't necessarily fit with the model of existing reporters, in that you normally define a single output file and an HTML report would require multiple files, normally going into a coverage directory of its own.
it wouldn't necessarily fit with the model of existing reporters, in that you normally define a single output file
It's a very good point.
I'll raise the feature issue, but tldr the problem I'm trying to resolve is navigating in detail the coverage of files to find the missing tested lines, functions, etcA note also on this is some of the lcov reporters in other runners like jest and mocha do generate the html output files in the same directory than the lcov.info file.
I tried to mitigate requesting for this by using a package to generate html report from the lcov file, but I was unsuccessful, not sure if you have any good alternatives for this.
What package did you try and what was unsuccessful about it? I haven't actually tried that myself yet, but it's something I'd be happy to look into.
Sorry I should have said it didn't work for my particular problem 😊 I haven't tried it with js files, it didn't work with some typescript project I was working on, but I was hoping you might known an alternative package I could try.
The issue I was having was that I could not explore in detail each file in the lcov.info file
Ah, my understanding is that coverage still doesn't work accurately for TypeScript because the coverage system doesn't yet support source maps.
Reacted by Fernando PasikAh, my understanding is that coverage still doesn't work accurately for TypeScript because the coverage system doesn't yet support source maps.
Oh thanks! By any chance do you know an issue in this repo about it that I can follow?
What is the problem this feature will solve?
We can now produce code coverage reports from the built-in test runner and (currently experimental) code coverage. Being able to report that coverage to third-parties, like SonarQube, SonarCloud, Coveralls, or Code Climate is useful to track coverage over time.
Each of these tools accepts lcov as a format for providing test coverage results.
What is the feature you are proposing to solve the problem?
I propose to write a test reporter that outputs code coverage results in the lcov format.
I've actually got quite a long way through this, as part of adding more information to the
test:coverageevent sent to reporters. I don't wish the reading of the lcov documentation on anyone else.I did want to raise a feature request to see if there were any comments or thoughts before I open a PR.
What alternatives have you considered?
This could be built as a third-party module, but given lcov's seeming ubiquity as the code coverage format of choice for different code quality tools, it would be useful for users to have it built in.
In comparison with other platforms, Deno can generate an lcov report from its coverage output and Bun has an open issue to implement lcov, so this is becoming par for the course for a test runner.
I am happy to work on this. Full disclosure, I work at Sonar and this would be beneficial to our users if they decide to choose to use the Node test runner in their projects.