From dbba0cf847bd83222b7d45f376ac0535cb379147 Mon Sep 17 00:00:00 2001 From: Nicholas Palenchar Date: Wed, 8 Jan 2020 20:40:50 -0500 Subject: [PATCH] wip --- functions/postwomanTesting.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 functions/postwomanTesting.js diff --git a/functions/postwomanTesting.js b/functions/postwomanTesting.js new file mode 100644 index 000000000..096ee9d32 --- /dev/null +++ b/functions/postwomanTesting.js @@ -0,0 +1,31 @@ +export default function runTestScriptWitVariables(script, variables) { + + let pw = { + assert + // globals that the script is allowed to have access to. + }; + Object.assign(pw, variables); + + // run pre-request script within this function so that it has access to the pw object. + let errors = null; + try { + new Function("pw", script)(pw); + } + catch (e) { + errors = e; + } + return errors; + +} + +function assert(expression) { + if (!expression) { + throw {name: "PostWomanTestError", message: "expression evaluated to false"} + } +} + +class PostwomanTestFailure { + constructor(message) { + return {message} + } +}