Skip to content
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
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,29 @@
"test:javascript": "npm run test:javascript:no-jest && npm run test:jest",
"test:javascript:no-jest": "npm run generate-pem && npm run test:unit && npm run test:fetch && npm run test:node-fetch && npm run test:infra && npm run test:cache && npm run test:cache-interceptor && npm run test:interceptors && npm run test:cookies && npm run test:eventsource && npm run test:subresource-integrity && npm run test:wpt && npm run test:websocket && npm run test:node-test && npm run test:cache-tests",
"test:javascript:without-intl": "npm run test:javascript:no-jest",
"test:busboy": "borp -p \"test/busboy/*.js\"",
"test:cache": "borp -p \"test/cache/*.js\"",
"test:cache-interceptor": "borp -p \"test/cache-interceptor/*.js\"",
"test:busboy": "borp --timeout 180000 -p \"test/busboy/*.js\"",
"test:cache": "borp --timeout 180000 -p \"test/cache/*.js\"",
"test:cache-interceptor": "borp --timeout 180000 -p \"test/cache-interceptor/*.js\"",
"test:cache-interceptor:sqlite": "cross-env NODE_OPTIONS=--experimental-sqlite npm run test:cache-interceptor",
"test:cookies": "borp -p \"test/cookie/*.js\"",
"test:eventsource": "npm run build:node && borp --expose-gc -p \"test/eventsource/*.js\"",
"test:cookies": "borp --timeout 180000 -p \"test/cookie/*.js\"",
"test:eventsource": "npm run build:node && borp --timeout 180000 --expose-gc -p \"test/eventsource/*.js\"",
"test:fuzzing": "node test/fuzzing/fuzzing.test.js",
"test:fetch": "npm run build:node && borp --timeout 180000 --expose-gc --concurrency 1 -p \"test/fetch/*.js\" && npm run test:webidl && npm run test:busboy",
"test:subresource-integrity": "borp -p \"test/subresource-integrity/*.js\"",
"test:subresource-integrity": "borp --timeout 180000 -p \"test/subresource-integrity/*.js\"",
"test:h2": "npm run test:h2:core && npm run test:h2:fetch",
"test:h2:core": "borp -p \"test/+(http2|h2)*.js\"",
"test:h2:fetch": "npm run build:node && borp -p \"test/fetch/http2*.js\"",
"test:infra": "borp -p \"test/infra/*.js\"",
"test:interceptors": "borp -p \"test/interceptors/*.js\"",
"test:h2:core": "borp --timeout 180000 -p \"test/+(http2|h2)*.js\"",
"test:h2:fetch": "npm run build:node && borp --timeout 180000 -p \"test/fetch/http2*.js\"",
"test:infra": "borp --timeout 180000 -p \"test/infra/*.js\"",
"test:interceptors": "borp --timeout 180000 -p \"test/interceptors/*.js\"",
"test:jest": "cross-env NODE_V8_COVERAGE= jest",
"test:unit": "borp --expose-gc -p \"test/*.js\"",
"test:node-fetch": "borp -p \"test/node-fetch/**/*.js\"",
"test:node-test": "borp -p \"test/node-test/**/*.js\"",
"test:tdd": "borp --expose-gc -p \"test/*.js\"",
"test:tdd:node-test": "borp -p \"test/node-test/**/*.js\" -w",
"test:unit": "borp --timeout 180000 --expose-gc -p \"test/*.js\"",
"test:node-fetch": "borp --timeout 180000 -p \"test/node-fetch/**/*.js\"",
"test:node-test": "borp --timeout 180000 -p \"test/node-test/**/*.js\"",
"test:tdd": "borp --timeout 180000 --expose-gc -p \"test/*.js\"",
"test:tdd:node-test": "borp --timeout 180000 -p \"test/node-test/**/*.js\" -w",
"test:typescript": "tsd && tsc test/imports/undici-import.ts --typeRoots ./types --noEmit && tsc ./types/*.d.ts --noEmit --typeRoots ./types",
"test:webidl": "borp -p \"test/webidl/*.js\"",
"test:websocket": "borp -p \"test/websocket/**/*.js\"",
"test:webidl": "borp --timeout 180000 -p \"test/webidl/*.js\"",
"test:websocket": "borp --timeout 180000 -p \"test/websocket/**/*.js\"",
"test:websocket:autobahn": "node test/autobahn/client.js",
"test:websocket:autobahn:report": "node test/autobahn/report.js",
"test:wpt:setup": "node test/web-platform-tests/wpt-runner.mjs setup",
Expand Down
9 changes: 7 additions & 2 deletions test/fetch/client-error-stack-trace.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
'use strict'

const { test } = require('node:test')
const { test, after } = require('node:test')
const { sep, basename, join } = require('node:path')
const { fetch, setGlobalDispatcher, Agent } = require('../..')
const { fetch, setGlobalDispatcher, getGlobalDispatcher, Agent } = require('../..')

const projectFolder = basename(join(__dirname, '..', '..'))
const { fetch: fetchIndex } = require('../../index-fetch')

const previousDispatcher = getGlobalDispatcher()
setGlobalDispatcher(new Agent({
headersTimeout: 500,
connectTimeout: 500
}))

after(() => {
setGlobalDispatcher(previousDispatcher)
})

test('FETCH: request errors and prints trimmed stack trace', async (t) => {
try {
await fetch('http://a.com')
Expand Down
9 changes: 7 additions & 2 deletions test/fetch/client-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

'use strict'

const { test } = require('node:test')
const { test, after } = require('node:test')
const { createServer } = require('node:http')
const { fetch, Response, Request, FormData } = require('../..')
const { Client, setGlobalDispatcher, Agent } = require('../..')
const { Client, setGlobalDispatcher, getGlobalDispatcher, Agent } = require('../..')
const nodeFetch = require('../../index-fetch')
const { once } = require('node:events')
const { gzipSync } = require('node:zlib')
Expand All @@ -14,11 +14,16 @@ const { randomFillSync, createHash } = require('node:crypto')

const { closeServerAsPromise } = require('../utils/node-http')

const previousDispatcher = getGlobalDispatcher()
setGlobalDispatcher(new Agent({
keepAliveTimeout: 1,
keepAliveMaxTimeout: 1
}))

after(() => {
setGlobalDispatcher(previousDispatcher)
})

test('function signature', (t) => {
t.plan(2)

Expand Down
14 changes: 13 additions & 1 deletion test/fetch/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { once } = require('node:events')
const { createServer } = require('node:http')
const { test, before, after, describe } = require('node:test')
const { fetch } = require('../..')
const { fetch, Client } = require('../..')

describe('content-encoding handling', () => {
const gzipDeflateText = Buffer.from('H4sIAAAAAAAAA6uY89nj7MmT1wM5zuuf8gxkYZCfx5IFACQ8u/wVAAAA', 'base64')
Expand Down Expand Up @@ -118,7 +118,11 @@ describe('content-encoding chain limit', () => {
})

test(`should allow exactly ${MAX_CONTENT_ENCODINGS} content-encodings`, async (t) => {
const client = new Client(`http://localhost:${server.address().port}`)
t.after(() => client.close())

const response = await fetch(`http://localhost:${server.address().port}`, {
dispatcher: client,
keepalive: false,
headers: { 'x-encoding-count': String(MAX_CONTENT_ENCODINGS) }
})
Expand All @@ -129,8 +133,12 @@ describe('content-encoding chain limit', () => {
})

test(`should reject more than ${MAX_CONTENT_ENCODINGS} content-encodings`, async (t) => {
const client = new Client(`http://localhost:${server.address().port}`)
t.after(() => client.close())

await t.assert.rejects(
fetch(`http://localhost:${server.address().port}`, {
dispatcher: client,
keepalive: false,
headers: { 'x-encoding-count': String(MAX_CONTENT_ENCODINGS + 1) }
}),
Expand All @@ -142,8 +150,12 @@ describe('content-encoding chain limit', () => {
})

test('should reject excessive content-encoding chains', async (t) => {
const client = new Client(`http://localhost:${server.address().port}`)
t.after(() => client.close())

await t.assert.rejects(
fetch(`http://localhost:${server.address().port}`, {
dispatcher: client,
keepalive: false,
headers: { 'x-encoding-count': '100' }
}),
Expand Down
4 changes: 4 additions & 0 deletions test/fetch/export-env-proxy-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ test('EnvHttpProxyAgent should be part of Node.js bundle', (t) => {
t.assert.strictEqual(typeof undiciFetch.setGlobalDispatcher, 'function')

const agent = new undiciFetch.EnvHttpProxyAgent()
const previousDispatcher = undiciFetch.getGlobalDispatcher()
undiciFetch.setGlobalDispatcher(agent)
t.after(() => {
undiciFetch.setGlobalDispatcher(previousDispatcher)
})
t.assert.strictEqual(undiciFetch.getGlobalDispatcher(), agent)
})
6 changes: 5 additions & 1 deletion test/fetch/fire-and-forget.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { randomFillSync } = require('node:crypto')
const { setTimeout: sleep, setImmediate: nextTick } = require('node:timers/promises')
const { test } = require('node:test')
const { fetch, Request, Response, Agent, setGlobalDispatcher } = require('../..')
const { fetch, Request, Response, Agent, setGlobalDispatcher, getGlobalDispatcher } = require('../..')
const { createServer } = require('node:http')
const { closeServerAsPromise } = require('../utils/node-http')

Expand Down Expand Up @@ -54,7 +54,11 @@ test('does not need the body to be consumed to continue', { timeout: 180_000 },
keepAliveMaxTimeout: 10,
keepAliveTimeoutThreshold: 10
})
const previousDispatcher = getGlobalDispatcher()
setGlobalDispatcher(agent)
t.after(() => {
setGlobalDispatcher(previousDispatcher)
})
const server = createServer({ joinDuplicateHeaders: true }, (req, res) => {
res.writeHead(200)
res.end(blob)
Expand Down
7 changes: 6 additions & 1 deletion test/fetch/integrity.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@
const { test, after } = require('node:test')
const { createServer } = require('node:http')
const { gzipSync } = require('node:zlib')
const { fetch, setGlobalDispatcher, Agent } = require('../..')
const { fetch, setGlobalDispatcher, getGlobalDispatcher, Agent } = require('../..')
const { once } = require('node:events')
const { closeServerAsPromise } = require('../utils/node-http')
const { runtimeFeatures } = require('../../lib/util/runtime-features')

const previousDispatcher = getGlobalDispatcher()
setGlobalDispatcher(new Agent({
keepAliveTimeout: 1,
keepAliveMaxTimeout: 1
}))

after(() => {
setGlobalDispatcher(previousDispatcher)
})

const skip = runtimeFeatures.has('crypto') === false

test('request with correct integrity checksum', { skip }, async (t) => {
Expand Down
4 changes: 4 additions & 0 deletions test/fetch/issue-1447.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ test('Mocking works with both fetches', async (t) => {
const body = JSON.stringify({ foo: 'bar' })

mockAgent.disableNetConnect()
const previousDispatcher = undici.getGlobalDispatcher()
undici.setGlobalDispatcher(mockAgent)
t.after(() => {
undici.setGlobalDispatcher(previousDispatcher)
})
const pool = mockAgent.get('https://example.com')

pool.intercept({
Expand Down
Loading