Skip to content

Commit c9984e6

Browse files
committed
Add client option to pass custom RequestInit object into fetch requests for supported implementations - refactor test to use own server/endpoint
1 parent 41e1d81 commit c9984e6

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

packages/openapi-fetch/test/common/create-client-e2e.test.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,30 @@ import * as https from "node:https";
44
import { Agent } from "undici";
55
import createClient from "../../src/index.js";
66
import * as forge from "node-forge";
7-
import * as crypto from "crypto";
8-
import httpServer from "express/lib/application.js";
7+
import * as crypto from "node:crypto";
98

109
const pki = forge.pki;
1110

12-
const genCACert = async (options = {}) => {
13-
options = {
11+
const genCACert = async (opts = {}) => {
12+
const options = {
1413
...{
1514
commonName: "Testing CA - DO NOT TRUST",
1615
bits: 2048,
1716
},
18-
...options,
17+
...opts,
1918
};
2019

21-
let keyPair = await new Promise((res, rej) => {
20+
const keyPair = await new Promise((res, rej) => {
2221
pki.rsa.generateKeyPair({ bits: options.bits }, (error, pair) => {
23-
if (error) rej(error);
24-
else res(pair);
22+
if (error) {
23+
rej(error);
24+
} else {
25+
res(pair);
26+
}
2527
});
2628
});
2729

28-
let cert = pki.createCertificate();
30+
const cert = pki.createCertificate();
2931
cert.publicKey = keyPair.publicKey;
3032
cert.serialNumber = crypto.randomUUID().replace(/-/g, "");
3133

@@ -70,9 +72,9 @@ app.get("/v1/foo", (req, res) => {
7072
});
7173

7274
test("requestInitExt", async () => {
73-
let cert = await genCACert();
74-
let buffers = caToBuffer(cert.ca);
75-
let options = {};
75+
const cert = await genCACert();
76+
const buffers = caToBuffer(cert.ca);
77+
const options = {};
7678
options.key = buffers.key;
7779
options.cert = buffers.cert;
7880
const httpsServer = https.createServer(options, app);

packages/openapi-fetch/test/common/create-client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, test } from "vitest";
22
import { createObservedClient } from "../helpers.js";
3-
import { type FetchOptions, type HeadersOptions } from "../../src/index.js";
3+
import type { FetchOptions, HeadersOptions } from "../../src/index.js";
44
import type { paths } from "./schemas/common.js";
55

66
describe("createClient options", () => {

0 commit comments

Comments
 (0)