Skip to content

Commit

Permalink
chore(branch): Merge branch 'master' of https://github.com/mlex/karma…
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom McGeehon committed Mar 29, 2016
2 parents 1be87ea + 05efc29 commit e42aa92
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 13 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ karma.conf.js file
suppressErrorSummary: true, // do not print error summary
suppressFailed: false, // do not print information about failed tests
suppressPassed: false, // do not print information about passed tests
suppressSkipped: true // do not print information about skipped tests
suppressSkipped: true, // do not print information about skipped tests
showSpecTiming: false // print the time elapsed for each spec
},
plugins: ["karma-spec-reporter"],
...
Expand Down
26 changes: 14 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ require('colors');
var SpecReporter = function(baseReporterDecorator, formatError, config) {
baseReporterDecorator(this);

var reporterCfg = config.specReporter || {};
var prefixes = reporterCfg.prefixes || {
success: '✓ ',
failure: '✗ ',
skipped: '- ',
};

this.failures = [];
this.USE_COLORS = false;

Expand Down Expand Up @@ -74,22 +81,25 @@ var SpecReporter = function(baseReporterDecorator, formatError, config) {
if (index === 0) {
this.writeCommonMsg('\n');
}

this.writeCommonMsg(indent + value + '\n');
this.currentSuite = [];
}
indent += " ";

indent += ' ';
}, this);

this.currentSuite = suite;

var specName = result.description;
//TODO: add timing information
var elapsedTime = reporterCfg.showSpecTiming ? ' (' + result.time + 'ms)' : '';

if(this.USE_COLORS) {
if(result.skipped) specName = specName.cyan;
else if(!result.success) specName = specName.red;
}

var msg = indent + status + specName;
var msg = indent + status + specName + elapsedTime;

result.log.forEach(function(log) {
if (reporterCfg.maxLogLines) {
Expand All @@ -103,9 +113,6 @@ var SpecReporter = function(baseReporterDecorator, formatError, config) {
// NOTE: other useful properties
// browser.id;
// browser.fullName;
// result.time;
// result.skipped;
// result.success;
}).bind(this);
};

Expand All @@ -119,12 +126,6 @@ var SpecReporter = function(baseReporterDecorator, formatError, config) {
}
};

var reporterCfg = config.specReporter || {};
var prefixes = reporterCfg.prefixes || {
success: '✓ ',
failure: '✗ ',
skipped: '- '
};

function noop(){}
this.onSpecFailure = function(browsers, results) {
Expand All @@ -136,6 +137,7 @@ var SpecReporter = function(baseReporterDecorator, formatError, config) {
this.specSkipped = reporterCfg.suppressSkipped ? noop : this.writeSpecMessage(this.USE_COLORS ? prefixes.skipped.cyan : prefixes.skipped);
this.specFailure = reporterCfg.suppressFailed ? noop : this.onSpecFailure;
this.suppressErrorSummary = reporterCfg.suppressErrorSummary || false;
this.showSpecTiming = reporterCfg.showSpecTiming || false;
};

SpecReporter.$inject = ['baseReporterDecorator', 'formatError', 'config'];
Expand Down
34 changes: 34 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global beforeEach, it, describe */

'use strict';
var chai = require('chai');
var sinon = require('sinon');
Expand Down Expand Up @@ -76,6 +78,7 @@ describe('SpecReporter', function () {
newSpecReporter.TOTAL_FAILED.should.equal(ansiColors.red + 'TOTAL: %d FAILED, %d SUCCESS' + ansiColors.reset + '\n');
});
});

describe('and there are configurations set for the spec reporter', function () {
describe('and suppressFailed is truthy', function () {
var newSpecReporter;
Expand All @@ -91,6 +94,7 @@ describe('SpecReporter', function () {
expect(newSpecReporter.specFailure()).to.equal();
});
});

describe('and suppressSkipped is truthy', function () {
var newSpecReporter;
var config = {};
Expand All @@ -105,6 +109,7 @@ describe('SpecReporter', function () {
expect(newSpecReporter.specSkipped()).to.equal();
});
});

describe('and suppressPassed is truthy', function () {
var newSpecReporter;
var config = {};
Expand All @@ -119,6 +124,7 @@ describe('SpecReporter', function () {
expect(newSpecReporter.specSuccess()).to.equal();
});
});

describe('and suppressErrorSummary is truthy', function () {
var newSpecReporter;
var config = {};
Expand All @@ -133,8 +139,24 @@ describe('SpecReporter', function () {
newSpecReporter.suppressErrorSummary.should.equal(true);
});
});

describe('and showSpecTiming is truthy', function () {
var newSpecReporter;
var config = {};
beforeEach(function () {
config.specReporter = {
showSpecTiming: true,
};
newSpecReporter = new SpecReporter[1](baseReporterDecorator, formatError, config);
});

it('should set the showSpecTiming flag to true', function () {
newSpecReporter.showSpecTiming.should.equal(true);
});
});
});
});

describe('functionality', function () {
describe('onRunComplete', function () {
describe('with no browsers', function () {
Expand All @@ -152,13 +174,16 @@ describe('SpecReporter', function () {
newSpecReporter.currentSuite.length.should.equal(0);
newSpecReporter.failures.length.should.equal(0);
});

it('should call writeCommonMsg', function () {
newSpecReporter.writeCommonMsg.should.have.been.called;
});

it('should call write', function () {
newSpecReporter.write.should.have.been.called;
});
});

describe('with browsers', function () {
describe('and there are no failures', function () {
var newSpecReporter;
Expand All @@ -178,10 +203,12 @@ describe('SpecReporter', function () {
it('should call to write all of the successful specs', function () {
newSpecReporter.write.should.have.been.calledWith(undefined, 10);
});

it('should reset failures and currentSuite arrays', function () {
newSpecReporter.currentSuite.length.should.equal(0);
newSpecReporter.failures.length.should.equal(0);
});

it('should call writeCommonMsg', function () {
newSpecReporter.writeCommonMsg.should.have.been.called;
});
Expand Down Expand Up @@ -210,17 +237,21 @@ describe('SpecReporter', function () {
it('should call to write all of the failed and successful specs', function () {
newSpecReporter.write.should.have.been.calledWith(undefined, 10, 0);
});

it('should reset failures and currentSuite arrays', function () {
newSpecReporter.currentSuite.length.should.equal(0);
newSpecReporter.failures.length.should.equal(0);
});

it('should call writeCommonMsg', function () {
newSpecReporter.writeCommonMsg.should.have.been.called;
});

it('should not call to log the final errors', function () {
newSpecReporter.logFinalErrors.should.not.have.been.called;
});
});

describe('and suppressErrorSummary is false', function () {
var newSpecReporter;
var config = {};
Expand All @@ -239,13 +270,16 @@ describe('SpecReporter', function () {
it('should call to write all of the failed and successful specs', function () {
newSpecReporter.write.should.have.been.calledWith(undefined, 10, 0);
});

it('should reset failures and currentSuite arrays', function () {
newSpecReporter.currentSuite.length.should.equal(0);
newSpecReporter.failures.length.should.equal(0);
});

it('should call writeCommonMsg', function () {
newSpecReporter.writeCommonMsg.should.have.been.called;
});

it('should call to log the final errors', function () {
newSpecReporter.logFinalErrors.should.have.been.called;
});
Expand Down

0 comments on commit e42aa92

Please sign in to comment.