Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

feat: Option to hide errors in the cli. #1005

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/usage-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ header: []
sorted: false
user: null
inline-errors: false
hide-errors: false
details: false
method: []
level: info
Expand Down
1 change: 1 addition & 0 deletions docs/usage-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function applyConfiguration(config) {
header: null,
user: null,
'inline-errors': false,
'hide-errors': false,
details: false,
method: [],
only: [],
Expand Down
4 changes: 2 additions & 2 deletions src/configure-reporters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
);
}

Expand Down
7 changes: 7 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
23 changes: 13 additions & 10 deletions src/reporters/cli-reporter.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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`);
Expand Down Expand Up @@ -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);
}
}
});

Expand All @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions test/unit/config-utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const argvData = {
user: null,
u: null,
'inline-errors': false,
'hide-errors': false,
e: false,
details: false,
d: false,
Expand Down Expand Up @@ -166,6 +167,7 @@ header: []
sorted: false
user: null
inline-errors: false
hide-errors: false
details: false
method: []
color: true
Expand Down
3 changes: 2 additions & 1 deletion test/unit/configure-reporters-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ describe('configureReporters(config, stats, tests, onSaveCallback)', () => {
reporter: [],
output: [],
silent: false,
'inline-errors': false
'inline-errors': false,
'hide-errors': false
}
};

Expand Down
1 change: 1 addition & 0 deletions test/unit/dredd-command-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ describe('DreddCommand class', () => {
sorted: false,
user: null,
'inline-errors': false,
'hide-errors': false,
details: false,
method: [],
color: true,
Expand Down