@@ -20,15 +20,7 @@ vi.mock("http", async () => {
20
20
const actual = ( await vi . importActual ( "http" ) ) as any ;
21
21
const pkg = {
22
22
...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 ) ,
32
24
} ;
33
25
return {
34
26
...pkg ,
@@ -38,18 +30,9 @@ vi.mock("http", async () => {
38
30
39
31
vi . mock ( "https" , async ( ) => {
40
32
const actual = ( await vi . importActual ( "https" ) ) as any ;
41
- const http = ( await vi . importActual ( "http" ) ) as any ;
42
33
const pkg = {
43
34
...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 ) ,
53
36
} ;
54
37
return {
55
38
...pkg ,
@@ -144,7 +127,7 @@ describe("http", () => {
144
127
} ) ;
145
128
} ) ;
146
129
147
- it . only ( "can handle expect 100-continue" , async ( ) => {
130
+ it ( "can handle expect 100-continue" , async ( ) => {
148
131
const body = Buffer . from ( "test" ) ;
149
132
const mockResponse = {
150
133
statusCode : 200 ,
@@ -302,7 +285,7 @@ describe("https", () => {
302
285
body : "test" ,
303
286
} ;
304
287
mockHttpsServer . addListener ( "request" , createResponseFunction ( mockResponse ) ) ;
305
- const spy = vi . spyOn ( https , "request" ) . mockImplementationOnce ( ( ) => {
288
+ const spy = vi . mocked ( hsRequest ) . mockImplementationOnce ( ( ) => {
306
289
const calls = spy . mock . calls ;
307
290
const currentIndex = calls . length - 1 ;
308
291
return https . request ( calls [ currentIndex ] [ 0 ] , calls [ currentIndex ] [ 1 ] ) ;
@@ -360,7 +343,7 @@ describe("https", () => {
360
343
mockHttpsServer . addListener ( "request" , createResponseFunction ( mockResponse ) ) ;
361
344
let httpRequest : http . ClientRequest ;
362
345
let reqDestroySpy : any ;
363
- const spy = vi . spyOn ( https , "request" ) . mockImplementationOnce ( ( ) => {
346
+ const spy = vi . mocked ( hsRequest ) . mockImplementationOnce ( ( ) => {
364
347
const calls = spy . mock . calls ;
365
348
const currentIndex = calls . length - 1 ;
366
349
httpRequest = https . request ( calls [ currentIndex ] [ 0 ] , calls [ currentIndex ] [ 1 ] ) ;
0 commit comments