Skip to content

Commit 24ff6e9

Browse files
authored
deps(dev): update sinon-ts to 2.x.x (#2186)
Updates sinon-ts to 2.x
1 parent 346ff5a commit 24ff6e9

File tree

8 files changed

+33
-32
lines changed

8 files changed

+33
-32
lines changed

packages/interface/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,6 @@
177177
"it-all": "^3.0.3",
178178
"it-drain": "^3.0.3",
179179
"sinon": "^17.0.0",
180-
"sinon-ts": "^1.0.0"
180+
"sinon-ts": "^2.0.0"
181181
}
182182
}

packages/libp2p/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@
193193
"p-wait-for": "^5.0.2",
194194
"protons": "^7.0.2",
195195
"sinon": "^17.0.0",
196-
"sinon-ts": "^1.0.0"
196+
"sinon-ts": "^2.0.0"
197197
},
198198
"browser": {
199199
"./dist/src/connection-manager/constants.js": "./dist/src/connection-manager/constants.browser.js",

packages/libp2p/test/addresses/address-manager.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { createEd25519PeerId } from '@libp2p/peer-id-factory'
55
import { multiaddr } from '@multiformats/multiaddr'
66
import { expect } from 'aegir/chai'
77
import delay from 'delay'
8+
import Sinon from 'sinon'
89
import { type StubbedInstance, stubInterface } from 'sinon-ts'
910
import { type AddressFilter, DefaultAddressManager } from '../../src/address-manager/index.js'
1011
import type { Libp2pEvents } from '@libp2p/interface'
@@ -23,8 +24,7 @@ describe('Address Manager', () => {
2324
beforeEach(async () => {
2425
peerId = await createEd25519PeerId()
2526
peerStore = stubInterface<PeerStore>({
26-
// @ts-expect-error incorrect return type
27-
patch: Promise.resolve({})
27+
patch: Sinon.stub().resolves({})
2828
})
2929
events = new TypedEventEmitter()
3030
})
@@ -147,7 +147,7 @@ describe('Address Manager', () => {
147147
const am = new DefaultAddressManager({
148148
peerId,
149149
transportManager: stubInterface<TransportManager>({
150-
getAddrs: []
150+
getAddrs: Sinon.stub().returns([])
151151
}),
152152
peerStore,
153153
events

packages/libp2p/test/connection-manager/auto-dial.spec.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ describe('auto-dial', () => {
6969
await peerStore.save(peerWithoutAddress.id, peerWithoutAddress)
7070

7171
const connectionManager = stubInterface<ConnectionManager>({
72-
getConnectionsMap: new PeerMap(),
73-
getDialQueue: []
72+
getConnectionsMap: Sinon.stub().returns(new PeerMap()),
73+
getDialQueue: Sinon.stub().returns([])
7474
})
7575

7676
autoDialler = new AutoDial({
@@ -123,8 +123,8 @@ describe('auto-dial', () => {
123123
connectionMap.set(connectedPeer.id, [stubInterface<Connection>()])
124124

125125
const connectionManager = stubInterface<ConnectionManager>({
126-
getConnectionsMap: connectionMap,
127-
getDialQueue: []
126+
getConnectionsMap: Sinon.stub().returns(connectionMap),
127+
getDialQueue: Sinon.stub().returns([])
128128
})
129129

130130
autoDialler = new AutoDial({
@@ -172,13 +172,13 @@ describe('auto-dial', () => {
172172
await peerStore.save(peerNotInDialQueue.id, peerNotInDialQueue)
173173

174174
const connectionManager = stubInterface<ConnectionManager>({
175-
getConnectionsMap: new PeerMap(),
176-
getDialQueue: [{
175+
getConnectionsMap: Sinon.stub().returns(new PeerMap()),
176+
getDialQueue: Sinon.stub().returns([{
177177
id: 'foo',
178178
peerId: peerInDialQueue.id,
179179
multiaddrs: [],
180180
status: 'queued'
181-
}]
181+
}])
182182
})
183183

184184
autoDialler = new AutoDial({
@@ -203,8 +203,8 @@ describe('auto-dial', () => {
203203
const peerStoreAllSpy = Sinon.spy(peerStore, 'all')
204204

205205
const connectionManager = stubInterface<ConnectionManager>({
206-
getConnectionsMap: new PeerMap(),
207-
getDialQueue: []
206+
getConnectionsMap: Sinon.stub().returns(new PeerMap()),
207+
getDialQueue: Sinon.stub().returns([])
208208
})
209209

210210
autoDialler = new AutoDial({
@@ -254,8 +254,8 @@ describe('auto-dial', () => {
254254
await peerStore.save(undialablePeer.id, undialablePeer)
255255

256256
const connectionManager = stubInterface<ConnectionManager>({
257-
getConnectionsMap: new PeerMap(),
258-
getDialQueue: []
257+
getConnectionsMap: Sinon.stub().returns(new PeerMap()),
258+
getDialQueue: Sinon.stub().returns([])
259259
})
260260

261261
autoDialler = new AutoDial({

packages/libp2p/test/connection-manager/direct.node.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { pipe } from 'it-pipe'
2222
import { pushable } from 'it-pushable'
2323
import pDefer from 'p-defer'
2424
import pWaitFor from 'p-wait-for'
25-
import sinon from 'sinon'
25+
import Sinon from 'sinon'
2626
import { stubInterface } from 'sinon-ts'
2727
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
2828
import { DefaultAddressManager } from '../../src/address-manager/index.js'
@@ -49,10 +49,10 @@ describe('dialing (direct, TCP)', () => {
4949
let remoteAddr: Multiaddr
5050
let remoteComponents: Components
5151
let localComponents: Components
52-
let resolver: sinon.SinonStub<[Multiaddr], Promise<string[]>>
52+
let resolver: Sinon.SinonStub<[Multiaddr], Promise<string[]>>
5353

5454
beforeEach(async () => {
55-
resolver = sinon.stub<[Multiaddr], Promise<string[]>>()
55+
resolver = Sinon.stub<[Multiaddr], Promise<string[]>>()
5656
const [localPeerId, remotePeerId] = await Promise.all([
5757
createEd25519PeerId(),
5858
createEd25519PeerId()
@@ -66,7 +66,7 @@ describe('dialing (direct, TCP)', () => {
6666
upgrader: mockUpgrader({ events: remoteEvents }),
6767
connectionGater: mockConnectionGater(),
6868
transportManager: stubInterface<TransportManager>({
69-
getAddrs: []
69+
getAddrs: Sinon.stub().returns([])
7070
})
7171
})
7272
remoteComponents.peerStore = new PersistentPeerStore(remoteComponents)
@@ -109,7 +109,7 @@ describe('dialing (direct, TCP)', () => {
109109
})
110110

111111
afterEach(() => {
112-
sinon.restore()
112+
Sinon.restore()
113113
})
114114

115115
it('should be able to connect to a remote node via its multiaddr', async () => {
@@ -194,7 +194,7 @@ describe('dialing (direct, TCP)', () => {
194194

195195
const dialer = new DialQueue(localComponents)
196196

197-
sinon.spy(localTM, 'dial')
197+
Sinon.spy(localTM, 'dial')
198198
const connection = await dialer.dial(peerId)
199199
expect(localTM.dial).to.have.property('callCount', remoteAddrs.length)
200200
expect(connection).to.exist()
@@ -207,7 +207,7 @@ describe('dialing (direct, TCP)', () => {
207207
dialTimeout: 50
208208
})
209209

210-
sinon.stub(localTM, 'dial').callsFake(async (addr, options = {}) => {
210+
Sinon.stub(localTM, 'dial').callsFake(async (addr, options = {}) => {
211211
expect(options.signal).to.exist()
212212
expect(options.signal?.aborted).to.equal(false)
213213
expect(addr.toString()).to.eql(remoteAddr.toString())
@@ -235,7 +235,7 @@ describe('dialing (direct, TCP)', () => {
235235
})
236236

237237
const deferredDial = pDefer<Connection>()
238-
const transportManagerDialStub = sinon.stub(localTM, 'dial')
238+
const transportManagerDialStub = Sinon.stub(localTM, 'dial')
239239
transportManagerDialStub.callsFake(async () => deferredDial.promise)
240240

241241
// Perform 3 multiaddr dials
@@ -273,7 +273,7 @@ describe('dialing (direct, TCP)', () => {
273273
maxParallelDialsPerPeer: 10
274274
})
275275

276-
const transportManagerDialStub = sinon.stub(localTM, 'dial')
276+
const transportManagerDialStub = Sinon.stub(localTM, 'dial')
277277
transportManagerDialStub.callsFake(async (ma) => {
278278
await delay(10)
279279
return mockConnection(mockMultiaddrConnection(mockDuplex(), remoteComponents.peerId))
@@ -340,7 +340,7 @@ describe('libp2p.dialer (direct, TCP)', () => {
340340
})
341341

342342
afterEach(async () => {
343-
sinon.restore()
343+
Sinon.restore()
344344

345345
if (libp2p != null) {
346346
await libp2p.stop()
@@ -515,7 +515,7 @@ describe('libp2p.dialer (direct, TCP)', () => {
515515
connectionProtector: () => protector
516516
})
517517

518-
const protectorProtectSpy = sinon.spy(protector, 'protect')
518+
const protectorProtectSpy = Sinon.spy(protector, 'protect')
519519

520520
remoteLibp2p.components.connectionProtector = preSharedKey({ psk: swarmKeyBuffer })()
521521

@@ -589,7 +589,7 @@ describe('libp2p.dialer (direct, TCP)', () => {
589589

590590
const dials = 10
591591
const error = new Error('Boom')
592-
sinon.stub(libp2p.components.transportManager, 'dial').callsFake(async () => Promise.reject(error))
592+
Sinon.stub(libp2p.components.transportManager, 'dial').callsFake(async () => Promise.reject(error))
593593

594594
await libp2p.peerStore.patch(remotePeerId, {
595595
multiaddrs: remoteLibp2p.getMultiaddrs()

packages/peer-discovery-bootstrap/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@
5858
"devDependencies": {
5959
"@libp2p/interface-compliance-tests": "^4.1.2",
6060
"aegir": "^41.0.2",
61-
"sinon-ts": "^1.0.0"
61+
"sinon-ts": "^2.0.0"
6262
}
6363
}

packages/transport-webrtc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"p-retry": "^6.1.0",
9090
"protons": "^7.0.2",
9191
"sinon": "^17.0.0",
92-
"sinon-ts": "^1.0.0"
92+
"sinon-ts": "^2.0.0"
9393
},
9494
"browser": {
9595
"./dist/src/webrtc/index.js": "./dist/src/webrtc/index.browser.js"

packages/transport-webrtc/test/listener.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
22
import { multiaddr } from '@multiformats/multiaddr'
33
import { expect } from 'aegir/chai'
4+
import Sinon from 'sinon'
45
import { stubInterface } from 'sinon-ts'
56
import { WebRTCPeerListener } from '../src/private-to-private/listener.js'
67
import type { Listener } from '@libp2p/interface/transport'
@@ -21,11 +22,11 @@ describe('webrtc private-to-private listener', () => {
2122
})
2223

2324
const otherListener = stubInterface<Listener>({
24-
getAddrs: [multiaddr(otherListenAddress)]
25+
getAddrs: Sinon.stub().returns([multiaddr(otherListenAddress)])
2526
})
2627

2728
const relayListener = stubInterface<Listener>({
28-
getAddrs: [multiaddr(relayedAddress)]
29+
getAddrs: Sinon.stub().returns([multiaddr(relayedAddress)])
2930
})
3031

3132
transportManager.getListeners.returns([

0 commit comments

Comments
 (0)