diff --git a/package.json b/package.json index bdfe7896b19..20bca679da0 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/fetch/client-error-stack-trace.js b/test/fetch/client-error-stack-trace.js index daa4838a34e..b31e2830428 100644 --- a/test/fetch/client-error-stack-trace.js +++ b/test/fetch/client-error-stack-trace.js @@ -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') diff --git a/test/fetch/client-fetch.js b/test/fetch/client-fetch.js index 5e424783d09..81a8bb4028a 100644 --- a/test/fetch/client-fetch.js +++ b/test/fetch/client-fetch.js @@ -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') @@ -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) diff --git a/test/fetch/encoding.js b/test/fetch/encoding.js index ec07a4bdbd8..893a24886e4 100644 --- a/test/fetch/encoding.js +++ b/test/fetch/encoding.js @@ -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') @@ -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) } }) @@ -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) } }), @@ -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' } }), diff --git a/test/fetch/export-env-proxy-agent.js b/test/fetch/export-env-proxy-agent.js index a40a48566ee..e43b974c793 100644 --- a/test/fetch/export-env-proxy-agent.js +++ b/test/fetch/export-env-proxy-agent.js @@ -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) }) diff --git a/test/fetch/fire-and-forget.js b/test/fetch/fire-and-forget.js index 8e0df453fca..a3ea6d83bb2 100644 --- a/test/fetch/fire-and-forget.js +++ b/test/fetch/fire-and-forget.js @@ -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') @@ -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) diff --git a/test/fetch/integrity.js b/test/fetch/integrity.js index bd8d5f953f4..b01125b8ef6 100644 --- a/test/fetch/integrity.js +++ b/test/fetch/integrity.js @@ -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) => { diff --git a/test/fetch/issue-1447.js b/test/fetch/issue-1447.js index 118237b7772..55b704b720f 100644 --- a/test/fetch/issue-1447.js +++ b/test/fetch/issue-1447.js @@ -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({