diff --git a/docs/usage-cli.md b/docs/usage-cli.md index 79cd2aedf..a31bd0a2e 100644 --- a/docs/usage-cli.md +++ b/docs/usage-cli.md @@ -60,6 +60,7 @@ header: [] sorted: false user: null inline-errors: false +hide-errors: false details: false method: [] level: info diff --git a/docs/usage-js.md b/docs/usage-js.md index 89f3c3e8f..13167d0cf 100644 --- a/docs/usage-js.md +++ b/docs/usage-js.md @@ -51,6 +51,7 @@ Let's have a look at an example configuration first. (Please also see [options s 'output': [], // Array of Strings, filepaths to files used for output of file-based reporters 'inline-errors': false, // Boolean, If failures/errors are display immediately in Dredd run + 'hide-errors': false, // Boolean, Hide all errors in the cli. Useful if another reporter is reporting the errors (eg. html or apiary). Setting this to true will override the inline-errors option. 'color': true, 'timestamp': false diff --git a/src/configuration.js b/src/configuration.js index 814d03b49..4a80a70ad 100644 --- a/src/configuration.js +++ b/src/configuration.js @@ -50,6 +50,7 @@ function applyConfiguration(config) { header: null, user: null, 'inline-errors': false, + 'hide-errors': false, details: false, method: [], only: [], diff --git a/src/configure-reporters.js b/src/configure-reporters.js index db43870d9..2c4125dc5 100644 --- a/src/configure-reporters.js +++ b/src/configure-reporters.js @@ -37,13 +37,13 @@ function configureReporters(config, stats, tests, runner) { const usedCliReporters = intersection(reportersArr, cliReporters); if (usedCliReporters.length === 0) { return new CliReporter( - config.emitter, stats, tests, config.options['inline-errors'], config.options.details + config.emitter, stats, tests, config.options['inline-errors'], config.options.details, config.options['hide-errors'] ); } return addReporter(usedCliReporters[0], config.emitter, stats, tests); } return new CliReporter( - config.emitter, stats, tests, config.options['inline-errors'], config.options.details + config.emitter, stats, tests, config.options['inline-errors'], config.options.details, config.options['hide-errors'] ); } diff --git a/src/options.js b/src/options.js index 9ca0bf5a7..0e57d2426 100644 --- a/src/options.js +++ b/src/options.js @@ -105,6 +105,13 @@ occur (true) or aggregated and displayed at the end (false).\n`, default: false }, + 'hide-errors': { + description: ` +Determines whether failures and errors are displayed on the +cli (true) or hidden from the cli (false).\n`, + default: false + }, + details: { alias: 'd', description: 'Determines whether request/response details are included in passing tests.\n', diff --git a/src/reporters/cli-reporter.js b/src/reporters/cli-reporter.js index 5912101d2..82fb7ec30 100644 --- a/src/reporters/cli-reporter.js +++ b/src/reporters/cli-reporter.js @@ -1,12 +1,13 @@ const logger = require('./../logger'); const prettifyResponse = require('./../prettify-response'); -function CliReporter(emitter, stats, tests, inlineErrors, details) { +function CliReporter(emitter, stats, tests, inlineErrors, details, hideErrors) { this.type = 'cli'; this.stats = stats; this.tests = tests; this.inlineErrors = inlineErrors; this.details = details; + this.hideErrors = hideErrors; this.errors = []; this.configureEmitter(emitter); @@ -21,7 +22,7 @@ CliReporter.prototype.configureEmitter = function (emitter) { }); emitter.on('end', (callback) => { - if (!this.inlineErrors) { + if (!this.inlineErrors && !this.hideErrors) { if (this.errors.length !== 0) { logger.info('Displaying failed tests...'); } for (const test of this.errors) { logger.fail(`${test.title} duration: ${test.duration}ms`); @@ -58,13 +59,15 @@ CliReporter.prototype.configureEmitter = function (emitter) { emitter.on('test fail', (test) => { logger.fail(`${test.title} duration: ${test.duration}ms`); - if (this.inlineErrors) { - logger.fail(test.message); - if (test.request) { logger.request(`\n${prettifyResponse(test.request)}\n`); } - if (test.expected) { logger.expected(`\n${prettifyResponse(test.expected)}\n`); } - if (test.actual) { logger.actual(`\n${prettifyResponse(test.actual)}\n\n`); } - } else { - this.errors.push(test); + if (!this.hideErrors) { + if (this.inlineErrors) { + logger.fail(test.message); + if (test.request) { logger.request(`\n${prettifyResponse(test.request)}\n`); } + if (test.expected) { logger.expected(`\n${prettifyResponse(test.expected)}\n`); } + if (test.actual) { logger.actual(`\n${prettifyResponse(test.actual)}\n\n`); } + } else { + this.errors.push(test); + } } }); @@ -83,7 +86,7 @@ CliReporter.prototype.configureEmitter = function (emitter) { test.message = 'Error connecting to server under test!'; } - if (!this.inlineErrors) { + if (!this.inlineErrors && !this.hideErrors) { this.errors.push(test); } diff --git a/test/unit/config-utils-test.js b/test/unit/config-utils-test.js index 5286e42df..9da7361bb 100644 --- a/test/unit/config-utils-test.js +++ b/test/unit/config-utils-test.js @@ -43,6 +43,7 @@ const argvData = { user: null, u: null, 'inline-errors': false, + 'hide-errors': false, e: false, details: false, d: false, @@ -166,6 +167,7 @@ header: [] sorted: false user: null inline-errors: false +hide-errors: false details: false method: [] color: true diff --git a/test/unit/configure-reporters-test.js b/test/unit/configure-reporters-test.js index dbfdd76c3..78b6aa8b3 100644 --- a/test/unit/configure-reporters-test.js +++ b/test/unit/configure-reporters-test.js @@ -53,7 +53,8 @@ describe('configureReporters(config, stats, tests, onSaveCallback)', () => { reporter: [], output: [], silent: false, - 'inline-errors': false + 'inline-errors': false, + 'hide-errors': false } }; diff --git a/test/unit/dredd-command-test.js b/test/unit/dredd-command-test.js index 7c2f0d5dd..aae9695fe 100644 --- a/test/unit/dredd-command-test.js +++ b/test/unit/dredd-command-test.js @@ -441,6 +441,7 @@ describe('DreddCommand class', () => { sorted: false, user: null, 'inline-errors': false, + 'hide-errors': false, details: false, method: [], color: true,