Skip to content

Commit 09a34e5

Browse files
committed
fix node http tests
1 parent ffed577 commit 09a34e5

File tree

1 file changed

+5
-22
lines changed

1 file changed

+5
-22
lines changed

packages/node-http-handler/src/node-http-handler.mock-server.spec.ts

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,7 @@ vi.mock("http", async () => {
2020
const actual = (await vi.importActual("http")) as any;
2121
const pkg = {
2222
...actual,
23-
request: vi.fn().mockImplementation((_options, cb) => {
24-
cb({
25-
statusCode: 200,
26-
body: "body",
27-
headers: {},
28-
protocol: "http:",
29-
});
30-
return new actual.ClientRequest({ ..._options, protocol: "http:" });
31-
}),
23+
request: vi.fn().mockImplementation(actual.request),
3224
};
3325
return {
3426
...pkg,
@@ -38,18 +30,9 @@ vi.mock("http", async () => {
3830

3931
vi.mock("https", async () => {
4032
const actual = (await vi.importActual("https")) as any;
41-
const http = (await vi.importActual("http")) as any;
4233
const pkg = {
4334
...actual,
44-
request: vi.fn().mockImplementation((_options, cb) => {
45-
cb({
46-
statusCode: 200,
47-
body: "body",
48-
headers: {},
49-
protocol: "https:",
50-
});
51-
return new http.ClientRequest({ ..._options, protocol: "https:" });
52-
}),
35+
request: vi.fn().mockImplementation(actual.request),
5336
};
5437
return {
5538
...pkg,
@@ -144,7 +127,7 @@ describe("http", () => {
144127
});
145128
});
146129

147-
it.only("can handle expect 100-continue", async () => {
130+
it("can handle expect 100-continue", async () => {
148131
const body = Buffer.from("test");
149132
const mockResponse = {
150133
statusCode: 200,
@@ -302,7 +285,7 @@ describe("https", () => {
302285
body: "test",
303286
};
304287
mockHttpsServer.addListener("request", createResponseFunction(mockResponse));
305-
const spy = vi.spyOn(https, "request").mockImplementationOnce(() => {
288+
const spy = vi.mocked(hsRequest).mockImplementationOnce(() => {
306289
const calls = spy.mock.calls;
307290
const currentIndex = calls.length - 1;
308291
return https.request(calls[currentIndex][0], calls[currentIndex][1]);
@@ -360,7 +343,7 @@ describe("https", () => {
360343
mockHttpsServer.addListener("request", createResponseFunction(mockResponse));
361344
let httpRequest: http.ClientRequest;
362345
let reqDestroySpy: any;
363-
const spy = vi.spyOn(https, "request").mockImplementationOnce(() => {
346+
const spy = vi.mocked(hsRequest).mockImplementationOnce(() => {
364347
const calls = spy.mock.calls;
365348
const currentIndex = calls.length - 1;
366349
httpRequest = https.request(calls[currentIndex][0], calls[currentIndex][1]);

0 commit comments

Comments
 (0)