karma-junit-xray-reporter

A Karma plugin. Report results in junit xml format with XRay Id(if present)

Usage no npm install needed!

<script type="module">
  import karmaJunitXrayReporter from 'https://cdn.skypack.dev/karma-junit-xray-reporter';
</script>

README

karma-junit-xray-reporter

js-standard-style

The initial code is copied from karma-junit-reporter plugin and we modified workflow, options and the results output. Also added xrayId only option

Installation

The easiest way is to keep karma-junit-xray-reporter as a devDependency in your package.json pointing to its current repo

"karma-junit-xray-reporter": "git+https://github.com/Test-Utils/karma-junit-xray-reporter.git"

To update to the latest version

npm update karma-junit-xray-reporter

Run Tests

To run tests

npm test

If you want to skip eslinter and directly run just tests

mocha tests/reporter.spec.js

Run Tests with coverage

Run tests with coverage

npm run test-with-coverage

Configuration

// karma.conf.js
module.exports = function(config) {
  config.set({
    reporters: ['progress', 'junitxray'],

    // the default configuration
    junitXrayReporter: {
      metadataFile: 'unit-tests/meta-data.json'// optional path and name of metadataFile
      outputFile: 'unit-tests/result-output.xml'// optional path and name of the output file
      suite: '',// suite will become the package name attribute in xml testsuite element
      xrayIdOnly: true, //(default false) set it to true to process only the tests that have xrayId like :XRAY-ID:XRAY-123: in the tests name for e.g ':XRAY-ID:XRAY-123: test to validate params'
    }
  });
};

You can pass list of reporters as a CLI argument too:

karma start --reporters junitxray,dots

Example junit xray xml report:

<?xml version="1.0"?>
<testsuite name="PhantomJS 1.9.8 (Linux)" package="models" timestamp="2015-03-10T13:59:23" id="0" hostname="admin" tests="629" errors="0" failures="0" time="11.452">
 <testcase xrayId="XRAY-123" name="(C.2) Checks if an empty object is returned when error 404 is encountered" time="0.01" classname="pr_tdata CTRL: prTdataLineTrendGraphsController Commence prTdataLineTrendGraphsController testing =>  getBMIStatsValue()"/>
  </testsuite>"/>
 <testcase xrayId="XRAY-223" name="(C.3) Checks if an empty array is returned when error 405 is encountered" time="0.013" classname="pr_tdata CTRL: prTdataLineTrendGraphsController Commence prTdataLineTrendGraphsController testing =>  getBMIStatsValue()"/>
  </testsuite>"/>
</testsuite>
...

For more information on Karma see the homepage.