test-machinepack
Advanced tools
Comparing version 0.2.1 to 0.2.2
{ | ||
"name": "test-machinepack", | ||
"author": "Mike McNeil <@mikermcneil>", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Raw test runner for machinepacks (also includes a simple stub test driver)", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -33,4 +33,29 @@ /** | ||
// Ensure input configuration is ready to use | ||
// (i.e. parse JSON for inputs w/ typeclass/example of dictionary or array) | ||
// | ||
// TODO: replace this with shared logic from relevant code in the `machinepack` CLI | ||
// and in machinepack-machines. | ||
testCase.using = _.reduce(testCase.using || {}, function (memo, configuredValue, inputName) { | ||
var inputDef = machine.inputs[inputName]; | ||
if (!inputDef) { | ||
throw new Error('A test specifies a value for an input which does not actually exist in the machine definition (`'+inputName+'`).'); | ||
} | ||
if (inputDef.typeclass === 'dictionary' || inputDef.typeclass === 'array' || _.isArray(inputDef.example) || _.isPlainObject(inputDef.example)) { | ||
try { | ||
configuredValue = JSON.parse(configuredValue); | ||
} | ||
catch (e) { | ||
throw new Error('Could not parse the value for the `'+inputName+'` input specified by a test:\n'+e.stack); | ||
} | ||
} | ||
memo[inputName] = configuredValue; | ||
return memo; | ||
}, {}); | ||
// Configure the inputs | ||
var machineInstance = machine(testCase.using||{}); | ||
var machineInstance = machine(testCase.using); | ||
@@ -37,0 +62,0 @@ // Build an empty `exitsTraversed` array that will track which exit was traversed, |
16974
304