Skip to content

Commit

Permalink
fix(typescript): remove jest-fetch-mock dependency (#5077)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Nov 2, 2024
1 parent 5333551 commit fd99795
Show file tree
Hide file tree
Showing 421 changed files with 2,203 additions and 2,191 deletions.
4 changes: 4 additions & 0 deletions generators/typescript/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.41.1] - 2024-11-02

- Fix: Remove dev dependency on `jest-fetch-mock`.

## [0.41.0] - 2024-10-08

- Improvement: Add a variable jitter to the exponential backoff and retry.
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/sdk/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.41.0
0.41.1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"dependencies": {
"form-data-encoder": "^4.0.2",
"formdata-node": "^6.0.3",
"jest-fetch-mock": "^3.0.3",
"node-fetch": "2.7.0",
"qs": "6.12.1",
"readable-stream": "^4.5.2"
Expand All @@ -44,7 +43,6 @@
"depcheck": "^1.4.6",
"eslint": "^8.56.0",
"express": "^4.20.0",
"fetch-mock-jest": "^1.5.1",
"form-data": "4.0.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetchMock from "fetch-mock-jest";
import fs from "fs";
import { Fetcher, fetcherImpl } from "../Fetcher";
import { join } from "path";
Expand All @@ -14,15 +13,27 @@ describe("Test fetcherImpl", () => {
requestType: "json"
};

fetchMock.mock("https://httpbin.org/post", 200, {
response: JSON.stringify({ data: "test" })
global.fetch = jest.fn().mockResolvedValue({
ok: true,
status: 200,
text: () => Promise.resolve(JSON.stringify({ data: "test" })),
json: () => ({ data: "test" })
});

const result = await fetcherImpl(mockArgs);
expect(result.ok).toBe(true);
if (result.ok) {
expect(result.body).toEqual({ data: "test" });
}

expect(global.fetch).toHaveBeenCalledWith(
"https://httpbin.org/post",
expect.objectContaining({
method: "POST",
headers: expect.objectContaining({ "X-Test": "x-test-header" }),
body: JSON.stringify({ data: "test" })
})
);
});

it("should send octet stream", async () => {
Expand All @@ -37,16 +48,23 @@ describe("Test fetcherImpl", () => {
body: fs.createReadStream(join(__dirname, "test-file.txt"))
};

fetchMock.mock("https://httpbin.org/post/file", 200, {
response: JSON.stringify({ data: "test" })
global.fetch = jest.fn().mockResolvedValue({
ok: true,
status: 200,
text: () => Promise.resolve(JSON.stringify({ data: "test" })),
json: () => Promise.resolve({ data: "test" })
});

const result = await fetcherImpl(mockArgs);

expect(fetchMock).toHaveFetched(url, {
method: "POST",
body: fs.createReadStream(join(__dirname, "test-file.txt")).read()
});
expect(global.fetch).toHaveBeenCalledWith(
url,
expect.objectContaining({
method: "POST",
headers: expect.objectContaining({ "X-Test": "x-test-header" }),
body: expect.any(fs.ReadStream)
})
);
expect(result.ok).toBe(true);
if (result.ok) {
expect(result.body).toEqual({ data: "test" });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { RUNTIME } from "../../runtime";
import { getRequestBody } from "../getRequestBody";

if (RUNTIME.type === "browser") {
require("jest-fetch-mock").enableMocks();
}

describe("Test getRequestBody", () => {
it("should return FormData as is in Node environment", async () => {
if (RUNTIME.type === "node") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { RUNTIME } from "../../runtime";
import { getResponseBody } from "../getResponseBody";
import { chooseStreamWrapper } from "../stream-wrappers/chooseStreamWrapper";

if (RUNTIME.type === "browser") {
require("jest-fetch-mock").enableMocks();
}

describe("Test getResponseBody", () => {
it("should handle blob response type", async () => {
const mockBlob = new Blob(["test"], { type: "text/plain" });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { RUNTIME } from "../../runtime";
import { makeRequest } from "../makeRequest";

if (RUNTIME.type === "browser") {
require("jest-fetch-mock").enableMocks();
}

describe("Test makeRequest", () => {
const mockPostUrl = "https://httpbin.org/post";
const mockGetUrl = "https://httpbin.org/get";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { RUNTIME } from "../../runtime";
import { requestWithRetries } from "../requestWithRetries";

if (RUNTIME.type === "browser") {
require("jest-fetch-mock").enableMocks();
}

describe("requestWithRetries", () => {
let mockFetch: jest.Mock;
let originalMathRandom: typeof Math.random;
Expand Down
104 changes: 0 additions & 104 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fd99795

Please sign in to comment.