UNPKG

7.31 kBMarkdownView Raw
1[![Build Status](https://travis-ci.org/larrymyers/jasmine-reporters.svg?branch=master)](https://travis-ci.org/larrymyers/jasmine-reporters)
2
3This 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
8Jasmine Reporters is a collection of javascript jasmine reporter classes that can be used with
9the [JasmineBDD testing framework](http://jasmine.github.io/).
10
11Included 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
22Should work with all modern versions of Phantom JS, and has been tested with PhantomJS
231.4.6 through 1.9.6 on Mac OS X. If you find issues with a particular version, please
24consider creating a pull request.
25
26### Node.js
27
28The 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
30combination 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
35When used for in-browser tests, the reporters are registered on a `jasmineReporters` object in the
36global scope (i.e. `window.jasmineReporters`).
37
38```javascript
39var junitReporter = new jasmineReporters.JUnitXmlReporter({
40 savePath: '..',
41 consolidateAll: false
42});
43jasmine.getEnv().addReporter(junitReporter);
44```
45
46### PhantomJS
47
48In order to write files to the local filesystem for in-browser tests, the reporters will attempt
49to use PhantomJS to create the files. A special method `__phantom_writeFile` is injected by the
50included `phantomjs.runner.sh` script.
51
52It is strongly recommended to use the provided script to run your test suite using PhantomJS. If
53you want to use your own PhantomJS runner, you will need to inject a `__phantom_writeFile`
54method, and also take care to correctly determine when all results have been reported.
55
56You 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
58included PhantomJS runner for any of the included examples--this is where the examples
59look for the Jasmine core library.
60
61```bash
62# install jasmine via bower
63bower install
64
65# run any of the examples
66bin/phantomjs.runner.sh examples/tap_reporter.html
67bin/phantomjs.runner.sh examples/junit_xml_reporter.html
68```
69
70### NodeJS
71
72In Node.js, jasmine-reporters exports an object with all the reporters which you can use
73however you like.
74
75```javascript
76var reporters = require('jasmine-reporters');
77var junitReporter = new reporters.JUnitXmlReporter({
78 savePath: __dirname,
79 consolidateAll: false
80});
81jasmine.getEnv().addReporter(junitReporter)
82```
83
84### More examples
85
86An example for each reporter is available in the `examples` directory.
87
88# Changes in jasmine-reporters@2.0
89
90jasmine-reporters is built for Jasmine 2.x. If you are still using Jasmine 1.x, please use
91the 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
109As of Protractor 1.6.0, protractor supports Jasmine 2 by specifying
110`framework: "jasmine2"` in your protractor.conf file.
111
112First, install a Jasmine 2.x-compatible of jasmine-reporters:
113
114```bash
115npm install --save-dev jasmine-reporters@^2.0.0
116```
117
118Then set everything up inside your protractor.conf:
119
120```javascript
121framework: 'jasmine2',
122onPrepare: 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
134If you run a `multiCapabilities` setup you can reflect this in your test results
135by using the option `modifySuiteName`. This enables you to have distinct suite
136names per capability.
137
138```javascript
139multiCapabilities: [
140 {browserName: 'firefox'},
141 {browserName: 'chrome'}
142],
143framework: 'jasmine2',
144onPrepare: 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
168You can also use the `modifyReportFileName` option to generate distinct
169filenames when `consolidateAll` is `false`.
170
171```javascript
172multiCapabilities: [
173 {browserName: 'firefox'},
174 {browserName: 'chrome'}
175],
176framework: 'jasmine2',
177onPrepare: 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