1 | # karma-junit-reporter
|
2 |
|
3 | [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/karma-runner/karma-junit-reporter)
|
4 | [![npm version](https://img.shields.io/npm/v/karma-junit-reporter.svg?style=flat-square)](https://www.npmjs.com/package/karma-junit-reporter) [![npm downloads](https://img.shields.io/npm/dm/karma-junit-reporter.svg?style=flat-square)](https://www.npmjs.com/package/karma-junit-reporter)
|
5 |
|
6 | [![Build Status](https://img.shields.io/travis/karma-runner/karma-junit-reporter/master.svg?style=flat-square)](https://travis-ci.org/karma-runner/karma-junit-reporter) [![Dependency Status](https://img.shields.io/david/karma-runner/karma-junit-reporter.svg?style=flat-square)](https://david-dm.org/karma-runner/karma-junit-reporter) [![devDependency Status](https://img.shields.io/david/dev/karma-runner/karma-junit-reporter.svg?style=flat-square)](https://david-dm.org/karma-runner/karma-junit-reporter#info=devDependencies)
|
7 |
|
8 | > Reporter for the JUnit XML format.
|
9 |
|
10 | ## Installation
|
11 |
|
12 | The easiest way is to keep `karma-junit-reporter` as a devDependency in your `package.json`. Just run
|
13 |
|
14 | ```bash
|
15 | npm install karma-junit-reporter --save-dev
|
16 | ```
|
17 |
|
18 | to let npm automatically add it there.
|
19 |
|
20 | ## Configuration
|
21 |
|
22 | ```js
|
23 | // karma.conf.js
|
24 | module.exports = function(config) {
|
25 | config.set({
|
26 | reporters: ['progress', 'junit'],
|
27 |
|
28 | // the default configuration
|
29 | junitReporter: {
|
30 | outputDir: '', // results will be saved as $outputDir/$browserName.xml
|
31 | outputFile: undefined, // if included, results will be saved as $outputDir/$browserName/$outputFile
|
32 | suite: '', // suite will become the package name attribute in xml testsuite element
|
33 | useBrowserName: true, // add browser name to report and classes names
|
34 | nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element
|
35 | classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element
|
36 | properties: {}, // key value pair of properties to add to the <properties> section of the report
|
37 | xmlVersion: null // use '1' if reporting to be per SonarQube 6.2 XML format
|
38 | }
|
39 | });
|
40 | };
|
41 | ```
|
42 |
|
43 | You can pass list of reporters as a CLI argument too:
|
44 | ```bash
|
45 | karma start --reporters junit,dots
|
46 | ```
|
47 |
|
48 | ## Produce test result with schema acceptable in sonar
|
49 |
|
50 | To make this possible, it's required to make the classnames of each tests to match its file name.
|
51 |
|
52 | For Example:
|
53 | ```js
|
54 | describe('analytics.AnalyticsModule_test', function(){
|
55 |
|
56 | var analytics;
|
57 | beforeEach(module('ECApp'));
|
58 | beforeEach(module('angularytics'));
|
59 | beforeEach(module('AnalyticsModule'));
|
60 | ...
|
61 | ```
|
62 |
|
63 | should have a file name AnalyticsModule_test.js
|
64 |
|
65 | This will produce test result with schema acceptable in sonar.
|
66 |
|
67 | Grunt file reporters property example:
|
68 | ```js
|
69 | reporters: ['junit', 'coverage', 'progress'],
|
70 | junitReporter: {
|
71 | outputDir: $junitResults,
|
72 | suite: 'models'
|
73 | },
|
74 | coverageReporter: {
|
75 | type: 'lcov',
|
76 | dir: $coverageOutputDir,
|
77 | subdir: '.'
|
78 | },
|
79 | preprocessors: {
|
80 | 'src/main/webapp/public/js/ec3.3/**/*.js': 'coverage',
|
81 | 'src/main/webapp/public/js/ec3/**/*.js': 'coverage'
|
82 | },
|
83 | plugins: [
|
84 | 'karma-jasmine',
|
85 | 'karma-phantomjs-launcher',
|
86 | 'ec-karma-junit-reporter23',
|
87 | 'karma-coverage'
|
88 | ]
|
89 | ```
|
90 |
|
91 | Sonar property example:
|
92 | ```js
|
93 | sonar.projectName=js
|
94 | sonar.sources=site-main-php/src/main/webapp/public/js
|
95 | sonar.projectBaseDir=.
|
96 | sonar.exclusions=site-main-php/src/main/webapp/public/js/lib/*.js,site-main-php/src/main/webapp/public/js/tests/**/*.php,site-main-php/src/main/webapp/public/js/tests/**/*.js,site-main-php/src/main/webapp/public/js/ec3.3/vendor/**
|
97 | sonar.javascript.lcov.reportPath=site-main-php/target/coverage/lcov.info
|
98 | sonar.javascript.jstestdriver.reportsPath=site-main-php/target/surefire-reports/
|
99 | sonar.tests=site-main-php/src/main/webapp/public/js/tests
|
100 | ```
|
101 |
|
102 | Example junit xml report:
|
103 | ```xml
|
104 | <?xml version="1.0"?>
|
105 | <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">
|
106 | <properties>
|
107 | <property name="browser.fullName" value="Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.8 Safari/534.34"/>
|
108 | </properties>
|
109 | <testcase name="(C.2) Checks if an empty object is returned when error 404 is encountered" time="0.01" classname="PhantomJS_1_9_8_(Linux).models.AnalyticsModule_test"/>
|
110 | <testcase name="(C.3) Checks if an empty array is returned when error 405 is encountered" time="0.013" classname="PhantomJS_1_9_8_(Linux).models.AnalyticsModule_test"/>
|
111 | </testsuite>
|
112 | ...
|
113 | ```
|
114 | ----
|
115 |
|
116 | For more information on Karma see the [homepage].
|
117 |
|
118 |
|
119 | [homepage]: http://karma-runner.github.com
|
120 |
|