Code Monkey home page Code Monkey logo

jest-sonar-reporter's Introduction

jest-sonar-reporter

Build Status Quality Gate

jest-sonar-reporter is a custom results processor for Jest. The processor converts Jest's output into Sonar's generic test data format.

This project is inspired by Michael Allen's jest-junit-reporter project.

Installation

Using npm:

$ npm i -D jest-sonar-reporter

Using yarn:

$ yarn add -D jest-sonar-reporter

Configuration

Configure Jest in your package.json to use jest-sonar-reporter as a custom results processor.

{
  "jest": {
    "testResultsProcessor": "jest-sonar-reporter"
  }
}

Configure Sonar to import the test results. Add the sonar.testExecutionReportPaths property to your sonar-project.properties file.

sonar.testExecutionReportPaths=test-report.xml

Customization

To customize the reporter you can use package.json to store the configuration.

Important: The TEST_REPORT_PATH environment variable is deprecated!

Create a jestSonar entry like this:

{
  "jestSonar": {}
}

You can customize the following options:

  • reportPath This will specify the path to put the report in.
  • reportFile This will specify the file name of the report.
  • indent This will specify the indentation to format the report.
{
  "jestSonar": {
    "reportPath": "reports",
    "reportFile": "test-reporter.xml",
    "indent": 4
  }
}

Important: Don't forget to update sonar.testExecutionReportPaths when you use a custom path and file name.

Support for Sonarqube 5.6.x

Sonarqube 5.6.x does not support Generic Test Data however it has a Generic Test Coverage plugin which offers similar functionality.

If you have the plugin installed on Sonarqube, you can configure this reporter to produce files in supported format.

{
  "jestSonar": {
    "sonar56x": true
  }
}

Configure Sonar to import the test results. Add the sonar.genericcoverage.unitTestReportPaths property to your sonar-project.properties file.

sonar.genericcoverage.unitTestReportPaths=test-report.xml

Usage

  1. Run Jest to execute your tests.

Using npm:

$ npm run test

Using yarn:

$ yarn run test
  1. Run sonar-scanner to import the test results.
$ sonar-scanner

Licence

This project uses the MIT licence.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.