Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: port client-connect, client-dispatch, client-errors test to node:test #2591

Merged
merged 11 commits into from
Jan 16, 2024
Prev Previous commit
Next Next commit
Use done instead of t.end
  • Loading branch information
sosukesuzuki committed Jan 11, 2024
commit c643b85684bce8f7253a638de78bfc2126d384b3
8 changes: 5 additions & 3 deletions test/node-test/client-dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ test('dispatch onBodySent stream', async (t) => {
await p.completed
})

test('dispatch onBodySent async-iterable', (t) => {
test('dispatch onBodySent async-iterable', (t, done) => {
const server = http.createServer((req, res) => {
res.end('ad')
})
Expand All @@ -796,7 +796,7 @@ test('dispatch onBodySent async-iterable', (t) => {
const toSendBytes = chunks.reduce((a, b) => a + Buffer.byteLength(b), 0)
server.listen(0, () => {
const client = new Pool(`http://localhost:${server.address().port}`)
t.after(client.close.bind(client))
t.after(() => client.close.bind(client)())
let sentBytes = 0
let currentChunk = 0
client.dispatch({
Expand All @@ -817,12 +817,13 @@ test('dispatch onBodySent async-iterable', (t) => {
onComplete () {
assert.strictEqual(currentChunk, chunks.length)
assert.strictEqual(sentBytes, toSendBytes)
done()
}
})
})
})

test('dispatch onBodySent throws error', (t) => {
test('dispatch onBodySent throws error', (t, done) => {
const server = http.createServer((req, res) => {
res.end('ended')
})
Expand All @@ -843,6 +844,7 @@ test('dispatch onBodySent throws error', (t) => {
onError (err) {
assert.ok(err instanceof Error)
assert.strictEqual(err.message, 'fail')
done()
},
onConnect () {},
onHeaders () {},
Expand Down