-
-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add benchmarks for openapi-fetch (#1299)
- Loading branch information
Showing
11 changed files
with
467 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test/openapi-typescript-codegen.min.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import axios from "axios"; | ||
import { Fetcher } from "openapi-typescript-fetch"; | ||
import superagent from "superagent"; | ||
import { afterAll, bench, describe, vi } from "vitest"; | ||
import createFetchMock from "vitest-fetch-mock"; | ||
import * as openapiTSCodegen from "./openapi-typescript-codegen.min.js"; | ||
import createClient from "../dist/index.js"; | ||
|
||
const BASE_URL = "https://api.test.local"; | ||
|
||
const fetchMocker = createFetchMock(vi); | ||
|
||
fetchMocker.enableMocks(); | ||
fetchMocker.mockResponse("{}"); | ||
afterAll(() => { | ||
fetchMocker.resetMocks(); | ||
}); | ||
|
||
describe("setup", () => { | ||
bench("openapi-fetch", async () => { | ||
createClient(); | ||
}); | ||
|
||
bench("openapi-typescript-fetch", async () => { | ||
const fetcher = Fetcher.for(); | ||
fetcher.path("/pet/findByStatus").method("get").create(); | ||
}); | ||
|
||
// axios: N/A | ||
|
||
// superagent: N/A | ||
}); | ||
|
||
describe("get (only URL)", () => { | ||
let openapiFetch = createClient({ baseUrl: BASE_URL }); | ||
let openapiTSFetch = Fetcher.for(); | ||
openapiTSFetch.configure({ | ||
init: { baseUrl: BASE_URL }, | ||
}); | ||
|
||
bench("openapi-fetch", async () => { | ||
await openapiFetch.GET("/url"); | ||
}); | ||
|
||
bench("openapi-typescript-fetch", async () => { | ||
await openapiTSFetch.path("/url").method("get").create()(); | ||
}); | ||
|
||
bench("openapi-typescript-codegen", async () => { | ||
await openapiTSCodegen.PullsService.pullsGet(); | ||
}); | ||
|
||
bench("axios", async () => { | ||
await axios.get("/url", { | ||
async adapter() { | ||
return "{}"; | ||
}, | ||
}); | ||
}); | ||
|
||
bench("superagent", async () => { | ||
await superagent.get("/url").end(); | ||
}); | ||
}); | ||
|
||
describe("get (headers)", () => { | ||
let openapiFetch = createClient({ baseUrl: BASE_URL, headers: { "x-base-header": 123 } }); | ||
let openapiTSFetch = Fetcher.for(); | ||
openapiTSFetch.configure({ | ||
init: { baseUrl: BASE_URL, headers: { "x-base-header": 123 } }, | ||
}); | ||
|
||
bench("openapi-fetch", async () => { | ||
await openapiFetch.GET("/url", { headers: { "x-header-1": 123, "x-header-2": 456 } }); | ||
}); | ||
|
||
bench("openapi-typescript-fetch", async () => { | ||
await openapiTSFetch.path("/url").method("get").create()(null, { headers: { "x-header-1": 123, "x-header-2": 456 } }); | ||
}); | ||
|
||
bench("openapi-typescript-codegen", async () => { | ||
await openapiTSCodegen.PullsService.pullsGet(); | ||
}); | ||
|
||
bench("axios", async () => { | ||
await axios.get(`${BASE_URL}/url`, { | ||
headers: { "x-header-1": 123, "x-header-2": 456 }, | ||
async adapter() { | ||
return "{}"; | ||
}, | ||
}); | ||
}); | ||
|
||
bench("superagent", async () => { | ||
await superagent.get(`${BASE_URL}/url`).set("x-header-1", 123).set("x-header-2", 456).end(); | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
packages/openapi-fetch/test/openapi-typescript-codegen.min.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.