Sfoglia il codice sorgente

fix: revamp broken network tests

Andrew Bastin 3 anni fa
parent
commit
141697f9da

+ 0 - 84
packages/hoppscotch-app/helpers/__tests__/network-ExtDisabled.spec.js

@@ -1,84 +0,0 @@
-import { cancelRunningRequest, sendNetworkRequest } from "../network"
-
-import AxiosStrategy, {
-  cancelRunningAxiosRequest,
-} from "../strategies/AxiosStrategy"
-import ExtensionStrategy, {
-  cancelRunningExtensionRequest,
-  hasExtensionInstalled,
-} from "../strategies/ExtensionStrategy"
-
-jest.mock("../strategies/AxiosStrategy", () => ({
-  __esModule: true,
-  default: jest.fn(() => Promise.resolve()),
-  cancelRunningAxiosRequest: jest.fn(() => Promise.resolve()),
-}))
-
-jest.mock("../strategies/ExtensionStrategy", () => ({
-  __esModule: true,
-  default: jest.fn(() => Promise.resolve()),
-  cancelRunningExtensionRequest: jest.fn(() => Promise.resolve()),
-  hasExtensionInstalled: jest.fn(),
-}))
-
-jest.mock("~/newstore/settings", () => {
-  return {
-    settingsStore: {
-      value: {
-        EXTENSIONS_ENABLED: false,
-      },
-    },
-  }
-})
-
-global.$nuxt = {
-  $loading: {
-    finish: jest.fn(() => Promise.resolve()),
-  },
-}
-
-beforeEach(() => {
-  jest.clearAllMocks() // Reset the call count for the mock functions
-})
-
-describe("cancelRunningRequest", () => {
-  test("cancels only axios request if extension not allowed in settings and extension is installed", () => {
-    hasExtensionInstalled.mockReturnValue(true)
-
-    cancelRunningRequest()
-
-    expect(cancelRunningExtensionRequest).not.toHaveBeenCalled()
-    expect(cancelRunningAxiosRequest).toHaveBeenCalled()
-  })
-
-  test("cancels only axios request if extension is not allowed and not installed", () => {
-    hasExtensionInstalled.mockReturnValue(false)
-
-    cancelRunningRequest()
-
-    expect(cancelRunningExtensionRequest).not.toHaveBeenCalled()
-    expect(cancelRunningAxiosRequest).toHaveBeenCalled()
-  })
-})
-
-describe("sendNetworkRequest", () => {
-  test("runs only axios request if extension not allowed in settings and extension is installed and clears the progress bar", async () => {
-    hasExtensionInstalled.mockReturnValue(true)
-
-    await sendNetworkRequest({})
-
-    expect(ExtensionStrategy).not.toHaveBeenCalled()
-    expect(AxiosStrategy).toHaveBeenCalled()
-    expect(global.$nuxt.$loading.finish).toHaveBeenCalled()
-  })
-
-  test("runs only axios request if extension is not allowed and not installed and clears the progress bar", async () => {
-    hasExtensionInstalled.mockReturnValue(false)
-
-    await sendNetworkRequest({})
-
-    expect(ExtensionStrategy).not.toHaveBeenCalled()
-    expect(AxiosStrategy).toHaveBeenCalled()
-    expect(global.$nuxt.$loading.finish).toHaveBeenCalled()
-  })
-})

+ 0 - 83
packages/hoppscotch-app/helpers/__tests__/network-ExtEnabled.spec.js

@@ -1,83 +0,0 @@
-import { cancelRunningRequest, sendNetworkRequest } from "../network"
-
-import AxiosStrategy, {
-  cancelRunningAxiosRequest,
-} from "../strategies/AxiosStrategy"
-import ExtensionStrategy, {
-  cancelRunningExtensionRequest,
-  hasExtensionInstalled,
-} from "../strategies/ExtensionStrategy"
-
-jest.mock("../strategies/AxiosStrategy", () => ({
-  __esModule: true,
-  default: jest.fn(() => Promise.resolve()),
-  cancelRunningAxiosRequest: jest.fn(() => Promise.resolve()),
-}))
-
-jest.mock("../strategies/ExtensionStrategy", () => ({
-  __esModule: true,
-  default: jest.fn(() => Promise.resolve()),
-  cancelRunningExtensionRequest: jest.fn(() => Promise.resolve()),
-  hasExtensionInstalled: jest.fn(),
-}))
-
-jest.mock("~/newstore/settings", () => {
-  return {
-    settingsStore: {
-      value: {
-        EXTENSIONS_ENABLED: true,
-      },
-    },
-  }
-})
-
-global.$nuxt = {
-  $loading: {
-    finish: jest.fn(() => Promise.resolve()),
-  },
-}
-
-beforeEach(() => {
-  jest.clearAllMocks() // Reset the call count for the mock functions
-})
-
-describe("cancelRunningRequest", () => {
-  test("cancels only extension request if extension allowed in settings and is installed", () => {
-    hasExtensionInstalled.mockReturnValue(true)
-
-    cancelRunningRequest()
-
-    expect(cancelRunningAxiosRequest).not.toHaveBeenCalled()
-    expect(cancelRunningExtensionRequest).toHaveBeenCalled()
-  })
-  test("cancels only axios request if extension is allowed but not installed", () => {
-    hasExtensionInstalled.mockReturnValue(false)
-
-    cancelRunningRequest()
-
-    expect(cancelRunningExtensionRequest).not.toHaveBeenCalled()
-    expect(cancelRunningAxiosRequest).toHaveBeenCalled()
-  })
-})
-
-describe("sendNetworkRequest", () => {
-  test("runs only extension request if extension allowed in settings and is installed and clears the progress bar", async () => {
-    hasExtensionInstalled.mockReturnValue(true)
-
-    await sendNetworkRequest({})
-
-    expect(AxiosStrategy).not.toHaveBeenCalled()
-    expect(ExtensionStrategy).toHaveBeenCalled()
-    expect(global.$nuxt.$loading.finish).toHaveBeenCalled()
-  })
-
-  test("runs only axios request if extension is allowed but not installed and clears the progress bar", async () => {
-    hasExtensionInstalled.mockReturnValue(false)
-
-    await sendNetworkRequest({})
-
-    expect(ExtensionStrategy).not.toHaveBeenCalled()
-    expect(AxiosStrategy).toHaveBeenCalled()
-    expect(global.$nuxt.$loading.finish).toHaveBeenCalled()
-  })
-})

+ 9 - 10
packages/hoppscotch-app/helpers/strategies/__tests__/AxiosStrategy-NoProxy.spec.js

@@ -1,6 +1,5 @@
 import axios from "axios"
 import axiosStrategy from "../AxiosStrategy"
-import { JsonFormattedError } from "~/helpers/utils/JsonFormattedError"
 
 jest.mock("axios")
 jest.mock("~/newstore/settings", () => {
@@ -20,7 +19,7 @@ axios.mockResolvedValue({})
 describe("axiosStrategy", () => {
   describe("No-Proxy Requests", () => {
     test("sends request to the actual sender if proxy disabled", async () => {
-      await axiosStrategy({ url: "test" })
+      await axiosStrategy({ url: "test" })()
 
       expect(axios).toBeCalledWith(
         expect.objectContaining({
@@ -30,7 +29,7 @@ describe("axiosStrategy", () => {
     })
 
     test("asks axios to return data as arraybuffer", async () => {
-      await axiosStrategy({ url: "test" })
+      await axiosStrategy({ url: "test" })()
 
       expect(axios).toBeCalledWith(
         expect.objectContaining({
@@ -40,24 +39,24 @@ describe("axiosStrategy", () => {
     })
 
     test("resolves successful requests", async () => {
-      await expect(axiosStrategy({})).resolves.toBeDefined()
+      expect(await axiosStrategy({})()).toBeRight()
     })
 
     test("rejects cancel errors with text 'cancellation'", async () => {
       axios.isCancel.mockReturnValueOnce(true)
       axios.mockRejectedValue("err")
 
-      await expect(axiosStrategy({})).rejects.toBe("cancellation")
+      expect(await axiosStrategy({})()).toEqualLeft("cancellation")
     })
 
     test("rejects non-cancellation errors as-is", async () => {
       axios.isCancel.mockReturnValueOnce(false)
       axios.mockRejectedValue("err")
 
-      await expect(axiosStrategy({})).rejects.toBe("err")
+      expect(await axiosStrategy({})()).toEqualLeft("err")
     })
 
-    test("non-cancellation errors that have response data are thrown", async () => {
+    test("non-cancellation errors that have response data are right", async () => {
       const errorResponse = { error: "errr" }
       axios.isCancel.mockReturnValueOnce(false)
       axios.mockRejectedValue({
@@ -68,9 +67,9 @@ describe("axiosStrategy", () => {
         },
       })
 
-      await expect(axiosStrategy({})).rejects.toMatchObject(
-        new JsonFormattedError(errorResponse)
-      )
+      expect(await axiosStrategy({})()).toSubsetEqualRight({
+        data: "eyJlcnJvciI6ImVycnIifQ==",
+      })
     })
   })
 })

+ 16 - 28
packages/hoppscotch-app/helpers/strategies/__tests__/AxiosStrategy-Proxy.spec.js

@@ -1,8 +1,5 @@
 import axios from "axios"
-import axiosStrategy, {
-  testables,
-  cancelRunningAxiosRequest,
-} from "../AxiosStrategy"
+import axiosStrategy from "../AxiosStrategy"
 
 jest.mock("../../utils/b64", () => ({
   __esModule: true,
@@ -20,15 +17,6 @@ jest.mock("~/newstore/settings", () => {
   }
 })
 
-describe("cancelRunningAxiosRequest", () => {
-  test("cancels axios request and does that only 1 time", () => {
-    const cancelFunc = jest.spyOn(testables.cancelSource, "cancel")
-
-    cancelRunningAxiosRequest()
-    expect(cancelFunc).toHaveBeenCalledTimes(1)
-  })
-})
-
 describe("axiosStrategy", () => {
   describe("Proxy Requests", () => {
     test("sends POST request to proxy if proxy is enabled", async () => {
@@ -39,7 +27,7 @@ describe("axiosStrategy", () => {
         return Promise.resolve({ data: { success: true, isBinary: false } })
       })
 
-      await axiosStrategy({})
+      await axiosStrategy({})()
 
       expect(passedURL).toEqual("test")
     })
@@ -58,7 +46,7 @@ describe("axiosStrategy", () => {
         return Promise.resolve({ data: { success: true, isBinary: false } })
       })
 
-      await axiosStrategy(reqFields)
+      await axiosStrategy(reqFields)()
 
       expect(passedFields).toMatchObject(reqFields)
     })
@@ -71,7 +59,7 @@ describe("axiosStrategy", () => {
         return Promise.resolve({ data: { success: true, isBinary: false } })
       })
 
-      await axiosStrategy({})
+      await axiosStrategy({})()
 
       expect(passedFields).toHaveProperty("wantsBinary")
     })
@@ -86,7 +74,7 @@ describe("axiosStrategy", () => {
         },
       })
 
-      await expect(axiosStrategy({})).rejects.toThrow("test message")
+      expect(await axiosStrategy({})()).toEqualLeft("test message")
     })
 
     test("checks for proxy response success field and throws error 'Proxy Error' for non-success", async () => {
@@ -97,10 +85,10 @@ describe("axiosStrategy", () => {
         },
       })
 
-      await expect(axiosStrategy({})).rejects.toThrow("Proxy Error")
+      expect(await axiosStrategy({})()).toBeLeft("Proxy Error")
     })
 
-    test("checks for proxy response success and doesn't throw for success", async () => {
+    test("checks for proxy response success and doesn't left for success", async () => {
       jest.spyOn(axios, "post").mockResolvedValue({
         data: {
           success: true,
@@ -108,10 +96,10 @@ describe("axiosStrategy", () => {
         },
       })
 
-      await expect(axiosStrategy({})).resolves.toBeDefined()
+      expect(await axiosStrategy({})()).toBeRight()
     })
 
-    test("checks isBinary response field and resolve with the converted value if so", async () => {
+    test("checks isBinary response field and right with the converted value if so", async () => {
       jest.spyOn(axios, "post").mockResolvedValue({
         data: {
           success: true,
@@ -120,12 +108,12 @@ describe("axiosStrategy", () => {
         },
       })
 
-      await expect(axiosStrategy({})).resolves.toMatchObject({
+      expect(await axiosStrategy({})()).toSubsetEqualRight({
         data: "testdata-converted",
       })
     })
 
-    test("checks isBinary response field and resolve with the actual value if not so", async () => {
+    test("checks isBinary response field and right with the actual value if not so", async () => {
       jest.spyOn(axios, "post").mockResolvedValue({
         data: {
           success: true,
@@ -134,23 +122,23 @@ describe("axiosStrategy", () => {
         },
       })
 
-      await expect(axiosStrategy({})).resolves.toMatchObject({
+      expect(await axiosStrategy({})()).toSubsetEqualRight({
         data: "testdata",
       })
     })
 
-    test("cancel errors are thrown with the string 'cancellation'", async () => {
+    test("cancel errors are returned a left with the string 'cancellation'", async () => {
       jest.spyOn(axios, "post").mockRejectedValue("errr")
       jest.spyOn(axios, "isCancel").mockReturnValueOnce(true)
 
-      await expect(axiosStrategy({})).rejects.toBe("cancellation")
+      expect(await axiosStrategy({})()).toEqualLeft("cancellation")
     })
 
-    test("non-cancellation errors are thrown", async () => {
+    test("non-cancellation errors return a left", async () => {
       jest.spyOn(axios, "post").mockRejectedValue("errr")
       jest.spyOn(axios, "isCancel").mockReturnValueOnce(false)
 
-      await expect(axiosStrategy({})).rejects.toBe("errr")
+      expect(await axiosStrategy({})()).toEqualLeft("errr")
     })
   })
 })

+ 6 - 6
packages/hoppscotch-app/helpers/strategies/__tests__/ExtensionStrategy-NoProxy.spec.js

@@ -148,7 +148,7 @@ describe("extensionStrategy", () => {
         data: '{"success":true,"data":""}',
       })
 
-      await extensionStrategy({})
+      await extensionStrategy({})()
 
       expect(sendReqFunc).toHaveBeenCalledTimes(1)
     })
@@ -168,7 +168,7 @@ describe("extensionStrategy", () => {
         })
       })
 
-      await extensionStrategy({ url: "test" })
+      await extensionStrategy({ url: "test" })()
 
       expect(passedUrl).toEqual("test")
     })
@@ -188,12 +188,12 @@ describe("extensionStrategy", () => {
         })
       })
 
-      await extensionStrategy({})
+      await extensionStrategy({})()
 
       expect(passedFields).toHaveProperty("wantsBinary")
     })
 
-    test("resolves successful requests", async () => {
+    test("rights successful requests", async () => {
       global.__POSTWOMAN_EXTENSION_HOOK__ = {
         sendRequest: sendReqFunc,
       }
@@ -202,7 +202,7 @@ describe("extensionStrategy", () => {
         data: '{"success":true,"data":""}',
       })
 
-      await expect(extensionStrategy({})).resolves.toBeDefined()
+      expect(await extensionStrategy({})()).toBeRight()
     })
 
     test("rejects errors as-is", async () => {
@@ -212,7 +212,7 @@ describe("extensionStrategy", () => {
 
       sendReqFunc.mockRejectedValue("err")
 
-      await expect(extensionStrategy({})).rejects.toBe("err")
+      expect(await extensionStrategy({})()).toEqualLeft("err")
     })
   })
 })

+ 0 - 300
packages/hoppscotch-app/helpers/strategies/__tests__/ExtensionStrategy-Proxy.spec.js

@@ -1,300 +0,0 @@
-import extensionStrategy, {
-  hasExtensionInstalled,
-  hasChromeExtensionInstalled,
-  hasFirefoxExtensionInstalled,
-  cancelRunningExtensionRequest,
-} from "../ExtensionStrategy"
-
-jest.mock("../../utils/b64", () => ({
-  __esModule: true,
-  decodeB64StringToArrayBuffer: jest.fn((data) => `${data}-converted`),
-}))
-
-jest.mock("~/newstore/settings", () => {
-  return {
-    __esModule: true,
-    settingsStore: {
-      value: {
-        EXTENSIONS_ENABLED: true,
-        PROXY_ENABLED: true,
-        PROXY_URL: "test",
-      },
-    },
-  }
-})
-
-describe("hasExtensionInstalled", () => {
-  test("returns true if extension is present and hooked", () => {
-    global.__POSTWOMAN_EXTENSION_HOOK__ = {}
-
-    expect(hasExtensionInstalled()).toEqual(true)
-  })
-
-  test("returns false if extension not present or not hooked", () => {
-    global.__POSTWOMAN_EXTENSION_HOOK__ = undefined
-
-    expect(hasExtensionInstalled()).toEqual(false)
-  })
-})
-
-describe("hasChromeExtensionInstalled", () => {
-  test("returns true if extension is hooked and browser is chrome", () => {
-    global.__POSTWOMAN_EXTENSION_HOOK__ = {}
-    jest.spyOn(navigator, "userAgent", "get").mockReturnValue("Chrome")
-    jest.spyOn(navigator, "vendor", "get").mockReturnValue("Google")
-
-    expect(hasChromeExtensionInstalled()).toEqual(true)
-  })
-
-  test("returns false if extension is hooked and browser is not chrome", () => {
-    global.__POSTWOMAN_EXTENSION_HOOK__ = {}
-    jest.spyOn(navigator, "userAgent", "get").mockReturnValue("Firefox")
-    jest.spyOn(navigator, "vendor", "get").mockReturnValue("Google")
-
-    expect(hasChromeExtensionInstalled()).toEqual(false)
-  })
-
-  test("returns false if extension not installed and browser is chrome", () => {
-    global.__POSTWOMAN_EXTENSION_HOOK__ = undefined
-    jest.spyOn(navigator, "userAgent", "get").mockReturnValue("Chrome")
-    jest.spyOn(navigator, "vendor", "get").mockReturnValue("Google")
-
-    expect(hasChromeExtensionInstalled()).toEqual(false)
-  })
-
-  test("returns false if extension not installed and browser is not chrome", () => {
-    global.__POSTWOMAN_EXTENSION_HOOK__ = undefined
-    jest.spyOn(navigator, "userAgent", "get").mockReturnValue("Firefox")
-    jest.spyOn(navigator, "vendor", "get").mockReturnValue("Google")
-
-    expect(hasChromeExtensionInstalled()).toEqual(false)
-  })
-})
-
-describe("hasFirefoxExtensionInstalled", () => {
-  test("returns true if extension is hooked and browser is firefox", () => {
-    global.__POSTWOMAN_EXTENSION_HOOK__ = {}
-    jest.spyOn(navigator, "userAgent", "get").mockReturnValue("Firefox")
-
-    expect(hasFirefoxExtensionInstalled()).toEqual(true)
-  })
-
-  test("returns false if extension is hooked and browser is not firefox", () => {
-    global.__POSTWOMAN_EXTENSION_HOOK__ = {}
-    jest.spyOn(navigator, "userAgent", "get").mockReturnValue("Chrome")
-
-    expect(hasFirefoxExtensionInstalled()).toEqual(false)
-  })
-
-  test("returns false if extension not installed and browser is firefox", () => {
-    global.__POSTWOMAN_EXTENSION_HOOK__ = undefined
-    jest.spyOn(navigator, "userAgent", "get").mockReturnValue("Firefox")
-
-    expect(hasFirefoxExtensionInstalled()).toEqual(false)
-  })
-
-  test("returns false if extension not installed and browser is not firefox", () => {
-    global.__POSTWOMAN_EXTENSION_HOOK__ = undefined
-    jest.spyOn(navigator, "userAgent", "get").mockReturnValue("Chrome")
-
-    expect(hasFirefoxExtensionInstalled()).toEqual(false)
-  })
-})
-
-describe("cancelRunningExtensionRequest", () => {
-  const cancelFunc = jest.fn()
-
-  beforeEach(() => {
-    cancelFunc.mockClear()
-  })
-
-  test("cancels request if extension installed and function present in hook", () => {
-    global.__POSTWOMAN_EXTENSION_HOOK__ = {
-      cancelRunningRequest: cancelFunc,
-    }
-
-    cancelRunningExtensionRequest()
-    expect(cancelFunc).toHaveBeenCalledTimes(1)
-  })
-
-  test("does not cancel request if extension not installed", () => {
-    global.__POSTWOMAN_EXTENSION_HOOK__ = undefined
-
-    cancelRunningExtensionRequest()
-    expect(cancelFunc).not.toHaveBeenCalled()
-  })
-
-  test("does not cancel request if extension installed but function not present", () => {
-    global.__POSTWOMAN_EXTENSION_HOOK__ = {}
-
-    cancelRunningExtensionRequest()
-    expect(cancelFunc).not.toHaveBeenCalled()
-  })
-})
-
-describe("extensionStrategy", () => {
-  const sendReqFunc = jest.fn()
-
-  beforeEach(() => {
-    sendReqFunc.mockClear()
-  })
-
-  describe("Proxy Requests", () => {
-    test("asks extension to send request", async () => {
-      global.__POSTWOMAN_EXTENSION_HOOK__ = {
-        sendRequest: sendReqFunc,
-      }
-
-      sendReqFunc.mockResolvedValue({
-        data: '{"success":true,"data":""}',
-      })
-
-      await extensionStrategy({})
-
-      expect(sendReqFunc).toHaveBeenCalledTimes(1)
-    })
-
-    test("sends POST request to proxy if proxy is enabled", async () => {
-      let passedUrl
-      let passedMethod
-
-      global.__POSTWOMAN_EXTENSION_HOOK__ = {
-        sendRequest: sendReqFunc,
-      }
-
-      sendReqFunc.mockImplementation(({ method, url }) => {
-        passedUrl = url
-        passedMethod = method
-
-        return Promise.resolve({
-          data: '{"success":true,"data":""}',
-        })
-      })
-
-      await extensionStrategy({})
-
-      expect(passedUrl).toEqual("test")
-      expect(passedMethod).toEqual("post")
-    })
-
-    test("passes request fields properly", async () => {
-      const reqFields = {
-        testA: "testA",
-        testB: "testB",
-        testC: "testC",
-      }
-
-      let passedFields
-
-      global.__POSTWOMAN_EXTENSION_HOOK__ = {
-        sendRequest: sendReqFunc,
-      }
-
-      sendReqFunc.mockImplementation(({ data }) => {
-        passedFields = data
-
-        return Promise.resolve({
-          data: '{"success":true,"data":""}',
-        })
-      })
-
-      await extensionStrategy(reqFields)
-
-      expect(passedFields).toMatchObject(reqFields)
-    })
-
-    test("passes wantsBinary field", async () => {
-      let passedFields
-
-      global.__POSTWOMAN_EXTENSION_HOOK__ = {
-        sendRequest: sendReqFunc,
-      }
-
-      sendReqFunc.mockImplementation(({ data }) => {
-        passedFields = data
-
-        return Promise.resolve({
-          data: '{"success":true,"data":""}',
-        })
-      })
-
-      await extensionStrategy({})
-
-      expect(passedFields).toHaveProperty("wantsBinary")
-    })
-
-    test("checks for proxy response success field and throws error message for non-success", async () => {
-      global.__POSTWOMAN_EXTENSION_HOOK__ = {
-        sendRequest: sendReqFunc,
-      }
-
-      sendReqFunc.mockResolvedValue({
-        data: '{"success":false,"data": { "message": "testerr" } }',
-      })
-
-      await expect(extensionStrategy({})).rejects.toThrow("testerr")
-    })
-
-    test("checks for proxy response success field and throws error 'Proxy Error' for non-success", async () => {
-      global.__POSTWOMAN_EXTENSION_HOOK__ = {
-        sendRequest: sendReqFunc,
-      }
-
-      sendReqFunc.mockResolvedValue({
-        data: '{"success":false,"data": {} }',
-      })
-
-      await expect(extensionStrategy({})).rejects.toThrow("Proxy Error")
-    })
-
-    test("checks for proxy response success and doesn't throw for success", async () => {
-      global.__POSTWOMAN_EXTENSION_HOOK__ = {
-        sendRequest: sendReqFunc,
-      }
-
-      sendReqFunc.mockResolvedValue({
-        data: '{"success":true,"data": {} }',
-      })
-
-      await expect(extensionStrategy({})).resolves.toBeDefined()
-    })
-
-    test("checks isBinary response field and resolve with the converted value if so", async () => {
-      global.__POSTWOMAN_EXTENSION_HOOK__ = {
-        sendRequest: sendReqFunc,
-      }
-
-      sendReqFunc.mockResolvedValue({
-        data: '{"success": true, "isBinary": true, "data": "testdata" }',
-      })
-
-      await expect(extensionStrategy({})).resolves.toMatchObject({
-        data: "testdata-converted",
-      })
-    })
-
-    test("checks isBinary response field and resolve with the actual value if not so", async () => {
-      global.__POSTWOMAN_EXTENSION_HOOK__ = {
-        sendRequest: sendReqFunc,
-      }
-
-      sendReqFunc.mockResolvedValue({
-        data: '{"success": true, "isBinary": false, "data": "testdata" }',
-      })
-
-      await expect(extensionStrategy({})).resolves.toMatchObject({
-        data: "testdata",
-      })
-    })
-
-    test("failed request errors are thrown as-is", async () => {
-      global.__POSTWOMAN_EXTENSION_HOOK__ = {
-        sendRequest: sendReqFunc,
-      }
-
-      sendReqFunc.mockRejectedValue("err")
-
-      await expect(extensionStrategy({})).rejects.toBe("err")
-    })
-  })
-})

+ 1 - 0
packages/hoppscotch-app/jest.setup.js

@@ -1 +1,2 @@
 import "@testing-library/jest-dom"
+import "@relmify/jest-fp-ts"

+ 1 - 0
packages/hoppscotch-app/package.json

@@ -125,6 +125,7 @@
     "@nuxtjs/pwa": "^3.3.5",
     "@nuxtjs/stylelint-module": "^4.1.0",
     "@nuxtjs/svg": "^0.3.0",
+    "@relmify/jest-fp-ts": "^1.1.1",
     "@testing-library/jest-dom": "^5.16.0",
     "@types/codemirror": "^5.60.5",
     "@types/cookie": "^0.4.1",

+ 3 - 17
pnpm-lock.yaml

@@ -91,6 +91,7 @@ importers:
       '@nuxtjs/stylelint-module': ^4.1.0
       '@nuxtjs/svg': ^0.3.0
       '@nuxtjs/toast': ^3.3.1
+      '@relmify/jest-fp-ts': ^1.1.1
       '@testing-library/jest-dom': ^5.16.0
       '@types/codemirror': ^5.60.5
       '@types/cookie': ^0.4.1
@@ -255,6 +256,7 @@ importers:
       '@nuxtjs/pwa': 3.3.5
       '@nuxtjs/stylelint-module': [email protected]
       '@nuxtjs/svg': 0.3.0
+      '@relmify/jest-fp-ts': [email protected][email protected]
       '@testing-library/jest-dom': 5.16.1
       '@types/codemirror': 5.60.5
       '@types/cookie': 0.4.1
@@ -371,13 +373,6 @@ packages:
       zen-observable-ts: 1.2.3
     dev: false
 
-  /@babel/code-frame/7.15.8:
-    resolution: {integrity: sha512-2IAnmn8zbvC/jKYhq5Ki9I+DwjlrtMPUCH/CpHvqI4dNnlwHwsxoIhlc8WcYY5LSYknXQtAlFYuHfqAFCvQ4Wg==}
-    engines: {node: '>=6.9.0'}
-    dependencies:
-      '@babel/highlight': 7.14.5
-    dev: true
-
   /@babel/code-frame/7.16.0:
     resolution: {integrity: sha512-IF4EOMEV+bfYwOmNxGzSnjR2EmQod7f1UXOpZM3l4i4o4QNwzjtJAu/HxdjHq0aYBvdqMuQEY1eg0nqW9ZPORA==}
     engines: {node: '>=6.9.0'}
@@ -667,15 +662,6 @@ packages:
     transitivePeerDependencies:
       - supports-color
 
-  /@babel/highlight/7.14.5:
-    resolution: {integrity: sha512-qf9u2WFWVV0MppaL877j2dBtQIDgmidgjGk5VIMw3OadXvYaXn66U1BFlH2t4+t3i+8PhedppRv+i40ABzd+gg==}
-    engines: {node: '>=6.9.0'}
-    dependencies:
-      '@babel/helper-validator-identifier': 7.15.7
-      chalk: 2.4.2
-      js-tokens: 4.0.0
-    dev: true
-
   /@babel/highlight/7.16.0:
     resolution: {integrity: sha512-t8MH41kUQylBtu2+4IQA3atqevA2lRgqA2wyVB/YiWmsDSuylZZuXOUy9ric30hfzauEFfdsuk/eXTRrGrfd0g==}
     engines: {node: '>=6.9.0'}
@@ -11001,7 +10987,7 @@ packages:
     resolution: {integrity: sha512-rGiLePzQ3AzwUshu2+Rn+UMFk0pHN58sOG+IaJbk5Jxuqo3NYO1U2/MIR4S1sKgsoYSXSzdtSa0TgrmtUwEbmA==}
     engines: {node: '>= 10.14.2'}
     dependencies:
-      '@babel/code-frame': 7.15.8
+      '@babel/code-frame': 7.16.0
       '@jest/types': 26.6.2
       '@types/stack-utils': 2.0.1
       chalk: 4.1.2