UNPKG

4.17 kBMarkdownView Raw
1# Jasmine Reporters
2
3Jasmine Reporters is a collection of javascript jasmine.Reporter classes that can be used with
4the [JasmineBDD testing framework](http://pivotal.github.com/jasmine/).
5
6Included reporters:
7
8* JUnitXmlReporter - Report test results to a file in JUnit XML Report format.
9* NUnitXmlReporter - Report test results to a file in NUnit XML Report format.
10* TapReporter - Test Anything Protocol, report tests results to console.
11* TeamcityReporter - Basic reporter that outputs spec results to for the Teamcity build system.
12* TerminalReporter - Logs to a terminal (including colors) with variable verbosity.
13
14### PhantomJS
15
16Should work with all modern versions of Phantom JS, and has been tested with PhantomJS
171.4.6 through 1.9.6 on Mac OS X. If you find issues with a particular version, please
18consider creating a pull request.
19
20### Node.js
21
22The reporters also work in Node.js, and most can be used in combination with
23[jasmine-node](https://github.com/mhevery/jasmine-node). Make sure to use the correct
24combination of jasmine-repoters and jasmine-node, as both projects have different versions
25/ branches for Jasmine1.x vs Jasmine2.x support.
26
27# Basic Usage
28
29When used for in-browser tests, the reporters are registered on a `jasmineReporters` object in the
30global scope (i.e. `window.jasmineReporters`).
31
32 var junitReporter = new jasmineReporters.JUnitXmlReporter({
33 savePath: '..',
34 consolidateAll: false
35 });
36 jasmine.getEnv().addReporter(junitReporter);
37
38### PhantomJS
39
40In order to write files to the local filesystem for in-browser tests, the reporters will attempt
41to use PhantomJS to create the files. A special method `__phantom_writeFile` is injected by the
42included `phantomjs.runner.sh` script.
43
44It is strongly recommended to use the provided script to run your test suite using PhantomJS. If
45you want to use your own PhantomJS runner, you will need to inject a `__phantom_writeFile`
46method, and also take care to correctly determine when all results have been reported.
47
48You can use the included PhantomJS test runner to run any of the included examples.
49
50 bin/phantomjs.runner.sh test/tap_reporter.html
51 bin/phantomjs.runner.sh test/junit_xml_reporter.html
52
53### NodeJS
54
55In Node.js, jasmine-reporters exports an object with all the reporters which you can use
56however you like.
57
58 var reporters = require('jasmine-reporters');
59 var junitReporter = new reporters.JUnitXmlReporter({
60 savePath: __dirname,
61 consolidateAll: false
62 });
63
64### More examples
65
66An example for each reporter is available in the `test` directory.
67
68# Changes in jasmine-reporters@2.0
69
70jasmine-reporters is built for Jasmine 2.x. If you are still using Jasmine 1.x, please use
71the correct tag / branch / npm version:
72
73* bower: `bower install jasmine-reporters#~1.0.0`
74* Node.js: `npm install jasmine-reporters@~1.0.0`
75* git submodule: `git submodule add -b jasmine1.x git@github.com:larrymyers/jasmine-reporters.git jasmine-reporters`
76* or use any of the `1.*` tags
77
78## Migrating from Jasmine 1.x
79
80* reporters are no longer registered on the global `jasmine` object
81 * 1.x: `new jasmine.JUnitXmlReporter( /* ... */ );`
82 * 2.x: `new jasmineReporters.JUnitXmlReporter( /* ... */ );`
83* configurable reporters no longer use positional arguments
84 * 1.x: `new jasmine.JUnitXmlReporter('testresults', true, true, 'junit-', true);`
85 * 2.x: `new jasmineReporters.JUnitXmlReporter({savePath:'testresults', filePrefix: 'junit-', consolidateAll:true});`
86
87## Protractor
88
89If you are trying to use jasmine-reporters with Protractor, keep in mind that Protractor is built around
90Jasmine 1.x. As such, you need to use a 1.x version of jasmine-reporters.
91
92 npm install jasmine-reporters@~1.0.0
93
94And inside your protractor.conf:
95
96 onPrepare: function() {
97 // The require statement must be down here, since jasmine-reporters@1.0
98 // needs jasmine to be in the global and protractor does not guarantee
99 // this until inside the onPrepare function.
100 require('jasmine-reporters');
101 jasmine.getEnv().addReporter(
102 new jasmine.JUnitXmlReporter('xmloutput', true, true)
103 );
104 }