Skip to content

Commit

Permalink
(fix, TypeScript): remove flaky fetcher test (#4226)
Browse files Browse the repository at this point in the history
  • Loading branch information
RohinBhargava authored and amckinney committed Aug 8, 2024
1 parent fb5e1cf commit e899d7c
Show file tree
Hide file tree
Showing 183 changed files with 1,332 additions and 2,060 deletions.
390 changes: 390 additions & 0 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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.38.5] - 2024-08-07

- Fix: Addressed fetcher unit test flakiness by using a mock fetcher

## [0.38.4] - 2024-08-04

- Fix: Literal templates are generated if they are union members
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.38.4
0.38.5
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export class FetcherImpl extends CoreUtility implements Fetcher {
dependencyManager.addDependency("@types/node-fetch", "2.6.9", {
type: DependencyType.DEV
});
dependencyManager.addDependency("fetch-mock-jest", "^1.5.1", {
type: DependencyType.DEV
});
}
};
public readonly Fetcher: Fetcher["Fetcher"] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"depcheck": "^1.4.6",
"eslint": "^8.56.0",
"express": "^4.19.2",
"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,28 +1,7 @@
import fetchMock from "fetch-mock-jest";
import { Fetcher, fetcherImpl } from "../Fetcher";

describe("Test fetcherImpl", () => {
let mockCreateUrl: jest.Mock;
let mockGetBody: jest.Mock;
let mockGetFetchFn: jest.Mock;
let mockRequestWithRetries: jest.Mock;
let mockGetResponseBody: jest.Mock;

beforeEach(() => {
mockCreateUrl = jest.fn();
mockGetBody = jest.fn();
mockGetFetchFn = jest.fn();
mockRequestWithRetries = jest.fn();
mockGetResponseBody = jest.fn();

jest.mock("../Fetcher", () => ({
createUrl: mockCreateUrl,
getBody: mockGetBody,
getFetchFn: mockGetFetchFn,
requestWithRetries: mockRequestWithRetries,
getResponseBody: mockGetResponseBody
}));
});

it("should handle successful request", async () => {
const mockArgs: Fetcher.Args = {
url: "https://httpbin.org/post",
Expand All @@ -33,15 +12,14 @@ describe("Test fetcherImpl", () => {
requestType: "json"
};

mockCreateUrl.mockReturnValue("https://test.com");
mockGetBody.mockResolvedValue(JSON.stringify({ data: "test" }));
mockGetFetchFn.mockResolvedValue(() => Promise.resolve());
mockRequestWithRetries.mockResolvedValue({ status: 200 });
mockGetResponseBody.mockResolvedValue({ result: "success" });
fetchMock.mock("https://httpbin.org/post", 200, {
response: JSON.stringify({ data: "test" })
});

const result = await fetcherImpl(mockArgs);
expect(result.ok).toBe(true);
// @ts-expect-error
expect(result.body.json).toEqual({ data: "test" });
if (result.ok) {
expect(result.body).toEqual({ data: "test" });
}
});
});
1 change: 1 addition & 0 deletions seed/ts-sdk/alias-extends/package.json

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

36 changes: 7 additions & 29 deletions seed/ts-sdk/alias-extends/tests/unit/fetcher/Fetcher.test.ts

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

1 change: 1 addition & 0 deletions seed/ts-sdk/alias/package.json

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

36 changes: 7 additions & 29 deletions seed/ts-sdk/alias/tests/unit/fetcher/Fetcher.test.ts

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

1 change: 1 addition & 0 deletions seed/ts-sdk/api-wide-base-path/package.json

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

36 changes: 7 additions & 29 deletions seed/ts-sdk/api-wide-base-path/tests/unit/fetcher/Fetcher.test.ts

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

1 change: 1 addition & 0 deletions seed/ts-sdk/audiences/package.json

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

36 changes: 7 additions & 29 deletions seed/ts-sdk/audiences/tests/unit/fetcher/Fetcher.test.ts

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

1 change: 1 addition & 0 deletions seed/ts-sdk/auth-environment-variables/package.json

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

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

1 change: 1 addition & 0 deletions seed/ts-sdk/basic-auth-environment-variables/package.json

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

Loading

0 comments on commit e899d7c

Please sign in to comment.