Skip to content
Open
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
7 changes: 3 additions & 4 deletions test/issue-1757.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

const { deepStrictEqual, strictEqual } = require('node:assert')
const { test } = require('node:test')
const { Dispatcher, setGlobalDispatcher, fetch, MockAgent } = require('..')

Expand All @@ -23,7 +22,7 @@ class MiniflareDispatcher extends Dispatcher {
}
}

test('https://github.com/nodejs/undici/issues/1757', async () => {
test('https://github.com/nodejs/undici/issues/1757', async (t) => {
const mockAgent = new MockAgent()
const mockClient = mockAgent.get('http://localhost:3000')
mockAgent.disableNetConnect()
Expand All @@ -50,6 +49,6 @@ test('https://github.com/nodejs/undici/issues/1757', async () => {
body: JSON.stringify({ foo: 'bar' })
})

deepStrictEqual(await response.json(), { foo: 'bar' })
strictEqual(response.status, 200)
t.assert.deepStrictEqual(await response.json(), { foo: 'bar' })
t.assert.strictEqual(response.status, 200)
})
5 changes: 2 additions & 3 deletions test/issue-2065.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
'use strict'

const { tspl } = require('@matteo.collina/tspl')
const { test, after } = require('node:test')
const { createServer } = require('node:http')
const { once } = require('node:events')
const { FormData, request } = require('..')

test('undici.request with a FormData body should set content-length header', async (t) => {
t = tspl(t, { plan: 1 })
t.plan(1)

const server = createServer({ joinDuplicateHeaders: true }, (req, res) => {
t.ok(req.headers['content-length'])
t.assert.ok(req.headers['content-length'])
res.end()
}).listen(0)

Expand Down
7 changes: 2 additions & 5 deletions test/issue-2078.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict'

const { tspl } = require('@matteo.collina/tspl')
const { test, after } = require('node:test')
const { MockAgent, getGlobalDispatcher, setGlobalDispatcher, fetch } = require('..')

test('MockPool.reply headers are an object, not an array - issue #2078', async (t) => {
t = tspl(t, { plan: 1 })
t.plan(1)

const global = getGlobalDispatcher()
const mockAgent = new MockAgent()
Expand All @@ -18,12 +17,10 @@ test('MockPool.reply headers are an object, not an array - issue #2078', async (
path: '/foo',
method: 'GET'
}).reply((options) => {
t.strictEqual(Array.isArray(options.headers), false)
t.assert.strictEqual(Array.isArray(options.headers), false)

return { statusCode: 200 }
})

await fetch('http://localhost/foo')

await t.completed
})
5 changes: 2 additions & 3 deletions test/issue-2283.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const { describe, test } = require('node:test')
const assert = require('node:assert')
const { FormData, Response } = require('..')

describe('https://github.com/nodejs/undici/issues/2283', () => {
Expand All @@ -14,11 +13,11 @@ describe('https://github.com/nodejs/undici/issues/2283', () => {
const body = await res.clone().text()

// Just making sure that it contains ;charset=utf-8
assert.ok(body.includes('text/plain;charset=utf-8'))
t.assert.ok(body.includes('text/plain;charset=utf-8'))

const formData = await new Response(fd).formData()

// returns just 'text/plain'
assert.ok(formData.get('x').type === 'text/plain;charset=utf-8')
t.assert.ok(formData.get('x').type === 'text/plain;charset=utf-8')
})
})
5 changes: 2 additions & 3 deletions test/issue-2349.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict'

const { test } = require('node:test')
const { rejects } = require('node:assert')
const { Writable } = require('node:stream')
const { MockAgent, stream } = require('..')

test('stream() does not fail after request has been aborted', () => {
test('stream() does not fail after request has been aborted', async (t) => {
const mockAgent = new MockAgent()

mockAgent.disableNetConnect()
Expand All @@ -22,7 +21,7 @@ test('stream() does not fail after request has been aborted', () => {

setTimeout(() => ac.abort(), 5)

rejects(
await t.assert.rejects(
stream(
'http://localhost:3333/',
{
Expand Down
11 changes: 4 additions & 7 deletions test/issue-2590.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
'use strict'

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

test('aborting request with custom reason', async (t) => {
t = tspl(t, { plan: 3 })
t.plan(3)
const server = createServer({ joinDuplicateHeaders: true }, () => {}).listen(0)

after(() => server.close())
Expand All @@ -20,20 +19,18 @@ test('aborting request with custom reason', async (t) => {
const ac2 = new AbortController()
ac2.abort() // no reason

await t.rejects(
await t.assert.rejects(
request(`http://localhost:${server.address().port}`, { signal: timeout }),
timeout.reason
)

await t.rejects(
await t.assert.rejects(
request(`http://localhost:${server.address().port}`, { signal: ac.signal }),
/Error: aborted/
)

await t.rejects(
await t.assert.rejects(
request(`http://localhost:${server.address().port}`, { signal: ac2.signal }),
{ name: 'AbortError' }
)

await t.completed
})
11 changes: 4 additions & 7 deletions test/issue-3356.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

const { tspl } = require('@matteo.collina/tspl')
const { test, after } = require('node:test')
const { setTimeout: sleep } = require('node:timers/promises')
const { createServer } = require('node:http')
Expand All @@ -9,7 +8,7 @@ const { tick: fastTimersTick } = require('../lib/util/timers')
const { fetch, Agent, RetryAgent } = require('..')

test('https://github.com/nodejs/undici/issues/3356', { skip: process.env.CITGM }, async (t) => {
t = tspl(t, { plan: 3 })
t.plan(3)

let shouldRetry = true
const server = createServer({ joinDuplicateHeaders: true })
Expand Down Expand Up @@ -49,13 +48,11 @@ test('https://github.com/nodejs/undici/issues/3356', { skip: process.env.CITGM }
await sleep(500)

try {
t.equal(response.status, 200)
t.assert.strictEqual(response.status, 200)
// consume response
await response.text()
} catch (err) {
t.equal(err.name, 'TypeError')
t.equal(err.cause.code, 'UND_ERR_REQ_RETRY')
t.assert.strictEqual(err.name, 'TypeError')
t.assert.strictEqual(err.cause.code, 'UND_ERR_REQ_RETRY')
}

await t.completed
})
9 changes: 4 additions & 5 deletions test/issue-3410.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

const { tspl } = require('@matteo.collina/tspl')
const { fork } = require('node:child_process')
const { resolve: pathResolve } = require('node:path')
const { describe, test } = require('node:test')
Expand All @@ -9,7 +8,7 @@ const { eventLoopBlocker } = require('./utils/event-loop-blocker')

describe('https://github.com/nodejs/undici/issues/3410', () => {
test('FastTimers', async (t) => {
t = tspl(t, { plan: 1 })
t.plan(1)

// Spawn a server in a new process to avoid effects from the blocking event loop
const {
Expand Down Expand Up @@ -42,13 +41,13 @@ describe('https://github.com/nodejs/undici/issues/3410', () => {

const response = await fetchPromise

t.equal(await response.text(), 'Hello World')
t.assert.strictEqual(await response.text(), 'Hello World')

serverProcess.kill('SIGKILL')
})

test('native Timers', async (t) => {
t = tspl(t, { plan: 1 })
t.plan(1)

// Spawn a server in a new process to avoid effects from the blocking event loop
const {
Expand Down Expand Up @@ -81,7 +80,7 @@ describe('https://github.com/nodejs/undici/issues/3410', () => {

const response = await fetchPromise

t.equal(await response.text(), 'Hello World')
t.assert.strictEqual(await response.text(), 'Hello World')

serverProcess.kill('SIGKILL')
})
Expand Down
11 changes: 5 additions & 6 deletions test/issue-3904.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { describe, test, after } = require('node:test')
const assert = require('node:assert')
const { createServer } = require('node:http')
const { once } = require('node:events')
const MemoryCacheStore = require('../lib/cache/memory-cache-store.js')
Expand All @@ -11,7 +10,7 @@ describe('Cache with cache-control: no-store request header', () => {
'cache-control',
'Cache-Control'
].forEach(headerName => {
test(`should not cache response for request with header: "${headerName}: no-store`, async () => {
test(`should not cache response for request with header: "${headerName}: no-store`, async (t) => {
const store = new MemoryCacheStore()
let requestCount = 0
const server = createServer({ joinDuplicateHeaders: true }, (req, res) => {
Expand Down Expand Up @@ -44,13 +43,13 @@ describe('Cache with cache-control: no-store request header', () => {

const res1 = await request(url, { headers: { [headerName]: 'no-store' } })
const body1 = await res1.body.text()
assert.strictEqual(body1, 'Request count: 1')
assert.strictEqual(requestCount, 1)
t.assert.strictEqual(body1, 'Request count: 1')
t.assert.strictEqual(requestCount, 1)

const res2 = await request(url)
const body2 = await res2.body.text()
assert.strictEqual(body2, 'Request count: 2')
assert.strictEqual(requestCount, 2)
t.assert.strictEqual(body2, 'Request count: 2')
t.assert.strictEqual(requestCount, 2)

await new Promise(resolve => server.close(resolve))
})
Expand Down
3 changes: 1 addition & 2 deletions test/issue-3934.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const { test } = require('node:test')
const { createServer } = require('node:http')
const { once } = require('node:events')
const assert = require('node:assert')
const { Agent, RetryAgent, request } = require('..')

// https://github.com/nodejs/undici/issues/3934
Expand All @@ -28,5 +27,5 @@ test('WrapHandler works with multiple header values', async (t) => {
headers
} = await request(`http://localhost:${server.address().port}`, { dispatcher: retryAgent })

assert.deepStrictEqual(headers['set-cookie'], ['a', 'b', 'c'])
t.assert.deepStrictEqual(headers['set-cookie'], ['a', 'b', 'c'])
})
23 changes: 11 additions & 12 deletions test/issue-3959.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const { describe, test, after } = require('node:test')
const assert = require('node:assert')
const { createServer } = require('node:http')
const MemoryCacheStore = require('../lib/cache/memory-cache-store.js')
const { request, Agent, setGlobalDispatcher } = require('..')
const { interceptors } = require('..')
const { runtimeFeatures } = require('../lib/util/runtime-features.js')

describe('Cache with Vary headers', () => {
async function runCacheTest (store) {
async function runCacheTest (t, store) {
let requestCount = 0
const server = createServer({ joinDuplicateHeaders: true }, (req, res) => {
requestCount++
Expand All @@ -33,34 +32,34 @@ describe('Cache with Vary headers', () => {

const res1 = await request(url)
const body1 = await res1.body.text()
assert.strictEqual(body1, 'Request count: 1')
assert.strictEqual(requestCount, 1)
t.assert.strictEqual(body1, 'Request count: 1')
t.assert.strictEqual(requestCount, 1)

const res2 = await request(url)
const body2 = await res2.body.text()
assert.strictEqual(body2, 'Request count: 1')
assert.strictEqual(requestCount, 1)
t.assert.strictEqual(body2, 'Request count: 1')
t.assert.strictEqual(requestCount, 1)

const res3 = await request(url, {
headers: {
'Accept-Encoding': 'gzip'
}
})
const body3 = await res3.body.text()
assert.strictEqual(body3, 'Request count: 2')
assert.strictEqual(requestCount, 2)
t.assert.strictEqual(body3, 'Request count: 2')
t.assert.strictEqual(requestCount, 2)

await new Promise(resolve => server.close(resolve))
}

test('should cache response with MemoryCacheStore when Vary header exists but request header is missing', async () => {
await runCacheTest(new MemoryCacheStore())
test('should cache response with MemoryCacheStore when Vary header exists but request header is missing', async (t) => {
await runCacheTest(t, new MemoryCacheStore())
})

test('should cache response with SqliteCacheStore when Vary header exists but request header is missing', { skip: runtimeFeatures.has('sqlite') === false }, async () => {
test('should cache response with SqliteCacheStore when Vary header exists but request header is missing', { skip: runtimeFeatures.has('sqlite') === false }, async (t) => {
const SqliteCacheStore = require('../lib/cache/sqlite-cache-store.js')
const sqliteStore = new SqliteCacheStore()
await runCacheTest(sqliteStore)
await runCacheTest(t, sqliteStore)
after(() => sqliteStore.close())
})
})
3 changes: 1 addition & 2 deletions test/issue-4244.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { test, describe } = require('node:test')
const assert = require('node:assert')
const { createServer } = require('node:http')
const { request, Agent, Pool } = require('..')

Expand Down Expand Up @@ -30,7 +29,7 @@ describe('Agent should close inactive clients', () => {
}
})
const { statusCode } = await request(`http://localhost:${server.address().port}`, { dispatcher: agent })
assert.equal(statusCode, 200)
t.assert.strictEqual(statusCode, 200)

await p
})
Expand Down
Loading
Loading