Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix: fail state requests with response data can run tests fixes #1996

Andrew Bastin02be413effc6
diff --git a/packages/hoppscotch-app/helpers/RequestRunner.ts b/packages/hoppscotch-app/helpers/RequestRunner.ts
index 0aa11181d..bd4b2dfa3 100644
--- a/packages/hoppscotch-app/helpers/RequestRunner.ts
+++ b/packages/hoppscotch-app/helpers/RequestRunner.ts
@@ -16,7 +16,9 @@ import { HoppTestData, HoppTestResult } from "./types/HoppTestResult"
import { isJSONContentType } from "./utils/contenttypes"
import { getRESTRequest, setRESTTestResults } from "~/newstore/RESTSession"
-const getTestableBody = (res: HoppRESTResponse & { type: "success" }) => {
+const getTestableBody = (
+ res: HoppRESTResponse & { type: "success" | "fail" }
+) => {
const contentTypeHeader = res.headers.find(
(h) => h.key.toLowerCase() === "content-type"
)
@@ -60,9 +62,9 @@ export const runRESTRequest$ = (): TaskEither<
// Run Test Script when request ran successfully
const subscription = stream
- .pipe(filter((res) => res.type === "success"))
+ .pipe(filter((res) => res.type === "success" || res.type === "fail"))
.subscribe(async (res) => {
- if (res.type === "success") {
+ if (res.type === "success" || res.type === "fail") {
const runResult = await runTestScript(res.req.testScript, {
status: res.statusCode,
body: getTestableBody(res),