Skip to content

Commit

Permalink
Update dependency @sinonjs/fake-timers to v13 (#308)
Browse files Browse the repository at this point in the history
* Update dependency @sinonjs/fake-timers to v13

* Fix test

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Michael Xiao <michael.xiao@smartcontract.com>
  • Loading branch information
renovate[bot] and mxiao-cll authored Nov 26, 2024
1 parent b70f005 commit 6ed37b7
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 43 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"create-external-adapter": "adapter-generator.js"
},
"devDependencies": {
"@sinonjs/fake-timers": "9.1.2",
"@sinonjs/fake-timers": "13.0.5",
"@types/eventsource": "1.1.15",
"@types/node": "22.10.0",
"@types/sinonjs__fake-timers": "8.1.5",
Expand Down
7 changes: 4 additions & 3 deletions test/background-executor.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import FakeTimers, { InstalledClock } from '@sinonjs/fake-timers'
import { InstalledClock } from '@sinonjs/fake-timers'
import { installTimers } from './helper'
import untypedTest, { TestFn } from 'ava'
import { start } from '../src'
import { Adapter, AdapterEndpoint, EndpointContext } from '../src/adapter'
Expand Down Expand Up @@ -41,7 +42,7 @@ test.serial('background executor calls transport function with background contex
})

test.serial('background executor ends recursive chain on server close', async (t) => {
const clock = FakeTimers.install()
const clock = installTimers()
let timesCalled = 0

const transport = new (class extends NopTransport {
Expand Down Expand Up @@ -124,7 +125,7 @@ test.serial('background executor error does not stop the loop', async (t) => {

test.serial('background executor timeout does not stop the loop', async (t) => {
eaMetrics.clear()
const clock = FakeTimers.install()
const clock = installTimers()
const [promise, resolve] = deferredPromise<EndpointContext<NopTransportTypes>>()
let iteration = 0

Expand Down
10 changes: 7 additions & 3 deletions test/cache/local.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import FakeTimers, { InstalledClock } from '@sinonjs/fake-timers'
import { InstalledClock } from '@sinonjs/fake-timers'
import { installTimers } from '../helper'
import untypedTest, { TestFn } from 'ava'
import { Adapter, AdapterDependencies, AdapterEndpoint } from '../../src/adapter'
import { Cache, CacheFactory, LocalCache } from '../../src/cache'
Expand All @@ -13,8 +14,11 @@ const test = untypedTest as TestFn<{
cache: Cache
}>

test.before(async (t) => {
t.context.clock = installTimers()
})

test.beforeEach(async (t) => {
t.context.clock = FakeTimers.install()
const config = new AdapterConfig(
{},
{
Expand Down Expand Up @@ -51,7 +55,7 @@ test.beforeEach(async (t) => {
})

test.afterEach((t) => {
t.context.clock.uninstall()
t.context.clock.reset()
})

test.serial('Test cache factory success (redis)', async (t) => {
Expand Down
9 changes: 5 additions & 4 deletions test/cache/response-cache.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import FakeTimers, { InstalledClock } from '@sinonjs/fake-timers'
import { InstalledClock } from '@sinonjs/fake-timers'
import { installTimers } from '../helper'
import untypedTest, { TestFn } from 'ava'
import { FastifyInstance } from 'fastify'
import { Adapter, AdapterEndpoint } from '../../src/adapter'
Expand All @@ -19,12 +20,12 @@ const test = untypedTest as TestFn<{
api: FastifyInstance | undefined
}>

test.beforeEach((t) => {
t.context.clock = FakeTimers.install()
test.before((t) => {
t.context.clock = installTimers()
})

test.afterEach(async (t) => {
t.context.clock.uninstall()
t.context.clock.reset()
await t.context.testAdapter?.api.close()
})

Expand Down
16 changes: 16 additions & 0 deletions test/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import FakeTimers from '@sinonjs/fake-timers'

export const installTimers = () => {
return FakeTimers.install({
toFake: [
'setTimeout',
'clearTimeout',
'setImmediate',
'clearImmediate',
'setInterval',
'clearInterval',
'Date',
'hrtime',
],
})
}
5 changes: 3 additions & 2 deletions test/metrics/metrics.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import FakeTimers, { InstalledClock } from '@sinonjs/fake-timers'
import { InstalledClock } from '@sinonjs/fake-timers'
import { installTimers } from '../helper'
import untypedTest, { TestFn } from 'ava'
import axios from 'axios'
import MockAdapter from 'axios-mock-adapter'
Expand Down Expand Up @@ -100,7 +101,7 @@ const to = 'USD'
const price = 1234

test.before(async (t) => {
t.context.clock = FakeTimers.install()
t.context.clock = installTimers()
process.env['METRICS_ENABLED'] = 'true'
const config = new AdapterConfig(
{},
Expand Down
5 changes: 3 additions & 2 deletions test/metrics/polling-metrics.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import FakeTimers, { InstalledClock } from '@sinonjs/fake-timers'
import { InstalledClock } from '@sinonjs/fake-timers'
import { installTimers } from '../helper'
import untypedTest, { TestFn } from 'ava'
import { TestAdapter } from '../../src/util/testing-utils'
import { buildHttpAdapter } from './helper'
Expand All @@ -22,7 +23,7 @@ test.before(async (t) => {
const adapter = buildHttpAdapter()

// Start the adapter
t.context.clock = FakeTimers.install()
t.context.clock = installTimers()
t.context.testAdapter = await TestAdapter.startWithMockedCache(adapter, t.context)
})

Expand Down
5 changes: 3 additions & 2 deletions test/metrics/por-metrics.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import FakeTimers, { InstalledClock } from '@sinonjs/fake-timers'
import { InstalledClock } from '@sinonjs/fake-timers'
import { installTimers } from '../helper'
import untypedTest, { TestFn } from 'ava'
import { NopTransport, TestAdapter } from '../../src/util/testing-utils'
import { InputParameters } from '../../src/validation'
Expand Down Expand Up @@ -31,7 +32,7 @@ test.before(async (t) => {
})

// Start the adapter
t.context.clock = FakeTimers.install()
t.context.clock = installTimers()
t.context.testAdapter = await TestAdapter.startWithMockedCache(adapter, t.context)
})

Expand Down
5 changes: 3 additions & 2 deletions test/metrics/warmer-metrics.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import FakeTimers, { InstalledClock } from '@sinonjs/fake-timers'
import { InstalledClock } from '@sinonjs/fake-timers'
import { installTimers } from '../helper'
import untypedTest, { TestFn } from 'ava'
import axios from 'axios'
import MockAdapter from 'axios-mock-adapter'
Expand Down Expand Up @@ -28,7 +29,7 @@ test.before(async (t) => {
const adapter = buildHttpAdapter()

// Start the adapter
t.context.clock = FakeTimers.install()
t.context.clock = installTimers()
t.context.testAdapter = await TestAdapter.startWithMockedCache(adapter, t.context)
})

Expand Down
5 changes: 3 additions & 2 deletions test/metrics/ws-metrics.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import FakeTimers, { InstalledClock } from '@sinonjs/fake-timers'
import { InstalledClock } from '@sinonjs/fake-timers'
import { installTimers } from '../helper'
import untypedTest, { TestFn } from 'ava'
import { Server } from 'mock-socket'
import { Adapter, AdapterEndpoint } from '../../src/adapter'
Expand Down Expand Up @@ -133,7 +134,7 @@ test.before(async (t) => {
socket.on('message', parseMessage)
})

t.context.clock = FakeTimers.install()
t.context.clock = installTimers()
t.context.testAdapter = await TestAdapter.startWithMockedCache(adapter, t.context)
t.context.server = mockWsServer
})
Expand Down
7 changes: 4 additions & 3 deletions test/subscription-set/redis-subscription-set.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import FakeTimers, { InstalledClock } from '@sinonjs/fake-timers'
import { InstalledClock } from '@sinonjs/fake-timers'
import { installTimers } from '../helper'
import untypedTest, { TestFn } from 'ava'
import axios, { AxiosResponse } from 'axios'
import MockAdapter from 'axios-mock-adapter'
Expand Down Expand Up @@ -231,8 +232,8 @@ test.before(async (_) => {
process.env['BACKGROUND_EXECUTE_MS_HTTP'] = '1000'
})

test.beforeEach((t) => {
t.context.clock = FakeTimers.install()
test.before((t) => {
t.context.clock = installTimers()
})

test.afterEach((t) => {
Expand Down
8 changes: 4 additions & 4 deletions test/transports/http.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import FakeTimers, { InstalledClock } from '@sinonjs/fake-timers'
import { InstalledClock } from '@sinonjs/fake-timers'
import { installTimers } from '../helper'
import untypedTest, { TestFn } from 'ava'
import axios, { AxiosResponse } from 'axios'
import MockAdapter from 'axios-mock-adapter'
Expand Down Expand Up @@ -50,13 +51,12 @@ interface ProviderVolumeResponseBody {
}>
}

test.beforeEach((t) => {
t.context.clock = FakeTimers.install()
test.before((t) => {
t.context.clock = installTimers()
})

test.afterEach(async (t) => {
t.context.clock.reset()
t.context.clock.uninstall()
await t.context.testAdapter?.api.close()
})

Expand Down
5 changes: 3 additions & 2 deletions test/transports/sse.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import FakeTimers, { InstalledClock } from '@sinonjs/fake-timers'
import { InstalledClock } from '@sinonjs/fake-timers'
import { installTimers } from '../helper'
import untypedTest, { TestFn } from 'ava'
import axios, { AxiosRequestConfig } from 'axios'
import MockAdapter from 'axios-mock-adapter'
Expand Down Expand Up @@ -151,7 +152,7 @@ const mockHTTP = () => {
}

test('connects to EventSource, subscribes, gets message, unsubscribes and handles misconfigured subscription', async (t) => {
t.context.clock = FakeTimers.install()
t.context.clock = installTimers()

// Mocks SSE events which are handled by the mock EventListener dependency
mockSSE()
Expand Down
9 changes: 5 additions & 4 deletions test/transports/websocket.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import FakeTimers, { InstalledClock } from '@sinonjs/fake-timers'
import { InstalledClock } from '@sinonjs/fake-timers'
import { installTimers } from '../helper'
import untypedTest, { TestFn } from 'ava'
import { Server } from 'mock-socket'
import { Adapter, AdapterEndpoint } from '../../src/adapter'
Expand Down Expand Up @@ -123,12 +124,12 @@ const createAdapter = (envDefaultOverrides: Record<string, string | number | sym
return adapter
}

test.beforeEach((t) => {
t.context.clock = FakeTimers.install()
test.before((t) => {
t.context.clock = installTimers()
})

test.afterEach((t) => {
t.context.clock.uninstall()
t.context.clock.reset()
})

test.serial('connects to websocket, subscribes, gets message, unsubscribes', async (t) => {
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,19 @@
resolved "https://registry.yarnpkg.com/@shikijs/vscode-textmate/-/vscode-textmate-9.3.0.tgz#b2f1776e488c1d6c2b6cd129bab62f71bbc9c7ab"
integrity sha512-jn7/7ky30idSkd/O5yDBfAnVt+JJpepofP/POZ1iMOxK59cOfqIgg/Dj0eFsjOTMw+4ycJN0uhZH/Eb0bs/EUA==

"@sinonjs/commons@^1.7.0":
version "1.8.6"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.8.6.tgz#80c516a4dc264c2a69115e7578d62581ff455ed9"
integrity sha512-Ky+XkAkqPZSm3NLBeUng77EBQl3cmeJhITaGHdYH8kjVB+aun3S4XBRti2zt17mtt0mIUDiNxYeoJm6drVvBJQ==
"@sinonjs/commons@^3.0.1":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-3.0.1.tgz#1029357e44ca901a615585f6d27738dbc89084cd"
integrity sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==
dependencies:
type-detect "4.0.8"

"@sinonjs/fake-timers@9.1.2":
version "9.1.2"
resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-9.1.2.tgz#4eaab737fab77332ab132d396a3c0d364bd0ea8c"
integrity sha512-BPS4ynJW/o92PUR4wgriz2Ud5gpST5vz6GQfMixEDK0Z8ZCUv2M7SkBLykH56T++Xs+8ln9zTGbOvNGIe02/jw==
"@sinonjs/fake-timers@13.0.5":
version "13.0.5"
resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-13.0.5.tgz#36b9dbc21ad5546486ea9173d6bea063eb1717d5"
integrity sha512-36/hTbH2uaWuGVERyC6da9YwGWnzUZXuPro/F2LfsdOsLnCojz/iSH8MxUt/FD2S5XBSVPhmArFUXcpCQ2Hkiw==
dependencies:
"@sinonjs/commons" "^1.7.0"
"@sinonjs/commons" "^3.0.1"

"@tsconfig/node10@^1.0.7":
version "1.0.11"
Expand Down

0 comments on commit 6ed37b7

Please sign in to comment.