Skip to content

Commit

Permalink
fix: allow test prefixes to be overridden on win32
Browse files Browse the repository at this point in the history
  • Loading branch information
fluffynuts committed Mar 15, 2017
1 parent dac41c0 commit 92d66fe
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 18 deletions.
20 changes: 9 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ require('colors');
var SpecReporter = function (baseReporterDecorator, formatError, config) {
baseReporterDecorator(this);

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

if (process && process.platform === 'win32') {
this.prefixes.success = '\u221A ';
this.prefixes.failure = '\u00D7 ';
this.prefixes.skipped = '- ';
var platform = process ? process.platform : 'unknown';
var selectPrefix = function(defaultMarker, win32Marker) {
return platform === 'win32' ? win32Marker : defaultMarker;
}
var reporterCfg = config.specReporter || {};
this.prefixes = Object.assign({
success: selectPrefix('✓ ', '\u221A '),
failure: selectPrefix('✗ ', '\u00D7 '),
skipped: selectPrefix('- ', '\- ')
}, reporterCfg.prefixes);

this.failures = [];
this.USE_COLORS = false;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"test": "mocha-runner --reporter spec test/**/*.spec.js",
"coverage": "istanbul cover -x test/**/*.js ./node_modules/.bin/mocha-runner -- --reporter spec test/**/*.js"
"coverage": "istanbul cover -x test/**/*.js node_modules/mocha/bin/_mocha -- --reporter spec test/**/*.js"
},
"repository": {
"type": "git",
Expand Down
58 changes: 52 additions & 6 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ var baseReporterDecorator = function (context) {
describe('SpecReporter', function () {
describe('when initializing', function () {
describe('and on a windows machine', function () {
var newSpecReporter;
var config = {};

beforeEach(function () {
function createSpecReporter(config) {
config = config || {};
var processMock = {
platform: function () {
return 'win32';
Expand All @@ -84,14 +82,62 @@ describe('SpecReporter', function () {
platform: 'win32'
}
});
newSpecReporter = new reporterRewire['reporter:spec'][1](baseReporterDecorator, formatError, config);
});
return new reporterRewire['reporter:spec'][1](baseReporterDecorator, formatError, config);
};

it('SpecReporter should have icons defined appropriately', function () {
var newSpecReporter = createSpecReporter();
newSpecReporter.prefixes.success.should.equal(windowsIcons.success);
newSpecReporter.prefixes.failure.should.equal(windowsIcons.failure);
newSpecReporter.prefixes.skipped.should.equal(windowsIcons.skipped);
});

function createConfigWithPrefixes(prefixes) {
return {
specReporter: {
prefixes: prefixes
}
}
}
it('SpecReporter should allow overriding success icon only', function () {
var expected = 'PASS';
var config = createConfigWithPrefixes({ success: expected });
var newSpecReporter = createSpecReporter(config);
newSpecReporter.prefixes.success.should.equal(expected);
newSpecReporter.prefixes.failure.should.equal(windowsIcons.failure);
newSpecReporter.prefixes.skipped.should.equal(windowsIcons.skipped);
});

it('SpecReporter should allow overriding failure icon only', function () {
var expected = 'FAIL';
var config = createConfigWithPrefixes({ failure: expected });
var newSpecReporter = createSpecReporter(config);
newSpecReporter.prefixes.success.should.equal(windowsIcons.success);
newSpecReporter.prefixes.failure.should.equal(expected);
newSpecReporter.prefixes.skipped.should.equal(windowsIcons.skipped);
});

it('SpecReporter should allow overriding skipped icon only', function () {
var expected = 'SKIPPED';
var config = createConfigWithPrefixes({ skipped: expected });
var newSpecReporter = createSpecReporter(config);
newSpecReporter.prefixes.success.should.equal(windowsIcons.success);
newSpecReporter.prefixes.failure.should.equal(windowsIcons.failure);
newSpecReporter.prefixes.skipped.should.equal(expected);
});

it('SpecReporter should allow overriding all icons', function () {
var config = createConfigWithPrefixes({
skipped: 'Skipped',
failure: 'Failed',
success: 'Win!'
});
var expected = config.specReporter.prefixes;
var newSpecReporter = createSpecReporter(config);
newSpecReporter.prefixes.success.should.equal(expected.success);
newSpecReporter.prefixes.failure.should.equal(expected.failure);
newSpecReporter.prefixes.skipped.should.equal(expected.skipped);
});
});
describe('and colors are not defined', function () {
var newSpecReporter;
Expand Down

0 comments on commit 92d66fe

Please sign in to comment.