File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { createServer } from 'node:http'
22import { test , after } from 'node:test'
3- import {
3+ import undici , {
44 Agent ,
55 Client ,
66 errors ,
@@ -99,3 +99,29 @@ test('named exports', (t) => {
9999 t . assert . strictEqual ( typeof setGlobalDispatcher , 'function' )
100100 t . assert . strictEqual ( typeof getGlobalDispatcher , 'function' )
101101} )
102+
103+ test ( 'default import top-level request works with opts.dispatcher' , async ( t ) => {
104+ t . plan ( 4 )
105+
106+ const server = createServer ( { joinDuplicateHeaders : true } , ( req , res ) => {
107+ t . assert . strictEqual ( req . method , 'GET' )
108+ t . assert . strictEqual ( req . url , '/' )
109+ res . end ( 'ok' )
110+ } )
111+
112+ await new Promise ( ( resolve ) => server . listen ( 0 , resolve ) )
113+
114+ const dispatcher = new undici . Agent ( { allowH2 : true } )
115+
116+ t . after ( async ( ) => {
117+ await dispatcher . close ( )
118+ await new Promise ( ( resolve ) => server . close ( resolve ) )
119+ } )
120+
121+ const { statusCode, body } = await undici . request ( `http://127.0.0.1:${ server . address ( ) . port } ` , {
122+ dispatcher
123+ } )
124+
125+ t . assert . strictEqual ( statusCode , 200 )
126+ t . assert . strictEqual ( await body . text ( ) , 'ok' )
127+ } )
You can’t perform that action at this time.
0 commit comments