From effadea52ca1900d95cfc80e353425cfd91447b6 Mon Sep 17 00:00:00 2001 From: Shreyansh Shah Date: Mon, 6 Mar 2023 21:34:41 +0530 Subject: [PATCH 1/3] fix: empty-node-fetch-response Signed-off-by: Shreyansh Shah --- integrations/node-fetch/require.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/integrations/node-fetch/require.ts b/integrations/node-fetch/require.ts index 059f43e..8d47b8e 100644 --- a/integrations/node-fetch/require.ts +++ b/integrations/node-fetch/require.ts @@ -3,7 +3,7 @@ import Hook from "require-in-the-middle"; import { Headers, ResponseInit } from "node-fetch"; import mixin from "merge-descriptors"; -import { getExecutionContext } from "../../src/context"; +import { createExecutionContext,getExecutionContext } from "../../src/context"; import { Readable } from "stream"; import { ProcessDep, stringToBinary } from "../../src/util"; import { putMocks } from "../../mock/utils"; @@ -12,6 +12,7 @@ import { getRequestHeader, getResponseHeader } from "../express/middleware"; import { getReasonPhrase } from "http-status-codes"; import { DataBytes } from "../../proto/services/DataBytes"; import { MockIds } from "../../mock/mock"; +import { MODE_OFF } from "../../src/mode"; // @ts-ignore Hook(["node-fetch"], function (exported) { @@ -37,6 +38,9 @@ export function wrappedNodeFetch(fetch: any) { url: any, options: any ) { + if (process.env.KEPLOY_MODE == MODE_OFF) { + createExecutionContext({ mode: MODE_OFF }); + } if ( getExecutionContext() == undefined || getExecutionContext().context == undefined From 5f014eb60db42188512e2115aee19ebe287af484 Mon Sep 17 00:00:00 2001 From: Shreyansh Shah Date: Thu, 9 Mar 2023 22:44:49 +0530 Subject: [PATCH 2/3] fix: review comments Signed-off-by: Shreyansh Shah --- integrations/node-fetch/require.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/integrations/node-fetch/require.ts b/integrations/node-fetch/require.ts index 8d47b8e..f3b4ab2 100644 --- a/integrations/node-fetch/require.ts +++ b/integrations/node-fetch/require.ts @@ -3,7 +3,7 @@ import Hook from "require-in-the-middle"; import { Headers, ResponseInit } from "node-fetch"; import mixin from "merge-descriptors"; -import { createExecutionContext,getExecutionContext } from "../../src/context"; +import { getExecutionContext } from "../../src/context"; import { Readable } from "stream"; import { ProcessDep, stringToBinary } from "../../src/util"; import { putMocks } from "../../mock/utils"; @@ -39,7 +39,7 @@ export function wrappedNodeFetch(fetch: any) { options: any ) { if (process.env.KEPLOY_MODE == MODE_OFF) { - createExecutionContext({ mode: MODE_OFF }); + return fetchFunc.apply(this, [url, options]); } if ( getExecutionContext() == undefined || @@ -147,8 +147,6 @@ export function wrappedNodeFetch(fetch: any) { }); resp = new fetch.Response(Readable.from(buf), rinit); break; - case "off": - return fetchFunc.apply(this, [url, options]); default: console.debug( "mode is not valid. Please set valid keploy mode using env variables" From a9dc08bcd2d3aa60b469464194581fe5e5f5f4d9 Mon Sep 17 00:00:00 2001 From: Shreyansh Shah Date: Mon, 20 Mar 2023 23:21:04 +0530 Subject: [PATCH 3/3] fix: review comments Signed-off-by: Shreyansh Shah --- integrations/node-fetch/require.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/integrations/node-fetch/require.ts b/integrations/node-fetch/require.ts index f3b4ab2..9a57a1b 100644 --- a/integrations/node-fetch/require.ts +++ b/integrations/node-fetch/require.ts @@ -38,15 +38,12 @@ export function wrappedNodeFetch(fetch: any) { url: any, options: any ) { - if (process.env.KEPLOY_MODE == MODE_OFF) { - return fetchFunc.apply(this, [url, options]); - } if ( getExecutionContext() == undefined || getExecutionContext().context == undefined ) { console.error("keploy context is not present to mock dependencies"); - return; + return fetchFunc.apply(this, [url, options]); } const ctx = getExecutionContext().context; let resp = new fetch.Response(); @@ -147,6 +144,8 @@ export function wrappedNodeFetch(fetch: any) { }); resp = new fetch.Response(Readable.from(buf), rinit); break; + case "off": + return fetchFunc.apply(this, [url, options]); default: console.debug( "mode is not valid. Please set valid keploy mode using env variables"