diff --git a/index.js b/index.js index d95f0c1..49cb76c 100644 --- a/index.js +++ b/index.js @@ -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; diff --git a/package.json b/package.json index 5f044c3..f9ffda9 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/index.spec.js b/test/index.spec.js index 7f2fd80..eb9e3d9 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -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'; @@ -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;