Skip to content

Commit

Permalink
chore: migrate a batch of tests to node test runner (nodejs#2744)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak authored and crysmags committed Feb 27, 2024
1 parent 4cc822c commit a7f0824
Show file tree
Hide file tree
Showing 9 changed files with 838 additions and 678 deletions.
380 changes: 223 additions & 157 deletions test/client-pipeline.js

Large diffs are not rendered by default.

226 changes: 125 additions & 101 deletions test/client-pipelining.js

Large diffs are not rendered by default.

57 changes: 33 additions & 24 deletions test/client-timeout.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
'use strict'

const { test } = require('tap')
const { tspl } = require('@matteo.collina/tspl')
const { test, after } = require('node:test')
const { Client, errors } = require('..')
const { createServer } = require('node:http')
const { Readable } = require('node:stream')
const FakeTimers = require('@sinonjs/fake-timers')
const timers = require('../lib/timers')

test('refresh timeout on pause', (t) => {
t.plan(1)
test('refresh timeout on pause', async (t) => {
t = tspl(t, { plan: 1 })

const server = createServer((req, res) => {
res.flushHeaders()
})
t.teardown(server.close.bind(server))
after(() => server.close())

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

client.dispatch({
path: '/',
Expand All @@ -44,30 +45,32 @@ test('refresh timeout on pause', (t) => {
}
})
})

await t.completed
})

test('start headers timeout after request body', (t) => {
t.plan(2)
test('start headers timeout after request body', async (t) => {
t = tspl(t, { plan: 2 })

const clock = FakeTimers.install()
t.teardown(clock.uninstall.bind(clock))
const clock = FakeTimers.install({ shouldClearNativeTimers: true })
after(() => clock.uninstall())

const orgTimers = { ...timers }
Object.assign(timers, { setTimeout, clearTimeout })
t.teardown(() => {
after(() => {
Object.assign(timers, orgTimers)
})

const server = createServer((req, res) => {
})
t.teardown(server.close.bind(server))
after(() => server.close())

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

const body = new Readable({ read () {} })
client.dispatch({
Expand Down Expand Up @@ -100,30 +103,32 @@ test('start headers timeout after request body', (t) => {
}
})
})

await t.completed
})

test('start headers timeout after async iterator request body', (t) => {
t.plan(1)
test('start headers timeout after async iterator request body', async (t) => {
t = tspl(t, { plan: 1 })

const clock = FakeTimers.install()
t.teardown(clock.uninstall.bind(clock))
const clock = FakeTimers.install({ shouldClearNativeTimers: true })
after(() => clock.uninstall())

const orgTimers = { ...timers }
Object.assign(timers, { setTimeout, clearTimeout })
t.teardown(() => {
after(() => {
Object.assign(timers, orgTimers)
})

const server = createServer((req, res) => {
})
t.teardown(server.close.bind(server))
after(() => server.close())

server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`, {
bodyTimeout: 0,
headersTimeout: 100
})
t.teardown(client.destroy.bind(client))
after(() => client.destroy())
let res
const body = (async function * () {
await new Promise((resolve) => { res = resolve })
Expand Down Expand Up @@ -157,21 +162,23 @@ test('start headers timeout after async iterator request body', (t) => {
}
})
})

await t.completed
})

test('parser resume with no body timeout', (t) => {
t.plan(1)
test('parser resume with no body timeout', async (t) => {
t = tspl(t, { plan: 1 })

const server = createServer((req, res) => {
res.end('asd')
})
t.teardown(server.close.bind(server))
after(() => server.close())

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

client.dispatch({
path: '/',
Expand All @@ -190,8 +197,10 @@ test('parser resume with no body timeout', (t) => {
t.ok(true, 'pass')
},
onError (err) {
t.error(err)
t.ifError(err)
}
})
})

await t.completed
})
Loading

0 comments on commit a7f0824

Please sign in to comment.