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

chore: migrate a batch of tests to node test runner no. 2 #2737

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions test/client-connect.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
'use strict'

const { test } = require('tap')
const { tspl } = require('@matteo.collina/tspl')
const { test, after } = require('node:test')
const { once } = require('node:events')
const { Client, errors } = require('..')
const http = require('node:http')
const EE = require('node:events')
const { kBusy } = require('../lib/core/symbols')

// TODO: move to test/node-test/client-connect.js
test('connect aborted after connect', (t) => {
t.plan(3)
test('connect aborted after connect', async (t) => {
t = tspl(t, { plan: 3 })

const signal = new EE()
const server = http.createServer((req, res) => {
Expand All @@ -17,22 +19,26 @@ test('connect aborted after connect', (t) => {
server.on('connect', (req, c, firstBodyChunk) => {
signal.emit('abort')
})
t.teardown(server.close.bind(server))

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`, {
pipelining: 3
})
t.teardown(client.destroy.bind(client))

client.connect({
path: '/',
signal,
opaque: 'asd'
}, (err, { opaque }) => {
t.equal(opaque, 'asd')
t.ok(err instanceof errors.RequestAbortedError)
})
t.equal(client[kBusy], true)
after(() => server.close())

server.listen(0)

await once(server, 'listening')

const client = new Client(`http://localhost:${server.address().port}`, {
pipelining: 3
})
after(() => client.close())

client.connect({
path: '/',
signal,
opaque: 'asd'
}, (err, { opaque }) => {
t.strictEqual(opaque, 'asd')
t.ok(err instanceof errors.RequestAbortedError)
})
t.strictEqual(client[kBusy], true)

await t.completed
})
17 changes: 10 additions & 7 deletions test/client-idempotent-body.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
'use strict'

const { test } = require('tap')
const { tspl } = require('@matteo.collina/tspl')
const { test, after } = require('node:test')
const { Client } = require('..')
const { createServer } = require('node:http')

test('idempotent retry', (t) => {
t.plan(11)
test('idempotent retry', async (t) => {
t = tspl(t, { plan: 11 })

const body = 'world'
const server = createServer((req, res) => {
let buf = ''
req.on('data', data => {
buf += data
}).on('end', () => {
t.strictSame(buf, body)
t.strictEqual(buf, body)
res.end()
})
})
t.teardown(server.close.bind(server))
after(() => server.close())

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`, {
pipelining: 2
})
t.teardown(client.close.bind(client))
after(() => client.close())

const _err = new Error()

Expand All @@ -36,8 +37,10 @@ test('idempotent retry', (t) => {
}, () => {
throw _err
}, (err) => {
t.equal(err, _err)
t.strictEqual(err, _err)
})
}
})

await t.completed
})
Loading
Loading