Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge the results of different testing tools and report it (Read report from lcov.info instead of json files) #487

Open
glaubernespoli opened this issue Jul 25, 2023 · 1 comment

Comments

@glaubernespoli
Copy link

glaubernespoli commented Jul 25, 2023

  • 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.

@glaubernespoli
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant