@@ -4,6 +4,7 @@ import https from "https";
44import { afterEach , beforeEach , describe , expect , test as it , vi } from "vitest" ;
55
66import { NodeHttpHandler } from "./node-http-handler" ;
7+ import * as setConnectionTimeoutModule from "./set-connection-timeout" ;
78import { timing } from "./timing" ;
89
910vi . mock ( "http" , async ( ) => {
@@ -54,6 +55,7 @@ describe("NodeHttpHandler", () => {
5455 describe ( "constructor and #handle" , ( ) => {
5556 const randomMaxSocket = Math . round ( Math . random ( ) * 50 ) + 1 ;
5657 const randomSocketAcquisitionWarningTimeout = Math . round ( Math . random ( ) * 10000 ) + 1 ;
58+ const randomConnectionTimeout = Math . round ( Math . random ( ) * 10000 ) + 1 ;
5759
5860 beforeEach ( ( ) => { } ) ;
5961
@@ -110,6 +112,23 @@ describe("NodeHttpHandler", () => {
110112 expect ( vi . mocked ( timing . setTimeout ) . mock . calls [ 0 ] [ 1 ] ) . toBe ( randomSocketAcquisitionWarningTimeout ) ;
111113 } ) ;
112114
115+ it . each ( [
116+ [ "an options hash" , { connectionTimeout : randomConnectionTimeout } ] ,
117+ [
118+ "a provider" ,
119+ async ( ) => ( {
120+ connectionTimeout : randomConnectionTimeout ,
121+ } ) ,
122+ ] ,
123+ ] ) ( "sets connectionTimeout correctly when input is %s" , async ( _ , option ) => {
124+ vi . spyOn ( setConnectionTimeoutModule , "setConnectionTimeout" ) ;
125+ const nodeHttpHandler = new NodeHttpHandler ( option ) ;
126+ await nodeHttpHandler . handle ( { } as any ) ;
127+ expect ( vi . mocked ( setConnectionTimeoutModule . setConnectionTimeout ) . mock . calls [ 0 ] [ 2 ] ) . toBe (
128+ randomConnectionTimeout
129+ ) ;
130+ } ) ;
131+
113132 it . each ( [
114133 [ "an options hash" , { httpAgent : new http . Agent ( { keepAlive : false , maxSockets : randomMaxSocket } ) } ] ,
115134 [
0 commit comments