response data into testing and error handling
This commit is contained in:
@@ -6,12 +6,19 @@ const PASS = 'PASS',
|
|||||||
//TODO: probably have to use a more global state for `test`
|
//TODO: probably have to use a more global state for `test`
|
||||||
|
|
||||||
export default function runTestScriptWitVariables(script, variables) {
|
export default function runTestScriptWitVariables(script, variables) {
|
||||||
|
console.log(script);
|
||||||
|
console.log('start of the thing');
|
||||||
let pw = {
|
let pw = {
|
||||||
_errors: [],
|
_errors: [],
|
||||||
_testReports: [],
|
_testReports: [],
|
||||||
_report: '',
|
_report: '',
|
||||||
expect: function(value) {
|
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)
|
test: (descriptor, func) => test(descriptor, func, pw._testReports)
|
||||||
// globals that the script is allowed to have access to.
|
// 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.
|
// run pre-request script within this function so that it has access to the pw object.
|
||||||
let errors = null;
|
let errors = null;
|
||||||
try {
|
new Function("pw", script)(pw);
|
||||||
new Function("pw", script)(pw);
|
//
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
errors = e;
|
|
||||||
}
|
|
||||||
return {report: pw._report, errors: pw._errors, testResults: pw._testReports};
|
return {report: pw._report, errors: pw._errors, testResults: pw._testReports};
|
||||||
}
|
}
|
||||||
|
|
||||||
function test(descriptor, func, _testReports) {
|
function test(descriptor, func, _testReports) {
|
||||||
_testReports.push({startBlock: descriptor});
|
_testReports.push({startBlock: descriptor});
|
||||||
func();
|
try {
|
||||||
|
func();
|
||||||
|
} catch (e) {
|
||||||
|
_testReports.push({result: ERROR, message: e});
|
||||||
|
}
|
||||||
_testReports.push({endBlock: true});
|
_testReports.push({endBlock: true});
|
||||||
|
|
||||||
// TODO: Organieze and generate text report of each {descriptor: true} section in testReports.
|
// TODO: Organieze and generate text report of each {descriptor: true} section in testReports.
|
||||||
|
|||||||
@@ -2141,10 +2141,7 @@
|
|||||||
this.$toast.info(this.$t("finished_in", {duration}), {
|
this.$toast.info(this.$t("finished_in", {duration}), {
|
||||||
icon: "done"
|
icon: "done"
|
||||||
});
|
});
|
||||||
|
|
||||||
// tests
|
// tests
|
||||||
const testResults = runTestScriptWitVariables(this.testScript, {});
|
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
const status = (this.response.status = payload.status);
|
const status = (this.response.status = payload.status);
|
||||||
const headers = (this.response.headers = payload.headers);
|
const headers = (this.response.headers = payload.headers);
|
||||||
@@ -2171,6 +2168,17 @@
|
|||||||
};
|
};
|
||||||
this.$refs.historyComponent.addEntry(entry);
|
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) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
|
|||||||
Reference in New Issue
Block a user