1 | [![Build Status](https://travis-ci.org/larrymyers/jasmine-reporters.svg?branch=master)](https://travis-ci.org/larrymyers/jasmine-reporters)
|
2 |
|
3 | This branch is for Jasmine 2.x.
|
4 | [Switch to the 1.x branch.](https://github.com/larrymyers/jasmine-reporters/tree/jasmine1.x)
|
5 |
|
6 | # Jasmine Reporters
|
7 |
|
8 | Jasmine Reporters is a collection of javascript jasmine reporter classes that can be used with
|
9 | the [JasmineBDD testing framework](http://jasmine.github.io/).
|
10 |
|
11 | Included reporters:
|
12 |
|
13 | * AppVeyor - POSTs results to AppVeyor when running inside an AppVeyor environment.
|
14 | * JUnitXmlReporter - Report test results to a file in JUnit XML Report format.
|
15 | * NUnitXmlReporter - Report test results to a file in NUnit XML Report format.
|
16 | * TapReporter - Test Anything Protocol, report tests results to console.
|
17 | * TeamCityReporter - Basic reporter that outputs spec results to for the Teamcity build system.
|
18 | * TerminalReporter - Logs to a terminal (including colors) with variable verbosity.
|
19 |
|
20 | ### PhantomJS
|
21 |
|
22 | Should work with all modern versions of Phantom JS, and has been tested with PhantomJS
|
23 | 1.4.6 through 1.9.6 on Mac OS X. If you find issues with a particular version, please
|
24 | consider creating a pull request.
|
25 |
|
26 | ### Node.js
|
27 |
|
28 | The reporters also work in Node.js, and most can be used in combination with
|
29 | [jasmine-node](https://github.com/mhevery/jasmine-node). Make sure to use the correct
|
30 | combination of jasmine-reporters and jasmine-node, as both projects have different versions
|
31 | / branches for Jasmine1.x vs Jasmine2.x support.
|
32 |
|
33 | # Basic Usage
|
34 |
|
35 | When used for in-browser tests, the reporters are registered on a `jasmineReporters` object in the
|
36 | global scope (i.e. `window.jasmineReporters`).
|
37 |
|
38 | ```javascript
|
39 | var junitReporter = new jasmineReporters.JUnitXmlReporter({
|
40 | savePath: '..',
|
41 | consolidateAll: false
|
42 | });
|
43 | jasmine.getEnv().addReporter(junitReporter);
|
44 | ```
|
45 |
|
46 | ### PhantomJS
|
47 |
|
48 | In order to write files to the local filesystem for in-browser tests, the reporters will attempt
|
49 | to use PhantomJS to create the files. A special method `__phantom_writeFile` is injected by the
|
50 | included `phantomjs.runner.sh` script.
|
51 |
|
52 | It is strongly recommended to use the provided script to run your test suite using PhantomJS. If
|
53 | you want to use your own PhantomJS runner, you will need to inject a `__phantom_writeFile`
|
54 | method, and also take care to correctly determine when all results have been reported.
|
55 |
|
56 | You can use the included PhantomJS test runner to run any of the included examples.
|
57 | **NOTE:** you will need to install the Jasmine dependency via `bower` if you want to use the
|
58 | included PhantomJS runner for any of the included examples--this is where the examples
|
59 | look for the Jasmine core library.
|
60 |
|
61 | ```bash
|
62 | # install jasmine via bower
|
63 | bower install
|
64 |
|
65 | # run any of the examples
|
66 | bin/phantomjs.runner.sh examples/tap_reporter.html
|
67 | bin/phantomjs.runner.sh examples/junit_xml_reporter.html
|
68 | ```
|
69 |
|
70 | ### NodeJS
|
71 |
|
72 | In Node.js, jasmine-reporters exports an object with all the reporters which you can use
|
73 | however you like.
|
74 |
|
75 | ```javascript
|
76 | var reporters = require('jasmine-reporters');
|
77 | var junitReporter = new reporters.JUnitXmlReporter({
|
78 | savePath: __dirname,
|
79 | consolidateAll: false
|
80 | });
|
81 | jasmine.getEnv().addReporter(junitReporter)
|
82 | ```
|
83 |
|
84 | ### More examples
|
85 |
|
86 | An example for each reporter is available in the `examples` directory.
|
87 |
|
88 | # Changes in jasmine-reporters@2.0
|
89 |
|
90 | jasmine-reporters is built for Jasmine 2.x. If you are still using Jasmine 1.x, please use
|
91 | the correct tag / branch / npm version:
|
92 |
|
93 | * bower: `bower install jasmine-reporters#^1.0.0`
|
94 | * Node.js: `npm install jasmine-reporters@^1.0.0`
|
95 | * git submodule: `git submodule add -b jasmine1.x git@github.com:larrymyers/jasmine-reporters.git jasmine-reporters`
|
96 | * or use any of the `1.*` tags
|
97 |
|
98 | ## Migrating from jasmine-reporters@1.0
|
99 |
|
100 | * reporters are no longer registered on the global `jasmine` object
|
101 | * 1.x: `new jasmine.JUnitXmlReporter( /* ... */ );`
|
102 | * 2.x: `new jasmineReporters.JUnitXmlReporter( /* ... */ );`
|
103 | * configurable reporters no longer use positional arguments
|
104 | * 1.x: `new jasmine.JUnitXmlReporter('testresults', true, true, 'junit-', true);`
|
105 | * 2.x: `new jasmineReporters.JUnitXmlReporter({savePath:'testresults', filePrefix: 'junit-', consolidateAll:true});`
|
106 |
|
107 | # Protractor
|
108 |
|
109 | As of Protractor 1.6.0, protractor supports Jasmine 2 by specifying
|
110 | `framework: "jasmine2"` in your protractor.conf file.
|
111 |
|
112 | First, install a Jasmine 2.x-compatible of jasmine-reporters:
|
113 |
|
114 | ```bash
|
115 | npm install --save-dev jasmine-reporters@^2.0.0
|
116 | ```
|
117 |
|
118 | Then set everything up inside your protractor.conf:
|
119 |
|
120 | ```javascript
|
121 | framework: 'jasmine2',
|
122 | onPrepare: function() {
|
123 | var jasmineReporters = require('jasmine-reporters');
|
124 | jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
|
125 | consolidateAll: true,
|
126 | savePath: 'testresults',
|
127 | filePrefix: 'xmloutput'
|
128 | }));
|
129 | }
|
130 | ```
|
131 |
|
132 | ### Multi Capabilities
|
133 |
|
134 | If you run a `multiCapabilities` setup you can reflect this in your test results
|
135 | by using the option `modifySuiteName`. This enables you to have distinct suite
|
136 | names per capability.
|
137 |
|
138 | ```javascript
|
139 | multiCapabilities: [
|
140 | {browserName: 'firefox'},
|
141 | {browserName: 'chrome'}
|
142 | ],
|
143 | framework: 'jasmine2',
|
144 | onPrepare: function() {
|
145 | var jasmineReporters = require('jasmine-reporters');
|
146 |
|
147 | // returning the promise makes protractor wait for the reporter config before executing tests
|
148 | return browser.getProcessedConfig().then(function(config) {
|
149 | // you could use other properties here if you want, such as platform and version
|
150 | var browserName = config.capabilities.browserName;
|
151 |
|
152 | var junitReporter = new jasmineReporters.JUnitXmlReporter({
|
153 | consolidateAll: true,
|
154 | savePath: 'testresults',
|
155 | // this will produce distinct xml files for each capability
|
156 | filePrefix: browserName + '-xmloutput',
|
157 | modifySuiteName: function(generatedSuiteName, suite) {
|
158 | // this will produce distinct suite names for each capability,
|
159 | // e.g. 'firefox.login tests' and 'chrome.login tests'
|
160 | return browserName + '.' + generatedSuiteName;
|
161 | }
|
162 | });
|
163 | jasmine.getEnv().addReporter(junitReporter);
|
164 | });
|
165 | }
|
166 | ```
|
167 |
|
168 | You can also use the `modifyReportFileName` option to generate distinct
|
169 | filenames when `consolidateAll` is `false`.
|
170 |
|
171 | ```javascript
|
172 | multiCapabilities: [
|
173 | {browserName: 'firefox'},
|
174 | {browserName: 'chrome'}
|
175 | ],
|
176 | framework: 'jasmine2',
|
177 | onPrepare: function() {
|
178 | var jasmineReporters = require('jasmine-reporters');
|
179 |
|
180 | // returning the promise makes protractor wait for the reporter config before executing tests
|
181 | return browser.getProcessedConfig().then(function(config) {
|
182 | // you could use other properties here if you want, such as platform and version
|
183 | var browserName = config.capabilities.browserName;
|
184 |
|
185 | var junitReporter = new jasmineReporters.JUnitXmlReporter({
|
186 | consolidateAll: false,
|
187 | savePath: 'testresults',
|
188 | modifyReportFileName: function(generatedFileName, suite) {
|
189 | // this will produce distinct file names for each capability,
|
190 | // e.g. 'firefox.SuiteName' and 'chrome.SuiteName'
|
191 | return browserName + '.' + generatedFileName;
|
192 | }
|
193 | });
|
194 | jasmine.getEnv().addReporter(junitReporter);
|
195 | });
|
196 | }
|
197 | ```
|
198 |
|