Skip to content

Commit

Permalink
feat(reporter): update icons when on windows to be compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom McGeehon committed Apr 7, 2016
1 parent e42aa92 commit 3d511a3
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 7 deletions.
16 changes: 11 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ var SpecReporter = function(baseReporterDecorator, formatError, config) {
baseReporterDecorator(this);

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

if (process && process.platform === 'win32') {

This comment has been minimized.

Copy link
@kayhadrin

kayhadrin May 18, 2016

The problem with doing this is that it will overwrite the user configuration from reporterCfg.prefixes.
I think this should be done differently to allow the user customisations to remain.

e.g.

var reporterCfg = config.specReporter || {},
      isWindows = process && process.platform === 'win32';
this.prefixes = reporterCfg.prefixes || {
  success: isWindows? '\u221A ' : '✓ ',
  failure: isWindows? '\u00D7 ' : '✗ ',
  skipped: isWindows? '. ' : '- ',
};
this.prefixes.success = '\u221A';
this.prefixes.failure = '\u00D7';
this.prefixes.skipped = '.';
}

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

Expand Down Expand Up @@ -63,7 +69,7 @@ var SpecReporter = function(baseReporterDecorator, formatError, config) {
failure.log.forEach(function(log) {
if (reporterCfg.maxLogLines) {
log = log.split('\n').slice(0, reporterCfg.maxLogLines).join('\n');
}
}
this.writeCommonMsg(this.WHITESPACE + formatError(log).replace(/\\n/g, '\n').grey);
}, this);
}, this);
Expand Down Expand Up @@ -130,11 +136,11 @@ var SpecReporter = function(baseReporterDecorator, formatError, config) {
function noop(){}
this.onSpecFailure = function(browsers, results) {
this.failures.push(results);
this.writeSpecMessage(this.USE_COLORS ? prefixes.failure.red : prefixes.failure).apply(this, arguments);
this.writeSpecMessage(this.USE_COLORS ? this.prefixes.failure.red : this.prefixes.failure).apply(this, arguments);
};

this.specSuccess = reporterCfg.suppressPassed ? noop : this.writeSpecMessage(this.USE_COLORS ? prefixes.success.green : prefixes.success);
this.specSkipped = reporterCfg.suppressSkipped ? noop : this.writeSpecMessage(this.USE_COLORS ? prefixes.skipped.cyan : prefixes.skipped);
this.specSuccess = reporterCfg.suppressPassed ? noop : this.writeSpecMessage(this.USE_COLORS ? this.prefixes.success.green : this.prefixes.success);
this.specSkipped = reporterCfg.suppressSkipped ? noop : this.writeSpecMessage(this.USE_COLORS ? this.prefixes.skipped.cyan : this.prefixes.skipped);
this.specFailure = reporterCfg.suppressFailed ? noop : this.onSpecFailure;
this.suppressErrorSummary = reporterCfg.suppressErrorSummary || false;
this.showSpecTiming = reporterCfg.showSpecTiming || false;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"coveralls": "^2.11.4",
"istanbul": "^0.4.0",
"mocha-runner": "^1.1.1",
"rewire": "^2.5.1",
"sinon": "^1.17.2",
"sinon-chai": "^2.8.0"
},
Expand Down
66 changes: 64 additions & 2 deletions test/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,58 @@
/* global beforeEach, it, describe */

'use strict';
/*
* Based upon "Function.prototype.bind polyfill for PhantomJS"
* author: Tom Watson <tom.james.watson@gmail.com>
* homepage: https://github.com/tom-james-watson/phantomjs-polyfill
*
* This fixes a compatibility issue with running Phantom1 with Angular 1.5
*/

/* jshint ignore:start */

// if (typeof Function.prototype.bind != 'function') {
// Function.prototype.bind = function bind(obj) {
// var args = Array.prototype.slice.call(arguments, 1),
// self = this,
// nop = function() {
// },
// bound = function() {
// return self.apply(
// this instanceof nop ? this : (obj || {}), args.concat(
// Array.prototype.slice.call(arguments)
// )
// );
// };
// nop.prototype = this.prototype || {};
// bound.prototype = new nop();
// return bound;
// };
// }

/* jshint ignore:end */

var rewire = require('rewire');
var chai = require('chai');
var sinon = require('sinon');
var sinonChai = require('sinon-chai');
chai.use(sinonChai);
var should = chai.should();
var expect = chai.expect;

var SpecReporter = require('../index')['reporter:spec'];
var reporterRewire = rewire('../index.js');
var SpecReporter = require('../index.js')['reporter:spec'];

var ansiColors = {
red: '\u001b[31m',
yellow: '\u001b[33m',
green: '\u001b[32m',
reset: '\u001b[39m'
};
var windowsIcons = {
success: '\u221A',
failure: '\u00D7',
skipped: '.'
}

//baseReporterDecorator functions
var formatError = function (a, b) {
Expand All @@ -30,6 +67,31 @@ var baseReporterDecorator = function (context) {

describe('SpecReporter', function () {
describe('when initializing', function () {
describe('and on a windows machine', function () {
var newSpecReporter;
var config = {};

beforeEach(function () {
var processMock = {
platform: function () {
return 'win32';
}
};
reporterRewire.__set__({
'reporter:spec': SpecReporter,
process: {
platform: 'win32'
}
});
newSpecReporter = new reporterRewire['reporter:spec'][1](baseReporterDecorator, formatError, config);
});

it('SpecReporter should have icons defined appropriately', function () {
newSpecReporter.prefixes.success.should.equal(windowsIcons.success);
newSpecReporter.prefixes.failure.should.equal(windowsIcons.failure);
newSpecReporter.prefixes.skipped.should.equal(windowsIcons.skipped);
});
});
describe('and colors are not defined', function () {
var newSpecReporter;
var config = {};
Expand Down

0 comments on commit 3d511a3

Please sign in to comment.