Giter Site home page Giter Site logo

kevinmcdonnell / sonar-karma-test-report-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from acwatson/sonar-karma-test-report-plugin

0.0 2.0 0.0 36 KB

SonarQube plugin to facilitate publishing unit test reports created using the karma-junit-reporter to SonarQube

License: GNU Lesser General Public License v3.0

Java 100.00%

sonar-karma-test-report-plugin's Introduction

SonarQube Karma JUnit Reporting

Purpose

This is the SonarQube Karma JUnit Reporting plugin. It was created to facilitate publishing unit test reports created using the karma-junit-reporter to SonarQube.

Download

The latest release of this plugin can be downloaded from https://oss.sonatype.org/content/groups/public/com/github/acwatson/sonar-karma-test-report-plugin/1.0.0.3/sonar-karma-test-report-plugin-1.0.0.3.jar

Why Was This Plugin Created?

When using the karma-junit-reporter for a JavaScript project, you end up with a unit test report named something like "TESTS-PhantomJS_1.9.8_(Mac_OS_X_0.0.0).xml".

Looking inside that file, you will see content like:

<?xml version="1.0"?>
<testsuite name="PhantomJS 1.9.8 (Mac OS X 0.0.0)" package="" timestamp="2015-10-05T04:56:44" id="0" hostname="myComputer" tests="58" errors="0" failures="0" time="0.475">
    <properties>
        <property name="browser.fullName" value="Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.8 Safari/534.34"/>
    </properties>
    <testcase name="should do something cool" time="0.028" classname="PhantomJS_1_9_8_(Mac_OS_X_0_0_0).service.myservice"/>
    ...
    <system-out>
    <![CDATA[
    ]]>
    </system-out>
    <system-err/>
</testsuite>

So, What's The Problem?

The problem lies in the classname that the karma-junit-reporter plugin sets for your testcase. Notice above that the plugin has set the classname to PhantomJS_1_9_8_(Mac_OS_X_0_0_0).service.myservice. The PhantomJS part of the classname is the browser that ran the tests and the rest comes from the name of your test suite. In this example, imagine that we have a unit test file located at service/myservice.spec.js and that it defines the top-level test suite with describe('service.myservice', function() {. The karma-junit-reporter is basically concatenating the browser name and the test suite name to come up with the classname. Unfortunately, SonarQube cannot use this classname. SonarQube needs that name of the actual unit test file.

Instead of:

<testcase name="should do something cool" time="0.028" classname="PhantomJS_1_9_8_(Mac_OS_X_0_0_0).service.myservice"/>

SonarQube needs something like:

<testcase name="should do something cool" time="0.028" classname="src/app/service/myservice.spec.js"/>

Basically, we need a way to map the test suite name to the actual unit test file name so that we can report the unit test file report to SonarQube. That is what this plugin does.

How Does This Plugin Work?

The SonarQube Karma JUnit Reporting plugin reads the xml report that was created by the karma-junit-reporter and determines what the real unit test file names are (based off of the testcase classname attribute) and reports them to SonarQube.

Log Output

To troubleshoot or better understand what the SonarQube Karma JUnit Reporting plugin is doing, run Sonar with the debug flag turned on. You will see some debug logging done by the KarmaJunitReporterJsTestDriverSensor.

What Parameters Can Be Set For This Plugin?

  • sonar.javascript.karmajstestdriver.reportsPath must be set to a valid value in order for this plugin to take effect.
    • set this configuration instead of sonar.javascript.jstestdriver.reportsPath

sonar-karma-test-report-plugin's People

Contributors

acwatson avatar

Watchers

 avatar  avatar

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.