From 61bf7353151bc74c943aeb548b0bd1671b4c36c0 Mon Sep 17 00:00:00 2001 From: Nicholas Palenchar Date: Sun, 19 Jan 2020 11:28:23 -0500 Subject: [PATCH] response data into testing and error handling --- functions/postwomanTesting.js | 23 +++++++++++++++-------- pages/index.vue | 14 +++++++++++--- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/functions/postwomanTesting.js b/functions/postwomanTesting.js index 02e38b088..a1d7cfd60 100644 --- a/functions/postwomanTesting.js +++ b/functions/postwomanTesting.js @@ -6,12 +6,19 @@ const PASS = 'PASS', //TODO: probably have to use a more global state for `test` export default function runTestScriptWitVariables(script, variables) { + console.log(script); + console.log('start of the thing'); let pw = { _errors: [], _testReports: [], _report: '', expect: function(value) { - return expect(value, this._testReports, arguments) }, + try { + return expect(value, this._testReports, arguments); + } catch (e) { + pw._testReports.push({result: ERROR, message: e}); + } + }, test: (descriptor, func) => test(descriptor, func, pw._testReports) // globals that the script is allowed to have access to. }; @@ -19,18 +26,18 @@ export default function runTestScriptWitVariables(script, 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; - } + new Function("pw", script)(pw); + // return {report: pw._report, errors: pw._errors, testResults: pw._testReports}; } function test(descriptor, func, _testReports) { _testReports.push({startBlock: descriptor}); - func(); + try { + func(); + } catch (e) { + _testReports.push({result: ERROR, message: e}); + } _testReports.push({endBlock: true}); // TODO: Organieze and generate text report of each {descriptor: true} section in testReports. diff --git a/pages/index.vue b/pages/index.vue index 4b486afce..3e16e1b47 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -2141,10 +2141,7 @@ this.$toast.info(this.$t("finished_in", {duration}), { icon: "done" }); - // tests - const testResults = runTestScriptWitVariables(this.testScript, {}); - (() => { const status = (this.response.status = payload.status); const headers = (this.response.headers = payload.headers); @@ -2171,6 +2168,17 @@ }; this.$refs.historyComponent.addEntry(entry); })(); + + const syntheticResponse = { + status: this.response.status, + body: this.response.body, + headers: this.response.headers + }; + console.log(syntheticResponse); + debugger; + const testResults = runTestScriptWitVariables(this.testScript, {response: syntheticResponse}); + console.log('$$$', testResults); + } catch (error) { console.error(error); if (error.response) {