test-machinepack
Advanced tools
Comparing version 2.1.10 to 2.1.11
{ | ||
"name": "test-machinepack", | ||
"author": "Mike McNeil <@mikermcneil>", | ||
"version": "2.1.10", | ||
"version": "2.1.11", | ||
"description": "Raw test runner for machinepacks (also includes a simple stub test driver)", | ||
@@ -19,2 +19,4 @@ "keywords": [ | ||
"async": "0.9.2", | ||
"chalk": "^1.1.3", | ||
"json-diff": "0.3.1", | ||
"json5": "0.4.0", | ||
@@ -21,0 +23,0 @@ "lodash": "3.9.1", |
@@ -8,4 +8,6 @@ /** | ||
var async = require('async'); | ||
var JsonDiffer = require('json-diff'); | ||
var Machines = require('machinepack-machines'); | ||
var rttc = require('rttc'); | ||
var chalk = require('chalk'); | ||
@@ -170,5 +172,8 @@ | ||
// TODO: support `maxDuration` assertion | ||
// (but this should be accomplished by just calling testMachine()-- it's already implemented there) | ||
tookTooLong: false, | ||
// TODO: support `after` assertion (custom asynchronous function) | ||
// We could eventually support `postConditions` here | ||
// (maybe relevant for json5 files that can support functions) | ||
// (but if we do it, this should be accomplished by just calling testMachine()-- it's already implemented there.) | ||
failedPostcondition: false | ||
@@ -247,3 +252,25 @@ }; | ||
if (testResultObj.wrongOutput) { | ||
_testFailedErr.message += util.format(' Expected output was: `%s` (a %s) -- but actually the machine returned: `%s` (a %s)', util.inspect(outputAssertion, false, null), rttc.getDisplayType(outputAssertion), util.inspect(_testFailedErr.actual.output, false, null), rttc.getDisplayType(_testFailedErr.actual.output)); | ||
// Showing full expected output AND actual output can get really overwhelming sometimes. | ||
// So we check how big this stuff is before showing that. | ||
// | ||
// If the expected output AND actual output are both objects of some kind (could be arrays | ||
// too) then try to compute the JSON diff and use that. | ||
var diffStr; | ||
if (_.isObject(testResultObj.actual.output) && _.isObject(outputAssertion)){ | ||
try { | ||
diffStr = JsonDiffer.diffString(testResultObj.actual.output, outputAssertion); | ||
} catch (e) { /*ignore errors here-- we just use the more basic output if that happens */ } | ||
} | ||
if (diffStr) { | ||
_testFailedErr.message += util.format( | ||
' Expected output was a %s -- but actually the machine returned a %s. (diff below...)\n'+ | ||
chalk.reset(' Diff:'), rttc.getDisplayType(outputAssertion), rttc.getDisplayType(testResultObj.actual.output), diffStr); | ||
} | ||
// If that doesn't work, or if either the expected or actual output is a non-object, | ||
// then just show the normal expected vs. actual message: | ||
else { | ||
_testFailedErr.message += util.format(' Expected output was: `%s` (a %s) -- but actually the machine returned: `%s` (a %s)', util.inspect(outputAssertion, false, null), rttc.getDisplayType(outputAssertion), util.inspect(whatActuallyHappened.output, false, null), rttc.getDisplayType(testResultObj.actual.output)); | ||
} | ||
} | ||
@@ -250,0 +277,0 @@ |
@@ -127,3 +127,6 @@ module.exports = require('machine').build({ | ||
var rttc = require('rttc'); | ||
var JsonDiffer = require('json-diff'); | ||
var chalk = require('chalk'); | ||
if (_.isArray(inputs.using) || !_.isObject(inputs.using)) { | ||
@@ -374,3 +377,24 @@ return exits.error('Invalid input value for `using`. Should be a dictionary of input values.'); | ||
if (failureReport.wrongOutput) { | ||
failureReport.message += util.format(' Expected output was: `%s` (a %s) -- but actually the machine returned: `%s` (a %s)', util.inspect(outputAssertion, false, null), rttc.getDisplayType(outputAssertion), util.inspect(whatActuallyHappened.output, false, null), rttc.getDisplayType(failureReport.actual.output)); | ||
// Showing full expected output AND actual output can get really overwhelming sometimes. | ||
// So we check how big this stuff is before showing that. | ||
// | ||
// If the expected output AND actual output are both objects of some kind (could be arrays | ||
// too) then try to compute the JSON diff and use that. | ||
var diffStr; | ||
if (_.isObject(failureReport.actual.output) && _.isObject(outputAssertion)){ | ||
try { | ||
diffStr = JsonDiffer.diffString(failureReport.actual.output, outputAssertion); | ||
} catch (e) { /*ignore errors here-- we just use the more basic output if that happens */ } | ||
} | ||
if (diffStr) { | ||
failureReport.message += util.format( | ||
' Expected output was a %s -- but actually the machine returned a %s. (diff below...)\n'+ | ||
chalk.reset(' Diff:'), rttc.getDisplayType(outputAssertion), rttc.getDisplayType(failureReport.actual.output), diffStr); | ||
} | ||
// If that doesn't work, or if either the expected or actual output is a non-object, | ||
// then just show the normal expected vs. actual message: | ||
else { | ||
failureReport.message += util.format(' Expected output was: `%s` (a %s) -- but actually the machine returned: `%s` (a %s)', util.inspect(outputAssertion, false, null), rttc.getDisplayType(outputAssertion), util.inspect(whatActuallyHappened.output, false, null), rttc.getDisplayType(failureReport.actual.output)); | ||
} | ||
} | ||
@@ -377,0 +401,0 @@ |
39879
774
8
+ Addedchalk@^1.1.3
+ Addedjson-diff@0.3.1
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedcli-color@0.1.7(transitive)
+ Addeddifflib@0.2.4(transitive)
+ Addeddreamopt@0.6.0(transitive)
+ Addedes5-ext@0.8.2(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedheap@0.2.7(transitive)
+ Addedjson-diff@0.3.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedwordwrap@1.0.0(transitive)