Skip to content

Commit

Permalink
chore: migrate a batch of tests to node test runner (nodejs#2737)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak authored and crysmags committed Feb 27, 2024
1 parent c97db52 commit 0ddd13c
Show file tree
Hide file tree
Showing 10 changed files with 547 additions and 467 deletions.
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

0 comments on commit 0ddd13c

Please sign in to comment.