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. 5 #2740

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
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
Loading