Skip to content

Commit 85d8368

Browse files
authored
chore(test): cover issue 5014 (#5015)
1 parent 4e4c2a3 commit 85d8368

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

test/utils/esm-wrapper.mjs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createServer } from 'node:http'
22
import { 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+
})

0 commit comments

Comments
 (0)