Skip to content

Commit

Permalink
chore: migrate a batch of tests to node test runner (#2740)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak authored Feb 12, 2024
1 parent c27b00e commit e49471f
Show file tree
Hide file tree
Showing 6 changed files with 365 additions and 276 deletions.
27 changes: 14 additions & 13 deletions test/redirect-pipeline.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const t = require('tap')
const { tspl } = require('@matteo.collina/tspl')
const { test } = require('node:test')
const { pipeline: undiciPipeline } = require('..')
const { pipeline: streamPipelineCb } = require('node:stream')
const { promisify } = require('node:util')
Expand All @@ -9,42 +10,42 @@ const { startRedirectingServer } = require('./utils/redirecting-servers')

const streamPipeline = promisify(streamPipelineCb)

t.test('should not follow redirection by default if not using RedirectAgent', async t => {
t.plan(3)
test('should not follow redirection by default if not using RedirectAgent', async t => {
t = tspl(t, { plan: 3 })

const body = []
const serverRoot = await startRedirectingServer(t)
const serverRoot = await startRedirectingServer()

await streamPipeline(
createReadable('REQUEST'),
undiciPipeline(`http://${serverRoot}/`, {}, ({ statusCode, headers, body }) => {
t.equal(statusCode, 302)
t.equal(headers.location, `http://${serverRoot}/302/1`)
t.strictEqual(statusCode, 302)
t.strictEqual(headers.location, `http://${serverRoot}/302/1`)

return body
}),
createWritable(body)
)

t.equal(body.length, 0)
t.strictEqual(body.length, 0)
})

t.test('should not follow redirects when using RedirectAgent within pipeline', async t => {
t.plan(3)
test('should not follow redirects when using RedirectAgent within pipeline', async t => {
t = tspl(t, { plan: 3 })

const body = []
const serverRoot = await startRedirectingServer(t)
const serverRoot = await startRedirectingServer()

await streamPipeline(
createReadable('REQUEST'),
undiciPipeline(`http://${serverRoot}/`, { maxRedirections: 1 }, ({ statusCode, headers, body }) => {
t.equal(statusCode, 302)
t.equal(headers.location, `http://${serverRoot}/302/1`)
t.strictEqual(statusCode, 302)
t.strictEqual(headers.location, `http://${serverRoot}/302/1`)

return body
}),
createWritable(body)
)

t.equal(body.length, 0)
t.strictEqual(body.length, 0)
})
13 changes: 7 additions & 6 deletions test/redirect-relative.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
'use strict'

const t = require('tap')
const { tspl } = require('@matteo.collina/tspl')
const { test } = require('node:test')
const { request } = require('..')
const {
startRedirectingWithRelativePath
} = require('./utils/redirecting-servers')

t.test('should redirect to relative URL according to RFC 7231', async t => {
t.plan(2)
test('should redirect to relative URL according to RFC 7231', async t => {
t = tspl(t, { plan: 2 })

const server = await startRedirectingWithRelativePath(t)
const server = await startRedirectingWithRelativePath()

const { statusCode, body } = await request(`http://${server}`, {
maxRedirections: 3
})

const finalPath = await body.text()

t.equal(statusCode, 200)
t.equal(finalPath, '/absolute/b')
t.strictEqual(statusCode, 200)
t.strictEqual(finalPath, '/absolute/b')
})
Loading

0 comments on commit e49471f

Please sign in to comment.