@@ -4,6 +4,7 @@ import https from "https";
4
4
import { afterEach , beforeEach , describe , expect , test as it , vi } from "vitest" ;
5
5
6
6
import { NodeHttpHandler } from "./node-http-handler" ;
7
+ import * as setConnectionTimeoutModule from "./set-connection-timeout" ;
7
8
import { timing } from "./timing" ;
8
9
9
10
vi . mock ( "http" , async ( ) => {
@@ -54,6 +55,7 @@ describe("NodeHttpHandler", () => {
54
55
describe ( "constructor and #handle" , ( ) => {
55
56
const randomMaxSocket = Math . round ( Math . random ( ) * 50 ) + 1 ;
56
57
const randomSocketAcquisitionWarningTimeout = Math . round ( Math . random ( ) * 10000 ) + 1 ;
58
+ const randomConnectionTimeout = Math . round ( Math . random ( ) * 10000 ) + 1 ;
57
59
58
60
beforeEach ( ( ) => { } ) ;
59
61
@@ -110,6 +112,23 @@ describe("NodeHttpHandler", () => {
110
112
expect ( vi . mocked ( timing . setTimeout ) . mock . calls [ 0 ] [ 1 ] ) . toBe ( randomSocketAcquisitionWarningTimeout ) ;
111
113
} ) ;
112
114
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
+
113
132
it . each ( [
114
133
[ "an options hash" , { httpAgent : new http . Agent ( { keepAlive : false , maxSockets : randomMaxSocket } ) } ] ,
115
134
[
0 commit comments