npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sonar-generic-code-coverage

v0.0.1

Published

SonarQube Generic Code Coverage Reporter for Istanbul

Downloads

6

Readme

Background

This npm module is made as a work-around for jest/vitest users who need SonarQube Generic Test Coverage format. There are other npm projects supporting SonarQube Gerneric Test Execution Report Format.

One use-case for this module is creating code coverage for svelte projects in SonarQube. SonarQube reports .svelte files as HTML files and does not show code coverage in their UI, even though svelte files can have code coverage with lcov.

This module allows your test runner to create the "Generic Test Coverage" format that is associated with sonar.coverageReportPaths. You can combine the lcov output created via your test runner with the generic code coverage format when sending reports to SonarQube.

Do not use this module if your project is using only javascript/typescript! Use sonar.javascript.lcov.reportPaths=coverage/lcov.info as described in the documentation. The lcov option in your test runner is all you need, as it's optimized for sonar, again this module should only be used for projects that have files unsupported by SonarQube. Look into sonar community docs before using this module.

Installation & Setup

npm install --save-dev sonar-generic-code-coverage

Example vitest config

import { defineConfig } from 'vitest/config';

export default defineConfig({
    test: {
      coverage: {
        exclude: [...configDefaults.exclude],
        reporter: ["json", "lcov", "cobertura", ["sonar-generic-code-coverage", { file: 'sonar-generic-coverage.xml'}]], // <path>/dist/index.js locally
      },
      reporters: ["default", "vitest-sonar-reporter"],
      outputFile: {
        "vitest-sonar-reporter": "coverage/sonar-report.xml",
      },
    },
});

You can also see an example for jest setup in the example-jest folder

Noteworthy: in order to directly compare the resulting sonar-coverage.xml file in both directories, the vitest config should be set to istanbul rather than v8 to match the deafult jest config. Of course, if you use vitest you can still use v8 coverage for your own projects.

Highlights:

This implementation is similar to the work of node-sonar-coverage-reporter; however, the node-sonar-coverage-reporter does not create an xml file that can be used as generic test data for SonarQube. This is a different implementation to the cobertura istanbul reporter.

There are other jest-sonar projects on npm that may support your use-case, but they usually have to do with creating generic test execution report format.

If you prefer to have a post-process way of converting your test-runner reports into SonarQube generic test data, it may be worth looking into this coverage-report-cobertura-to-sonar-generic project that defines an xslt which can be used to convert cobertura to sonar generic test data format.

Another consideration to look into for the post-process way is to convert lcov to sonar generic test data.

Sonar

Assuming you have both vitest-sonar-reporter and sonar-generic-code-coverage, your sonar config may look like this:

sonar.testExecutionReportPaths=coverage/sonar-report.xml
# sonar.javascript.lcov.reportPaths=coverage/lcov.info     # include if javascript/typescript project
sonar.coverageReportPaths=coverage/sonar-coverage.xml