Skip to content

chore(openapi-fetch): Improve benchmarks #1897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/openapi-fetch/biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"extends": ["../../biome.json"],
"files": {
"include": ["./src/", "./test/"],
"ignore": ["**/test/**/schemas/**"]
"ignore": ["./test/**/schemas/**", "./test/bench/*.min.js"]
},
"linter": {
"rules": {
Expand Down
3 changes: 1 addition & 2 deletions packages/openapi-fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
"version": "pnpm run prepare && pnpm run build"
},
"dependencies": {
"openapi-typescript-helpers": "workspace:^",
"vitest-fetch-mock": "^0.3.0"
"openapi-typescript-helpers": "workspace:^"
},
"devDependencies": {
"axios": "^1.7.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@ import axios from "axios";
import { Fetcher } from "openapi-typescript-fetch";
import { createApiFetchClient } from "feature-fetch";
import superagent from "superagent";
import { afterAll, beforeAll, bench, describe, vi } from "vitest";
import createFetchMock from "vitest-fetch-mock";
import createClient, { createPathBasedClient } from "../dist/index.js";
import * as openapiTSCodegen from "./fixtures/openapi-typescript-codegen.min.js";
import { afterAll, bench, describe, vi } from "vitest";
import createClient, { createPathBasedClient } from "../../dist/index.js";
import * as openapiTSCodegen from "./openapi-typescript-codegen.min.js";

const BASE_URL = "https://api.test.local";

const fetchMocker = createFetchMock(vi);
const fetchMock = vi.fn(
() =>
new Promise((resolve) => {
process.nextTick(() => {
resolve(Response.json({}, { status: 200 }));
});
}),
);
vi.stubGlobal("fetch", fetchMock);

afterAll(() => {
vi.unstubAllGlobals();
});

describe("setup", () => {
beforeAll(() => {
// mock global fetch in this benchmark, without any delaly, shared state or resources
fetchMocker.enableMocks();
});

afterAll(() => {
fetchMocker.disableMocks();
});

bench("openapi-fetch", async () => {
createClient({ baseUrl: BASE_URL });
});
Expand Down
Loading