Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
feat: handle test script execution failure (#2104)
Rishabh Agarwal9c21013a0699
diff --git a/packages/hoppscotch-app/components/http/TestResult.vue b/packages/hoppscotch-app/components/http/TestResult.vueindex b2beeeb00..bab19666c 100644--- a/packages/hoppscotch-app/components/http/TestResult.vue+++ b/packages/hoppscotch-app/components/http/TestResult.vue@@ -62,6 +62,25 @@</div></div></div>+ <div+ v-else-if="testResults && testResults.scriptError"+ class="flex flex-col items-center justify-center flex-1 p-4"+ >+ <img+ :src="`/images/states/${$colorMode.value}/youre_lost.svg`"+ loading="lazy"+ class="inline-flex flex-col object-contain object-center w-32 h-32 my-4"+ :alt="`${t('error.test_script_fail')}`"+ />+ <span class="mb-2 font-semibold text-center">+ {{ t("error.test_script_fail") }}+ </span>+ <span+ class="max-w-sm mb-6 text-center whitespace-normal text-secondaryLight"+ >+ {{ t("helpers.test_script_fail") }}+ </span>+ </div><divv-elseclass="flex flex-col items-center justify-center p-4 text-secondaryLight"diff --git a/packages/hoppscotch-app/helpers/RequestRunner.ts b/packages/hoppscotch-app/helpers/RequestRunner.tsindex bd4b2dfa3..2453926a1 100644--- a/packages/hoppscotch-app/helpers/RequestRunner.ts+++ b/packages/hoppscotch-app/helpers/RequestRunner.ts@@ -71,9 +71,15 @@ export const runRESTRequest$ = (): TaskEither<headers: res.headers,})()- // TODO: Handle script executation fails (isLeft)if (isRight(runResult)) {setRESTTestResults(translateToSandboxTestResults(runResult.right))+ } else {+ setRESTTestResults({+ description: "",+ expectResults: [],+ tests: [],+ scriptError: true,+ })}subscription.unsubscribe()@@ -95,7 +101,9 @@ function translateToSandboxTestResults(}}return {+ description: "",expectResults: testDesc.expectResults,tests: testDesc.children.map(translateChildTests),+ scriptError: false,}}diff --git a/packages/hoppscotch-app/helpers/types/HoppTestResult.ts b/packages/hoppscotch-app/helpers/types/HoppTestResult.tsindex 7944b0bb8..31af5b58d 100644--- a/packages/hoppscotch-app/helpers/types/HoppTestResult.ts+++ b/packages/hoppscotch-app/helpers/types/HoppTestResult.ts@@ -13,4 +13,5 @@ export type HoppTestResult = {tests: HoppTestData[]expectResults: HoppTestExpectResult[]description: string+ scriptError: boolean}diff --git a/packages/hoppscotch-app/locales/en.json b/packages/hoppscotch-app/locales/en.jsonindex 045d15544..03e76a4ee 100644--- a/packages/hoppscotch-app/locales/en.json+++ b/packages/hoppscotch-app/locales/en.json@@ -182,7 +182,8 @@"network_fail": "Could not send request","no_duration": "No duration","script_fail": "Could not execute pre-request script",- "something_went_wrong": "Something went wrong"+ "something_went_wrong": "Something went wrong",+ "test_script_fail": "Could not execute post-request script"},"export": {"as_json": "Export as JSON",@@ -217,7 +218,8 @@"post_request_tests": "Test scripts are written in JavaScript, and are run after the response is received.","pre_request_script": "Pre-request scripts are written in JavaScript, and are run before the request is sent.","script_fail": "It seems there is a glitch in the pre-request script. Check the error below and fix the script accordingly.",- "tests": "Write a test script to automate debugging."+ "tests": "Write a test script to automate debugging.",+ "test_script_fail": "There seems to be an error with test script. Please fix the errors and run tests again"},"hide": {"more": "Hide more",