Skip to content

Commit

Permalink
fix: makes "ensureTestStructure" operate as a side-effect
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-zakharchenko committed Aug 22, 2019
1 parent 24cd543 commit 8483579
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions lib/TransactionRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,20 +332,16 @@ class TransactionRunner {
};
}

ensureTestStructure(test, transaction) {
return {
...test,

// If a test is skipped the data below will never be set on it.
// This makes a skipped test not inspectable in the Apiary repoter.
request: transaction.request,
actual: transaction.actual,
expected: transaction.expected,

// Ensure transaction errors are propagates to the test.
// That way transaction errors are a part of an Apiary Reporter.
errors: transaction.errors,
};
// Purposely side-effectish method to ensure "transaction.test"
// inherits data from the "transaction".
// Necessary when a test is skipped/failed to contain
// transaction information that is otherwise missing.
ensureTestStructure(transaction) {
transaction.test.request = transaction.request;
transaction.test.expected = transaction.expected;
transaction.test.actual = transaction.actual;
transaction.test.errors = transaction.errors;
transaction.test.results = transaction.results;
}

// Marks the transaction as failed and makes sure everything in the transaction
Expand All @@ -361,9 +357,7 @@ class TransactionRunner {
transaction.test.status = 'fail';
if (reason) { transaction.test.message = reason; }

transaction.test = this.ensureTestStructure(transaction.test, transaction);

return transaction.results;
this.ensureTestStructure(transaction);
}

// Marks the transaction as skipped and makes sure everything in the transaction
Expand All @@ -380,9 +374,7 @@ class TransactionRunner {
transaction.test.status = 'skip';
if (reason) { transaction.test.message = reason; }

transaction.test = this.ensureTestStructure(transaction.test, transaction);

return transaction.results;
this.ensureTestStructure(transaction);
}

// Ensures that given transaction object has the "errors" key
Expand Down

0 comments on commit 8483579

Please sign in to comment.