Skip to content

Commit

Permalink
fix: improves explanatory comments and ApiaryReporter property fallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-zakharchenko committed Aug 19, 2019
1 parent 8feadd5 commit 8fb3820
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
16 changes: 8 additions & 8 deletions lib/TransactionRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ class TransactionRunner {
failTransaction(transaction, reason) {
transaction.fail = true;

this.ensureTransactionResultsGeneralSection(transaction);
this.ensureTransactionErrors(transaction);
if (reason) { transaction.errors.push({ severity: 'error', message: reason }); }

if (!transaction.test) { transaction.test = this.createTest(transaction); }
Expand All @@ -363,7 +363,7 @@ class TransactionRunner {
skipTransaction(transaction, reason) {
transaction.skip = true;

this.ensureTransactionResultsGeneralSection(transaction);
this.ensureTransactionErrors(transaction);
if (reason) { transaction.errors.push({ severity: 'warning', message: reason }); }

if (!transaction.test) { transaction.test = this.createTest(transaction); }
Expand All @@ -376,16 +376,16 @@ class TransactionRunner {
results = transaction.test.results = transaction.results;
}

// Ensure transaction errors are propagates to the test.
// That way transaction errors are a part of an Apiary Reporter.
// Ensure transaction errors propagate to the test.
// That way transaction errors can make it to reporters.
transaction.test.errors = transaction.errors;

return results;
}

// Ensures that given transaction object has 'results' with 'general' section
// where custom Gavel-like errors or warnings can be inserted.
ensureTransactionResultsGeneralSection(transaction) {
// Ensures that given transaction object has the "errors" key
// where custom test run errors (not validation errors) are stored.
ensureTransactionErrors(transaction) {
if (!transaction.results) { transaction.results = {}; }
if (!transaction.errors) { transaction.errors = []; }

Expand Down Expand Up @@ -446,7 +446,7 @@ class TransactionRunner {
logger.debug('Emitting to reporters: test start');
this.configuration.emitter.emit('test start', test, eventCallback);

this.ensureTransactionResultsGeneralSection(transaction);
this.ensureTransactionErrors(transaction);

if (transaction.skip) {
logger.debug('HTTP transaction was marked in hooks as to be skipped. Skipping');
Expand Down
7 changes: 2 additions & 5 deletions lib/reporters/ApiaryReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,6 @@ ApiaryReporter.prototype.configureEmitter = function configureEmitter(emitter) {
if (this.serverError === true) { return callback(); }
const data = this._transformTestToReporter(test);

if (!data.results.errors) { data.results.errors = []; }
if (!data.results.validationResult) { data.results.validationResult = {}; }

if (Array.from(CONNECTION_ERRORS).includes(error.code)) {
data.results.errors.push({
severity: 'error', message: 'Error connecting to server under test!',
Expand Down Expand Up @@ -281,8 +278,8 @@ ApiaryReporter.prototype._transformTestToReporter = function _transformTestToRep
request: test.request,
realResponse: test.actual,
expectedResponse: test.expected,
validationResult: test.results,
errors: test.errors,
validationResult: test.results || {},
errors: test.errors || [],
},
};
};
Expand Down

0 comments on commit 8fb3820

Please sign in to comment.