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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
"@fastify/busboy": "3.2.0",
"@matteo.collina/tspl": "^0.2.0",
"@metcoder95/https-pem": "^1.0.0",
"@sinonjs/fake-timers": "^12.0.0",
"@sinonjs/fake-timers": "^15.1.1",
"@types/node": "^20.19.22",
"abort-controller": "^3.0.0",
"borp": "^0.20.0",
Expand Down
9 changes: 3 additions & 6 deletions test/cache-interceptor/cache-store-test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { describe, test, after } = require('node:test')
const { Readable } = require('node:stream')
const { once } = require('node:events')
const FakeTimers = require('@sinonjs/fake-timers')
const fakeTimersOpts = { toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'setImmediate', 'clearImmediate', 'Date', 'hrtime', 'performance', ...(typeof Intl !== 'undefined' ? ['Intl'] : [])] }

/**
* @typedef {import('../../types/cache-interceptor.d.ts').default.CacheStore} CacheStore
Expand Down Expand Up @@ -109,9 +110,7 @@ function cacheStoreTests (CacheStore, options) {
})

test('returns stale response before deleteAt', options, async () => {
const clock = FakeTimers.install({
shouldClearNativeTimers: true
})
const clock = FakeTimers.install({ ...fakeTimersOpts, shouldClearNativeTimers: true })

after(() => clock.uninstall())

Expand Down Expand Up @@ -167,9 +166,7 @@ function cacheStoreTests (CacheStore, options) {
})

test('a stale request is overwritten', options, async () => {
const clock = FakeTimers.install({
shouldClearNativeTimers: true
})
const clock = FakeTimers.install({ ...fakeTimersOpts, shouldClearNativeTimers: true })

after(() => clock.uninstall())

Expand Down
9 changes: 5 additions & 4 deletions test/client-keep-alive.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { kConnect } = require('../lib/core/symbols')
const { createServer } = require('node:net')
const http = require('node:http')
const FakeTimers = require('@sinonjs/fake-timers')
const fakeTimersOpts = { toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'setImmediate', 'clearImmediate', 'Date', 'hrtime', 'performance', ...(typeof Intl !== 'undefined' ? ['Intl'] : [])] }

test('keep-alive header', async (t) => {
t = tspl(t, { plan: 2 })
Expand Down Expand Up @@ -46,7 +47,7 @@ test('keep-alive header', async (t) => {
test('keep-alive header 0', async (t) => {
t = tspl(t, { plan: 2 })

const clock = FakeTimers.install()
const clock = FakeTimers.install(fakeTimersOpts)
after(() => clock.uninstall())

const server = createServer((socket) => {
Expand Down Expand Up @@ -151,7 +152,7 @@ test('keep-alive not timeout', async (t) => {
t = tspl(t, { plan: 2 })

const clock = FakeTimers.install({
apis: ['setTimeout']
...fakeTimersOpts
})
after(() => clock.uninstall())

Expand Down Expand Up @@ -193,7 +194,7 @@ test('keep-alive threshold', async (t) => {
t = tspl(t, { plan: 2 })

const clock = FakeTimers.install({
apis: ['setTimeout']
...fakeTimersOpts
})
after(() => clock.uninstall())

Expand Down Expand Up @@ -236,7 +237,7 @@ test('keep-alive max keepalive', async (t) => {
t = tspl(t, { plan: 2 })

const clock = FakeTimers.install({
apis: ['setTimeout']
...fakeTimersOpts
})
after(() => clock.uninstall())

Expand Down
3 changes: 2 additions & 1 deletion test/client-reconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ const { Client } = require('..')
const { createServer } = require('node:http')
const FakeTimers = require('@sinonjs/fake-timers')
const timers = require('../lib/util/timers')
const fakeTimersOpts = { toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'setImmediate', 'clearImmediate', 'Date', 'hrtime', 'performance', ...(typeof Intl !== 'undefined' ? ['Intl'] : [])] }

test('multiple reconnect', async (t) => {
t = tspl(t, { plan: 5 })

let n = 0
const clock = FakeTimers.install()
const clock = FakeTimers.install(fakeTimersOpts)
after(() => clock.uninstall())

const orgTimers = { ...timers }
Expand Down
5 changes: 3 additions & 2 deletions test/client-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { createServer } = require('node:http')
const { Readable } = require('node:stream')
const FakeTimers = require('@sinonjs/fake-timers')
const timers = require('../lib/util/timers')
const fakeTimersOpts = { toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'setImmediate', 'clearImmediate', 'Date', 'hrtime', 'performance', ...(typeof Intl !== 'undefined' ? ['Intl'] : [])] }

test('refresh timeout on pause', async (t) => {
t = tspl(t, { plan: 1 })
Expand Down Expand Up @@ -52,7 +53,7 @@ test('refresh timeout on pause', async (t) => {
test('start headers timeout after request body', async (t) => {
t = tspl(t, { plan: 2 })

const clock = FakeTimers.install({ shouldClearNativeTimers: true })
const clock = FakeTimers.install({ ...fakeTimersOpts, shouldClearNativeTimers: true })
after(() => clock.uninstall())

const orgTimers = { ...timers }
Expand Down Expand Up @@ -110,7 +111,7 @@ test('start headers timeout after request body', async (t) => {
test('start headers timeout after async iterator request body', async (t) => {
t = tspl(t, { plan: 1 })

const clock = FakeTimers.install({ shouldClearNativeTimers: true })
const clock = FakeTimers.install({ ...fakeTimersOpts, shouldClearNativeTimers: true })
after(() => clock.uninstall())

const orgTimers = { ...timers }
Expand Down
5 changes: 3 additions & 2 deletions test/eventsource/eventsource-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const http = require('node:http')
const { test, describe, after } = require('node:test')
const FakeTimers = require('@sinonjs/fake-timers')
const { EventSource, defaultReconnectionTime } = require('../../lib/web/eventsource/eventsource')
const fakeTimersOpts = { toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'setImmediate', 'clearImmediate', 'Date', 'hrtime', 'performance', ...(typeof Intl !== 'undefined' ? ['Intl'] : [])] }
const { randomInt } = require('node:crypto')

describe('EventSource - sending correct request headers', () => {
Expand Down Expand Up @@ -176,7 +177,7 @@ describe('EventSource - received response must have content-type to be text/even
})

test('should try to connect again if server is unreachable', async (t) => {
const clock = FakeTimers.install()
const clock = FakeTimers.install(fakeTimersOpts)

after(() => clock.uninstall())
const reconnectionTime = defaultReconnectionTime
Expand Down Expand Up @@ -209,7 +210,7 @@ describe('EventSource - received response must have content-type to be text/even

test('should try to connect again if server is unreachable, configure reconnectionTime', async (t) => {
const reconnectionTime = 1000
const clock = FakeTimers.install()
const clock = FakeTimers.install(fakeTimersOpts)
after(() => clock.uninstall())

const domain = 'bad.n' + randomInt(1e10).toString(36) + '.proxy'
Expand Down
3 changes: 2 additions & 1 deletion test/eventsource/eventsource-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const http = require('node:http')
const { test, describe, after } = require('node:test')
const { EventSource, defaultReconnectionTime } = require('../../lib/web/eventsource/eventsource')
const FakeTimers = require('@sinonjs/fake-timers')
const fakeTimersOpts = { toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'setImmediate', 'clearImmediate', 'Date', 'hrtime', 'performance', ...(typeof Intl !== 'undefined' ? ['Intl'] : [])] }

describe('EventSource - message', () => {
test('Should not emit a message if only retry field was sent', (t, done) => {
Expand Down Expand Up @@ -202,7 +203,7 @@ describe('EventSource - message', () => {
})

test('Should not emit a custom type message if no data is provided', (t, done) => {
const clock = FakeTimers.install()
const clock = FakeTimers.install(fakeTimersOpts)
after(() => clock.uninstall())

t.plan(1)
Expand Down
9 changes: 5 additions & 4 deletions test/eventsource/eventsource-reconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ const http = require('node:http')
const { test, describe, after } = require('node:test')
const FakeTimers = require('@sinonjs/fake-timers')
const { EventSource, defaultReconnectionTime } = require('../../lib/web/eventsource/eventsource')
const fakeTimersOpts = { toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'setImmediate', 'clearImmediate', 'Date', 'hrtime', 'performance', ...(typeof Intl !== 'undefined' ? ['Intl'] : [])] }

describe('EventSource - reconnect', () => {
test('Should reconnect on connection closed by server', (t, done) => {
t.plan(1)

const clock = FakeTimers.install()
const clock = FakeTimers.install(fakeTimersOpts)
after(() => clock.uninstall())

const server = http.createServer({ joinDuplicateHeaders: true }, (req, res) => {
Expand Down Expand Up @@ -43,7 +44,7 @@ describe('EventSource - reconnect', () => {

test('Should reconnect on with reconnection timeout', (t, done) => {
t.plan(2)
const clock = FakeTimers.install()
const clock = FakeTimers.install(fakeTimersOpts)
after(() => clock.uninstall())

const server = http.createServer({ joinDuplicateHeaders: true }, (req, res) => {
Expand Down Expand Up @@ -80,7 +81,7 @@ describe('EventSource - reconnect', () => {

test('Should reconnect on with modified reconnection timeout', (t, done) => {
t.plan(3)
const clock = FakeTimers.install()
const clock = FakeTimers.install(fakeTimersOpts)
after(() => clock.uninstall())

const server = http.createServer({ joinDuplicateHeaders: true }, (req, res) => {
Expand Down Expand Up @@ -119,7 +120,7 @@ describe('EventSource - reconnect', () => {

test('Should reconnect and send lastEventId', async (t) => {
t.plan(1)
const clock = FakeTimers.install()
const clock = FakeTimers.install(fakeTimersOpts)
after(() => clock.uninstall())

let requestCount = 0
Expand Down
3 changes: 2 additions & 1 deletion test/fetch/fetch-timeouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ const timers = require('../../lib/util/timers')
const { createServer } = require('node:http')
const FakeTimers = require('@sinonjs/fake-timers')
const { closeServerAsPromise } = require('../utils/node-http')
const fakeTimersOpts = { toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'setImmediate', 'clearImmediate', 'Date', 'hrtime', 'performance', ...(typeof Intl !== 'undefined' ? ['Intl'] : [])] }

test('Fetch very long request, timeout overridden so no error', (t, done) => {
const minutes = 6
const msToDelay = 1000 * 60 * minutes

t.plan(1)

const clock = FakeTimers.install()
const clock = FakeTimers.install(fakeTimersOpts)
t.after(clock.uninstall.bind(clock))

const orgTimers = { ...timers }
Expand Down
7 changes: 4 additions & 3 deletions test/interceptors/cache-async-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const { request, Client, interceptors } = require('../../index')
const MemoryCacheStore = require('../../lib/cache/memory-cache-store')
const FakeTimers = require('@sinonjs/fake-timers')
const { setTimeout } = require('node:timers/promises')
const fakeTimersOpts = { toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'setImmediate', 'clearImmediate', 'Date', 'hrtime', 'performance', ...(typeof Intl !== 'undefined' ? ['Intl'] : [])] }

/**
* Wraps a MemoryCacheStore to simulate an async remote store:
Expand Down Expand Up @@ -49,7 +50,7 @@ class AsyncCacheStore {

describe('cache interceptor with async store', () => {
test('stale-while-revalidate 304 refreshes cache with async store', async () => {
const clock = FakeTimers.install({ now: 1 })
const clock = FakeTimers.install({ ...fakeTimersOpts, now: 1 })
after(() => clock.uninstall())

let count200 = 0
Expand Down Expand Up @@ -118,7 +119,7 @@ describe('cache interceptor with async store', () => {
})

test('stale-while-revalidate 200 refreshes cache with async store', async () => {
const clock = FakeTimers.install({ now: 1 })
const clock = FakeTimers.install({ ...fakeTimersOpts, now: 1 })
after(() => clock.uninstall())

let requestCount = 0
Expand Down Expand Up @@ -172,7 +173,7 @@ describe('cache interceptor with async store', () => {
})

test('null vary values are not sent in revalidation headers', async () => {
const clock = FakeTimers.install({ now: 1 })
const clock = FakeTimers.install({ ...fakeTimersOpts, now: 1 })
after(() => clock.uninstall())

let revalidationHeaders = null
Expand Down
9 changes: 3 additions & 6 deletions test/interceptors/cache-revalidate-stale.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ const { once } = require('node:events')
const { request, Client, interceptors } = require('../../index')
const FakeTimers = require('@sinonjs/fake-timers')
const { setTimeout } = require('node:timers/promises')
const fakeTimersOpts = { toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'setImmediate', 'clearImmediate', 'Date', 'hrtime', 'performance', ...(typeof Intl !== 'undefined' ? ['Intl'] : [])] }

test('revalidates the request when the response is stale', async () => {
const clock = FakeTimers.install({
now: 1
})
const clock = FakeTimers.install({ ...fakeTimersOpts, now: 1 })
after(() => clock.uninstall())

let count = 0
Expand Down Expand Up @@ -75,9 +74,7 @@ describe('revalidates the request, handles 304s during stale-while-revalidate',
}

async function revalidateTest (useEtag = false) {
const clock = FakeTimers.install({
now: 1
})
const clock = FakeTimers.install({ ...fakeTimersOpts, now: 1 })
after(() => clock.uninstall())

let count200 = 0
Expand Down
Loading
Loading