Skip to content

Commit

Permalink
modified for ICTU needs - show total stats; show passed specs, skippe…
Browse files Browse the repository at this point in the history
…d count and stack trace only on demand
  • Loading branch information
greyarch committed Jan 13, 2016
1 parent ab3d5e3 commit 0debf84
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 47 deletions.
67 changes: 46 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
# protractor-jasmine2-html-reporter
[![npm version](https://badge.fury.io/js/protractor-jasmine2-html-reporter.svg)](http://badge.fury.io/js/protractor-jasmine2-html-reporter)
# testx-html-reporter
[![npm version](https://badge.fury.io/js/testx-html-reporter.svg)](http://badge.fury.io/js/testx-html-reporter)

HTML reporter for Jasmine2 and Protractor that will include screenshots of each test if you want.
This work is inspired by:
* [Protractor Jasmine 2 Screenshot Reporter](https://github.com/mlison/protractor-jasmine2-screenshot-reporter) from [@mslison](https://github.com/mlison)
* [Jasmine Reporters](https://github.com/larrymyers/jasmine-reporters) from [@larrymyers](https://github.com/larrymyers)
HTML and screenshot reporter for *testx*.

## Usage
The <code>protractor-jasmine2-html-reporter</code> is available via npm:

<code>$ npm install protractor-jasmine2-html-reporter --save-dev</code>
This work is heavily based on [Protractor Jasmine 2 HTML Reporter](https://github.com/Kenzitron/protractor-jasmine2-html-reporter.git).

In your Protractor configuration file, register protractor-jasmine2-html-reporter in jasmine:
## Usage
In your Protractor configuration file, register testx-html-reporter:

<pre><code>var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
<pre><code>var HtmlReporter = require('testx-html-reporter');

exports.config = {
// ...
onPrepare: function() {
jasmine.getEnv().addReporter(
new Jasmine2HtmlReporter({
savePath: 'target/screenshots'
new HtmlReporter({
savePath: 'target/screenshots/'
})
);
}
Expand All @@ -33,19 +28,49 @@ Output directory for created files. All screenshots and reports will be stored h

If the directory doesn't exist, it will be created automatically or otherwise cleaned before running the test suite.

<pre><code>jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
<pre><code>jasmine.getEnv().addReporter(new HtmlReporter({
savePath: './test/reports/'
}));</code></pre>

Default folder: <code>./</code>

### Show passed specs (optional)

By default the passed specifications will not be included in the report. To include them do:

<pre><code>jasmine.getEnv().addReporter(new HtmlReporter({
showPassed: true
}));</code></pre>

Default value: <code>false</code>

### Show skipped count (optional)

By default the number of skipped specifications will not be included in the report. To include it do:

<pre><code>jasmine.getEnv().addReporter(new HtmlReporter({
showSkippedCount: true
}));</code></pre>

Default value: <code>false</code>

### Show stack trace (optional)

By default the stacktrace of failed assertions will not be included in the report. To include it do:

<pre><code>jasmine.getEnv().addReporter(new HtmlReporter({
showStacktrace: true
}));</code></pre>

Default value: <code>false</code>

### Screenshots folder (optional)

By default the screenshots are stored in a folder inside the default path

If the directory doesn't exist, it will be created automatically or otherwise cleaned before running the test suite.

<pre><code>jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
<pre><code>jasmine.getEnv().addReporter(new HtmlReporter({
savePath: './test/reports/',
screenshotsFolder: 'images'
}));</code></pre>
Expand All @@ -56,7 +81,7 @@ Default folder: <code>screenshots</code>

When this option is enabled, reporter will create screenshots for specs.

<pre><code>jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
<pre><code>jasmine.getEnv().addReporter(new HtmlReporter({
takeScreenshots: false
}));</code></pre>

Expand All @@ -67,7 +92,7 @@ Default is <code>true</code>
This option allows you to choose if create screenshots always or only when failures.
If you disable screenshots, obviously this option will not be taken into account.

<pre><code>jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
<pre><code>jasmine.getEnv().addReporter(new HtmlReporter({
takeScreenshots: true,
takeScreenshotsOnlyOnFailures: true
}));</code></pre>
Expand All @@ -78,7 +103,7 @@ Default is <code>false</code> (So screenshots are always generated)

Filename for html report.

<pre><code>jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
<pre><code>jasmine.getEnv().addReporter(new HtmlReporter({
savePath: './test/reports/',
filePrefix: 'index'
}));</code></pre>
Expand All @@ -89,9 +114,9 @@ Default is <code>htmlReport.html</code>

This option allow you to create diferent HTML for each test suite.

<pre><code>jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
<pre><code>jasmine.getEnv().addReporter(new HtmlReporter({
consolidate: true,
consolidateAll: true
}));</code></pre>

Default is <code>false</code>
Default is <code>false</code>
59 changes: 40 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,20 @@ function Jasmine2HTMLReporter(options) {
options = options || {};
self.takeScreenshots = options.takeScreenshots === UNDEFINED ? true : options.takeScreenshots;
self.savePath = options.savePath || '';
if(self.savePath && !self.savePath.endsWith('/')) {
self.savePath += "/"
}
self.takeScreenshotsOnlyOnFailures = options.takeScreenshotsOnlyOnFailures === UNDEFINED ? false : options.takeScreenshotsOnlyOnFailures;
self.screenshotsFolder = (options.screenshotsFolder || 'screenshots').replace(/^\//, '') + '/';
self.useDotNotation = options.useDotNotation === UNDEFINED ? true : options.useDotNotation;
self.consolidate = options.consolidate === UNDEFINED ? true : options.consolidate;
self.consolidateAll = self.consolidate !== false && (options.consolidateAll === UNDEFINED ? true : options.consolidateAll);
self.filePrefix = options.filePrefix || (self.consolidateAll ? 'htmlReport' : 'htmlReport-');

self.showPassed = !!options.showPassed;
self.showSkippedCount = !!options.showSkippedCount;
self.showStacktrace = !!options.showStacktrace;

var suites = [],
currentSuite = null,
totalSpecsExecuted = 0,
Expand Down Expand Up @@ -185,7 +192,15 @@ function Jasmine2HTMLReporter(options) {
self.suiteDone(fakeFocusedSuite);
}

var output = '';
var tests = 0, failed = 0, skipped = 0;
for (var i = 0; i < suites.length; i++) {
s = suites[i];
tests += s._specs.length;
failed += s._failures;
skipped += s._skipped;
}
output = '<h1' + (failed ? ' style="color:red;"' : '') + '>Tests: ' + tests +
(self.showSkippedCount ? ' Skipped: ' + skipped : '') + ' Failures: ' + failed + '</h1>';
for (var i = 0; i < suites.length; i++) {
output += self.getOrWriteNestedOutput(suites[i]);
}
Expand Down Expand Up @@ -261,32 +276,35 @@ function Jasmine2HTMLReporter(options) {
html += '<h2>' + getFullyQualifiedSuiteName(suite) + ' - ' + elapsed(suite._startTime, suite._endTime) + 's</h2>';
html += '<ul class="stats">';
html += '<li>Tests: <strong>' + suite._specs.length + '</strong></li>';
html += '<li>Skipped: <strong>' + suite._skipped + '</strong></li>';
if(self.showSkippedCount) {
html += '<li>Skipped: <strong>' + suite._skipped + '</strong></li>';
}
html += '<li>Failures: <strong>' + suite._failures + '</strong></li>';
html += '</ul> </header>';

for (var i = 0; i < suite._specs.length; i++) {
var spec = suite._specs[i];
html += '<div class="spec">';
html += specAsHtml(spec);
html += '<div class="resume">';
if (spec.screenshot !== UNDEFINED){
html += '<a href="' + self.screenshotsFolder + '/' + spec.screenshot + '">';
html += '<img src="' + self.screenshotsFolder + '/' + spec.screenshot + '" width="100" height="100" />';
html += '</a>';
}
html += '<br />';
var num_tests= spec.failedExpectations.length + spec.passedExpectations.length;
var percentage = (spec.passedExpectations.length*100)/num_tests;
html += '<span>Tests passed: ' + parseDecimalRoundAndFixed(percentage,2) + '%</span><br /><progress max="100" value="' + Math.round(percentage) + '"></progress>';
html += '</div>';
html += '</div>';
if(self.showPassed || spec.status != 'passed') {
html += '<div class="spec">';
html += specAsHtml(spec);
html += '<div class="resume">';
if (spec.screenshot !== UNDEFINED){
html += '<a href="' + self.screenshotsFolder + '/' + spec.screenshot + '">';
html += '<img src="' + self.screenshotsFolder + '/' + spec.screenshot + '" width="100" height="100" />';
html += '</a>';
}
html += '<br />';
var num_tests= spec.failedExpectations.length + spec.passedExpectations.length;
var percentage = (spec.passedExpectations.length*100)/num_tests;
html += '<span>Tests passed: ' + parseDecimalRoundAndFixed(percentage,2) + '%</span><br /><progress max="100" value="' + Math.round(percentage) + '"></progress>';
html += '</div>';
html += '</div>';
}
}
html += '\n </article>';
html += '\n </article><br/>';
return html;
}
function specAsHtml(spec) {

var html = '<div class="description">';
html += '<h3>' + escapeInvalidHtmlChars(spec.description) + ' - ' + elapsed(spec._startTime, spec._endTime) + 's</h3>';

Expand All @@ -295,6 +313,9 @@ function Jasmine2HTMLReporter(options) {
_.each(spec.failedExpectations, function(expectation){
html += '<li>';
html += expectation.message + '<span style="padding:0 1em;color:red;">&#10007;</span>';
if(self.showStacktrace) {
html += '<p><strong>Stacktrace:</strong><br/>' + expectation.stack + '</p>';
}
html += '</li>';
});
_.each(spec.passedExpectations, function(expectation){
Expand Down Expand Up @@ -358,4 +379,4 @@ function Jasmine2HTMLReporter(options) {
return this;
}

module.exports = Jasmine2HTMLReporter;
module.exports = Jasmine2HTMLReporter;
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "protractor-jasmine2-html-reporter",
"version": "0.0.5",
"description": "HTML reporter for Jasmine2 and Protractor",
"name": "testx-html-reporter",
"version": "0.1.0",
"description": "HTML reporter for testx",
"main": "index.js",
"scripts": {
"test": "protractor protractor.config.js"
},
"repository": {
"type": "git",
"url": "https://github.com/Kenzitron/protractor-jasmine2-html-reporter"
"url": "https://github.com/testxio/html-reporter.git"
},
"keywords": [
"testx",
"jasmine2",
"protractor",
"reporter",
Expand All @@ -21,10 +22,10 @@
"end2end",
"bdd"
],
"author": "Alejandro Asensio <[email protected]> (http://www.kenzilab.com/)",
"license": "BSD-2-Clause",
"author": "Greyarch BV",
"license": "ISC",
"bugs": {
"url": "https://github.com/Kenzitron/protractor-jasmine2-html-reporter/issues"
"url": "https://github.com/testxio/html-reporter/issues"
},
"dependencies": {
"hat": "0.0.3",
Expand Down

0 comments on commit 0debf84

Please sign in to comment.