Skip to content

Commit f570294

Browse files
committed
Add benchmarks
1 parent f13f95d commit f570294

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

packages/openapi-fetch/test/index.bench.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import axios from "axios";
22
import { http, HttpResponse } from "msw";
33
import { setupServer } from "msw/node";
44
import { Fetcher } from "openapi-typescript-fetch";
5-
import { nanoid } from "nanoid";
65
import superagent from "superagent";
76
import { afterAll, bench, describe } from "vitest";
8-
import createClient from "../dist/index.js";
7+
import createClient, { createPathBasedClient } from "../dist/index.js";
98
import * as openapiTSCodegen from "./fixtures/openapi-typescript-codegen.min.js";
109

1110
const BASE_URL = "https://api.test.local";
@@ -41,6 +40,10 @@ describe("setup", () => {
4140
createClient({ baseUrl: BASE_URL });
4241
});
4342

43+
bench("openapi-fetch (path based)", async () => {
44+
createPathBasedClient({ baseUrl: BASE_URL });
45+
});
46+
4447
bench("openapi-typescript-fetch", async () => {
4548
const fetcher = Fetcher.for();
4649
fetcher.configure({
@@ -60,6 +63,7 @@ describe("setup", () => {
6063

6164
describe("get (only URL)", () => {
6265
const openapiFetch = createClient({ baseUrl: BASE_URL });
66+
const openapiFetchPath = createPathBasedClient({ baseUrl: BASE_URL });
6367
const openapiTSFetch = Fetcher.for();
6468
openapiTSFetch.configure({
6569
baseUrl: BASE_URL,
@@ -74,6 +78,10 @@ describe("get (only URL)", () => {
7478
await openapiFetch.GET("/url");
7579
});
7680

81+
bench("openapi-fetch (path based)", async () => {
82+
await openapiFetchPath["/url"].GET();
83+
});
84+
7785
bench("openapi-typescript-fetch", async () => {
7886
await openapiTSFetchGET();
7987
});
@@ -96,6 +104,10 @@ describe("get (headers)", () => {
96104
baseUrl: BASE_URL,
97105
headers: { "x-base-header": 123 },
98106
});
107+
const openapiFetchPath = createPathBasedClient({
108+
baseUrl: BASE_URL,
109+
headers: { "x-base-header": 123 },
110+
});
99111
const openapiTSFetch = Fetcher.for();
100112
openapiTSFetch.configure({
101113
baseUrl: BASE_URL,
@@ -113,6 +125,12 @@ describe("get (headers)", () => {
113125
});
114126
});
115127

128+
bench("openapi-fetch (path based)", async () => {
129+
await openapiFetchPath["/url"].GET({
130+
headers: { "x-header-1": 123, "x-header-2": 456 },
131+
});
132+
});
133+
116134
bench("openapi-typescript-fetch", async () => {
117135
await openapiTSFetchGET(null, {
118136
headers: { "x-header-1": 123, "x-header-2": 456 },

0 commit comments

Comments
 (0)