GithubHelp home page GithubHelp logo

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

View Code? Open in Web Editor NEW
2.0 2.0 3.0 37 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 People

Contributors

acwatson avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

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

Metric 'test_data' should not be computed by a Sensor

I'm using Sonar 6.4 with SonarJS 3.1.1
When I trigger an analysis on my Js code, it fails with the following error

Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.2:sonar (default-cli) on project webui-parent: Metric 'test_data' should not be computed by a Sensor -> [Help 1]

Please advise.
Thanks.

Don't pick up test name in SonarQube

Hey @acwatson. Plugin pick data about tests (test classes, duration, count) but looks like not fully. It doesn't show test names and logs of failure tests in SonarQube 5.3.

XML report generate by karma-junit-reporter:

<?xml version="1.0"?>
<testsuite name="PhantomJS 2.1.1 (Linux 0.0.0)" package="" timestamp="2016-09-24T12:44:25" id="0" hostname="anton-MS-7596" tests="3" errors="0" failures="0" time="0.002">
  <properties>
    <property name="browser.fullName" value="Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1"/>
  </properties>
  <testcase name="test_hello" time="0.002" classname="patientCtrlSpec"/>
  <testcase name="test12" time="0" classname="patientCtrlSpec"/>
  <testcase name="test1" time="0" classname="Physician Controller"/>
  <system-out>
    <![CDATA[
]]>
  </system-out>
  <system-err/>
</testsuite>

Karma config file:

var baseConfig = require('./karma.conf');

module.exports = function (config) {

    baseConfig(config);

    config.set({
        basePath: '../../..',
        frameworks: ['jasmine'],
        files: [
            'src/main/webapp/js/angular/angular.js',
            'src/main/webapp/js/angular/angular-mocks.js',

            'src/main/webapp/view/app/**/*.js',
            'src/test/js/**/*.js'
        ],
        preprocessors: {
            'src/main/webapp/view/app/**/*.js': ['coverage']
        },
        // added `junit`
        reporters: ['dots', 'progress', 'junit', 'coverage'],
        port: 9876,
        colors: false,
        logLevel: config.LOG_INFO,
        // don't watch for file change
        autoWatch: false,
        // only runs on headless browser
        browsers: ['PhantomJS'],
        // just run one time
        singleRun: true,
        // remove `karma-chrome-launcher` because we will be running on headless
        // browser on Jenkins
        plugins: [
            'karma-jasmine',
            'karma-phantomjs-launcher',
            'karma-junit-reporter',
            'karma-coverage'
        ],
        coverageReporter: {
            type:   'lcov',
            dir:    'target',
            subdir: 'coverage'
        },
        junitReporter: {
            outputDir: 'target/surefire-reports',
            suite: '',
            nameFormatter: function (browser, result) {
                return result.description;
            },
            classNameFormatter: function (browser, result) {
                return result.suite[0];
            }
        }
    });
};

Can you guide me what I'm doing wrong?

File not found

Hey,

I am very interested in being able to get my karm junit results into sonar but I am unable to get this plugin to work.

I am seeing warnings and then ultimately a failure

In the sonar-project.properties file I am setting js-module.sonar.javascript.jstestdriver.reportsPath=reports/js/unit-components/results/junit-results.xml but the plugin says it cannot find the file. Is that because of the previous warnings?

If I use js-module.sonar.javascript.jstest.reportsPath=reports/js/unit-components/results/junit-results.xml the file is found but is not in the supported format

@acwatson can you help?

09:28:41.593 INFO  - Sensor KarmaJunitReporterJsTestDriverSensor
09:28:41.593 INFO  - Parsing Unit Test run results in Surefire format from folder /Users/kevinmcdonnell/salt-developer/code/api/author/reports/js/unit-components/results/junit-results.xml
09:28:41.595 WARN  - Suite name could not be determined for "tests/integration/specs/collections/item.js"
09:28:41.597 WARN  - Suite name could not be determined for "tests/integration/specs/utils/migrateSpec.js"
09:28:41.599 WARN  - Suite name could not be determined for "tests/ui/specs/ui/customCommands/addItem.js"
09:28:41.600 WARN  - Suite name could not be determined for "tests/ui/specs/ui/customCommands/addQuestionFeature.js"
09:28:41.624 WARN  - Suite name could not be determined for "tests/ui/specs/ui/customCommands/editAuthorSiteWidget.js"
09:28:41.630 WARN  - Suite name could not be determined for "tests/ui/specs/ui/customCommands/isSaved.js"
09:28:41.631 WARN  - Suite name could not be determined for "tests/ui/specs/ui/customCommands/noErrors.js"
09:28:41.632 WARN  - Suite name could not be determined for "tests/ui/specs/ui/customCommands/onError.js"
09:28:41.633 WARN  - Suite name could not be determined for "tests/ui/specs/ui/customCommands/selectFeature.js"
09:28:41.633 WARN  - Suite name could not be determined for "tests/ui/specs/ui/customCommands/selectQuestion.js"
09:28:41.634 WARN  - Suite name could not be determined for "tests/ui/specs/ui/customCommands/setItem.js"
09:28:41.635 WARN  - Suite name could not be determined for "tests/ui/specs/ui/customCommands/toggleColumns.js"
09:28:41.636 WARN  - Suite name could not be determined for "tests/ui/specs/ui/customCommands/togglePreviewMode.js"
09:28:41.637 WARN  - Suite name could not be determined for "tests/ui/specs/ui/customCommands/uploadAsset.js"
09:28:41.638 WARN  - Suite name could not be determined for "tests/ui/specs/ui/customCommands/validateQuestions.js"
09:28:41.638 WARN  - Suite name could not be determined for "tests/ui/specs/ui/customCommands/waitForItemRender.js"
09:28:41.661 WARN  - Reports path not found: /Users/kevinmcdonnell/salt-developer/code/api/author/reports/js/unit-components/results/junit-results.xml
09:28:41.661 WARN  - No Unit Test information will be saved, because no Unit Test report has been found in the given directory: {}/Users/kevinmcdonnell/salt-developer/code/api/author/reports/js/unit-components/results/junit-results.xml
09:28:41.661 INFO  - Sensor KarmaJunitReporterJsTestDriverSensor (done) | time=68ms

Sonar Scanner fails to read karma generated report

Hi,

My project is written in TypeScript and uses karma which runs mocha and Istanbul + junit reporters to generate the coverage reports (coverage.json, lcov.info, HTML report) and a junit-style test report (test-results.xml).

We use the SonarTS plugin which works great with the code coverage (lcov.info) but using your plugin sonar scanner fails to read the corresponding junit-style test-results.xml report.
I am not sure exactly regarding the reason - the scan log is not meaningful to me.
Here are some snippets:

Snippet from test-result.xml:

<?xml version="1.0"?>
<testsuite name="PhantomJS 2.1.1 (Linux 0.0.0)" package="" timestamp="2016-11-22T13:13:30" id="0" hostname="hostname" tests="75" errors="0" failures="0" time="0.664">
  <properties>
    <property name="browser.fullName" value="Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1"/>
  </properties>
  <testcase name="bills components BillItem Should have columns for date, orderId, price &amp; view link" time="0.02" classname="PhantomJS_2_1_1_(Linux_0_0_0).bills"/>
  <testcase name="bills components BillList Should have table headers for date, order, price" time="0.009" classname="PhantomJS_2_1_1_(Linux_0_0_0).bills"/>
  <testcase name="bills components BillList Should have header table body with BillItems" time="0.002" classname="PhantomJS_2_1_1_(Linux_0_0_0).bills"/>
...
<testcase name="services components Header By default 3 buttons exist" time="0.001" classname="PhantomJS_2_1_1_(Linux_0_0_0).services"/>
  <system-out>
    <![CDATA[
]]>
  </system-out>
  <system-err/>
</testsuite>

A snippet from the scan log:

...
16:01:12.594 INFO: Sensor KarmaJunitReporterJsTestDriverSensor
16:01:12.594 INFO: Parsing Unit Test run results in Surefire format from folder /build/build_reports/test-results
16:01:12.594 DEBUG: test directory prefix is tests/
16:01:12.595 DEBUG: Attempting to determine suite name from "tests/index.js"
16:01:12.595 DEBUG: Removed "tests/" test directory prefix from relativePathKey
16:01:12.595 DEBUG: Found test file: "tests/index.js" with relativePathKey "index.js"
16:01:12.596 DEBUG: Trying to get suite name from "//"
16:01:12.596 DEBUG: Regex could not find suite name: ^(describe\((\'|\")(.*)(\'|\").*$)
16:01:12.596 DEBUG: Trying to get suite name from "//  require.context is a special webpack function"
16:01:12.596 DEBUG: Regex could not find suite name: ^(describe\((\'|\")(.*)(\'|\").*$)
16:01:12.596 DEBUG: Trying to get suite name from "//  it allows us to dynamically decide which files are considered dependency of this file and therefore will"
16:01:12.596 DEBUG: Regex could not find suite name: ^(describe\((\'|\")(.*)(\'|\").*$)
16:01:12.596 DEBUG: Trying to get suite name from "//  be processed by webpack"
16:01:12.597 DEBUG: Regex could not find suite name: ^(describe\((\'|\")(.*)(\'|\").*$)
16:01:12.597 DEBUG: Trying to get suite name from "//  In our case, we should search for all app/**/*.spec.ts files"
16:01:12.597 DEBUG: Regex could not find suite name: ^(describe\((\'|\")(.*)(\'|\").*$)
16:01:12.597 DEBUG: Trying to get suite name from "//  However since we want to generate a code coverag report we includes all application TS[x] files"
16:01:12.597 DEBUG: Regex could not find suite name: ^(describe\((\'|\")(.*)(\'|\").*$)
16:01:12.597 DEBUG: Trying to get suite name from "//  that's way a TS file that was not covered by our tests is still visible inside coverage report"
16:01:12.597 DEBUG: Regex could not find suite name: ^(describe\((\'|\")(.*)(\'|\").*$)
16:01:12.597 DEBUG: Trying to get suite name from "//"
16:01:12.597 DEBUG: Regex could not find suite name: ^(describe\((\'|\")(.*)(\'|\").*$)
16:01:12.597 DEBUG: Trying to get suite name from "const testsContext = require.context('../app', true, /\.ts[x]?$/)"
16:01:12.598 DEBUG: Regex could not find suite name: ^(describe\((\'|\")(.*)(\'|\").*$)
16:01:12.598 DEBUG: Trying to get suite name from "testsContext.keys().forEach(testsContext);"
16:01:12.598 DEBUG: Regex could not find suite name: ^(describe\((\'|\")(.*)(\'|\").*$)
16:01:12.598 WARN: Suite name could not be determined for "tests/index.js"
16:01:12.598 DEBUG: Attempting to determine suite name from "tests/int-polyfil.js"
16:01:12.598 DEBUG: Removed "tests/" test directory prefix from relativePathKey
16:01:12.598 DEBUG: Found test file: "tests/int-polyfil.js" with relativePathKey "int-polyfil.js"
16:01:12.599 DEBUG: Trying to get suite name from "!function(e){function n(r){if(t[r])return t[r].exports;var a=t[r]={exports:{},id:r,loaded:!1};return... -->a very long line which I truncated
...
16:01:12.601 DEBUG: Regex could not find suite name: ^(describe\((\'|\")(.*)(\'|\").*$)
16:01:12.601 WARN: Suite name could not be determined for "tests/int-polyfil.js"
16:01:12.712 WARN: Test result will not be saved for test class "PhantomJS_2_1_1_(Linux_0_0_0).bills", because SonarQube associated resource has not been found in suite-to-file map using key "bills".
16:01:12.712 WARN: Test result will not be saved for test class "PhantomJS_2_1_1_(Linux_0_0_0).services", because SonarQube associated resource has not been found in suite-to-file map using key "services".
16:01:12.712 WARN: Test result will not be saved for test class "PhantomJS_2_1_1_(Linux_0_0_0).(Component) AppButton", because SonarQube associated resource has not been found in suite-to-file map using key "(Component) AppButton".
16:01:12.712 WARN: Test result will not be saved for test class "PhantomJS_2_1_1_(Linux_0_0_0).login", because SonarQube associated resource has not been found in suite-to-file map using key "login".
16:01:12.712 WARN: Test result will not be saved for test class "PhantomJS_2_1_1_(Linux_0_0_0).(Component) InputGroup", because SonarQube associated resource has not been found in suite-to-file map using key "(Component) InputGroup".
16:01:12.712 WARN: Test result will not be saved for test class "PhantomJS_2_1_1_(Linux_0_0_0).(Component) Header", because SonarQube associated resource has not been found in suite-to-file map using key "(Component) Header".
16:01:12.712 INFO: Sensor KarmaJunitReporterJsTestDriverSensor (done) | time=118ms
...

Any help would be appreciated.
Thanks,
Mor

Add support for Grunt-Jasmine-Istanbul module generated Junit report

Hi Team

Please add the support for Grunt-Jasmine-Istanbul module generated Junit report.
I am able to push few of the test execution data to sonar however the test executed count are differing.

On Jenkins its showing 10 test cases executed but on sonar it shows only 5.

Jenkins console error is

23:56:37.567 WARN - Suite name could not be determined for "spec/ConvertSpec.js"
23:56:37.568 WARN - Suite name could not be determined for "spec/SpecHelper.js"
23:56:37.618 WARN - Test result will not be saved for test class "Convert", because SonarQube associated resource has not been found in suite-to-file map using key "Convert".
23:56:37.618 WARN - Test result will not be saved for test class "Player #resume", because SonarQube associated resource has not been found in suite-to-file map using key "Player #resume".
23:56:37.621 WARN - Test result will not be saved for test class "Player when song has been paused", because SonarQube associated resource has not been found in suite-to-file map using key "Player when song has been paused".

Please help

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.