c8
c8 copied to clipboard
Merge the results of different testing tools and report it (Read report from lcov.info instead of json files)
- Version: v18.16.0
- Platform: Linux 5.15.90.1-microsoft-standard-WSL2 x86_64 x86_64 x86_64 GNU/Linux
- c8 Version: 8.0.0
I'm working on a project where we use two different testing tools - mocha for node tests, and web-test-runner for tests on the browser.
While setting up c8, I could easily set it up to report for the node tests, by simply having a script like:
"test:coverage": "c8 mocha"
Our browser tests script, on the other hand, is called as:
"test:browser": "npx web-test-runner 'src/spec/browser/**/*.spec.ts' --playwright --browsers chromium firefox"
Now what I want to do is to have a report that shows the coverage of both the browser and node tests together. From what I've found, c8 doesn't really have an option to merge the results.
The solution I came up with is to use the --coverage
option with the "test:browser"
script, and by using the following config in my web-test-runner.config.mjs
:
coverageConfig: {
report: true,
reporters: ['lcovonly', 'text', 'text-summary'],
reportDir: './coverage/browser'
}
I then have my .c8rc
as:
{
"all": true,
"include": ["src/lib/**/*.ts"],
"exclude": ["src/spec/**/*.ts", "src/typings/*.ts", "src/lib/index.ts"],
"reporter": ["lcovonly", "text", "text-summary"],
"check-coverage": true,
"clean": true,
"reports-dir": "./coverage/node"
}
That way both testing tools generate their own lcov.info
file in their respective folders. Then with the help of the lcov
lib I can manage to merge that, but then I'd like to somehow make usage of the c8 report
command to output the result on the console.
By manually placing the merged lcov.info
file into the coverage/node
folder and running the c8 report
command, I realized the results didn't change, regardless of the changes in the file, since the report
command reads from json files located in the /tmp
folder.
So my question is: Is there any way to achieve what I want? To use c8
to report text (on console) a merged result coming from another test runner?
Thanks in advance.
Another point: given the script "test:browser": "npx web-test-runner 'src/spec/browser/**/*.spec.ts' --playwright --browsers chromium firefox"
. If I just try to run c8
with it as: npx c8 npm run test:browser
, I simply get 0% coverage in all aspects, while adding the --coverage flag to the command line generates a correct lcov.info
by the web-test-runner
.