Skip to content

Commit 3461dfb

Browse files
committed
chore: linting and tests
1 parent c137b96 commit 3461dfb

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

packages/transport-webrtc/src/private-to-public/transport.browser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { serviceCapabilities, transportSymbol } from '@libp2p/interface'
22
import { peerIdFromString } from '@libp2p/peer-id'
33
import { CODE_P2P } from '@multiformats/multiaddr'
44
import { WebRTCDirect } from '@multiformats/multiaddr-matcher'
5+
import { UnimplementedError } from '../error.ts'
56
import { genUfrag } from '../util.js'
67
import { connect } from './utils/connect.js'
78
import { createDialerRTCPeerConnection } from './utils/get-rtcpeerconnection.js'
@@ -12,7 +13,6 @@ import type { TransportManager } from '@libp2p/interface-internal'
1213
import type { Keychain } from '@libp2p/keychain'
1314
import type { Multiaddr } from '@multiformats/multiaddr'
1415
import type { Datastore } from 'interface-datastore'
15-
import { UnimplementedError } from '../error.ts'
1616

1717
export interface WebRTCDirectTransportComponents {
1818
peerId: PeerId

packages/transport-webrtc/src/private-to-public/transport.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
1010
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
1111
import { DEFAULT_CERTIFICATE_DATASTORE_KEY, DEFAULT_CERTIFICATE_LIFESPAN, DEFAULT_CERTIFICATE_PRIVATE_KEY_NAME, DEFAULT_CERTIFICATE_RENEWAL_THRESHOLD } from '../constants.js'
1212
import { WebRTCDirectListener } from './listener.js'
13+
import { WebRTCDirectTransport as WebRTCDirectBrowserTransport } from './transport.browser.js'
1314
import { formatAsPem } from './utils/pem.js'
1415
import type { TransportCertificate } from '../index.js'
16+
import type { WebRTCTransportDirectInit as WebRTCTransportDirectBrowserInit, WebRTCMetrics, WebRTCDirectTransportComponents } from './transport.browser.ts'
1517
import type { CreateListenerOptions, Transport, Listener, PrivateKey, Startable } from '@libp2p/interface'
1618
import type { Keychain } from '@libp2p/keychain'
1719
import type { Multiaddr } from '@multiformats/multiaddr'
1820
import type { TypedEventTarget } from 'main-event'
19-
import { WebRTCDirectTransport as WebRTCDirectBrowserTransport } from './transport.browser.js'
20-
import type { WebRTCTransportDirectInit as WebRTCTransportDirectBrowserInit, WebRTCMetrics, WebRTCDirectTransportComponents } from './transport.browser.ts'
2121

2222
export type { WebRTCMetrics, WebRTCDirectTransportComponents }
2323

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

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ function assertAllMultiaddrsHaveSamePort (addrs: Multiaddr[]): void {
3232
}
3333
}
3434

35+
const LISTEN_SUPPORTED = isNode || isElectronMain
36+
3537
describe('WebRTCDirect Transport', () => {
3638
let components: WebRTCDirectTransportComponents
3739
let listener: Listener
@@ -68,9 +70,11 @@ describe('WebRTCDirect Transport', () => {
6870

6971
await start(transport)
7072

71-
listener = transport.createListener({
72-
upgrader
73-
})
73+
if (LISTEN_SUPPORTED) {
74+
listener = transport.createListener({
75+
upgrader
76+
})
77+
}
7478
})
7579

7680
afterEach(async () => {
@@ -102,14 +106,21 @@ describe('WebRTCDirect Transport', () => {
102106
multiaddr('/ip4/1.2.3.4/udp/1234/certhash/uEiAUqV7kzvM1wI5DYDc1RbcekYVmXli_Qprlw3IkiEg6tQ/p2p/12D3KooWGDMwwqrpcYKpKCgxuKT2NfqPqa94QnkoBBpqvCaiCzWd')
103107
]
104108

105-
expect(transport.listenFilter([
106-
...valid,
107-
...invalid
108-
])).to.deep.equal(valid)
109+
if (LISTEN_SUPPORTED) {
110+
expect(transport.listenFilter([
111+
...valid,
112+
...invalid
113+
])).to.deep.equal(valid)
114+
} else {
115+
expect(transport.listenFilter([
116+
...valid,
117+
...invalid
118+
])).to.be.empty()
119+
}
109120
})
110121

111122
it('can listen on ipv4 and ipv6 on the same port in series', async function () {
112-
if ((!isNode && !isElectronMain) || !supportsIpV6()) {
123+
if (!LISTEN_SUPPORTED || !supportsIpV6()) {
113124
return this.skip()
114125
}
115126

@@ -125,7 +136,7 @@ describe('WebRTCDirect Transport', () => {
125136
})
126137

127138
it('can listen on ipv4 and ipv6 on the same port in parallel', async function () {
128-
if ((!isNode && !isElectronMain) || !supportsIpV6()) {
139+
if (!LISTEN_SUPPORTED || !supportsIpV6()) {
129140
return this.skip()
130141
}
131142

@@ -143,7 +154,7 @@ describe('WebRTCDirect Transport', () => {
143154
})
144155

145156
it('can listen on wildcard IPv4 hosts', async function () {
146-
if ((!isNode && !isElectronMain) || !supportsIpV6()) {
157+
if (!LISTEN_SUPPORTED || !supportsIpV6()) {
147158
return this.skip()
148159
}
149160

@@ -168,7 +179,7 @@ describe('WebRTCDirect Transport', () => {
168179
})
169180

170181
it('can listen on wildcard IPv6 hosts', async function () {
171-
if ((!isNode && !isElectronMain) || !supportsIpV6()) {
182+
if (!LISTEN_SUPPORTED || !supportsIpV6()) {
172183
return this.skip()
173184
}
174185

@@ -193,7 +204,7 @@ describe('WebRTCDirect Transport', () => {
193204
})
194205

195206
it('should add certificate to announce addresses', async function () {
196-
if ((!isNode && !isElectronMain) || !supportsIpV6()) {
207+
if (!LISTEN_SUPPORTED || !supportsIpV6()) {
197208
return this.skip()
198209
}
199210

@@ -225,7 +236,7 @@ describe('WebRTCDirect Transport', () => {
225236
})
226237

227238
it('can start listeners for two nodes on wildcard socket addresses', async function () {
228-
if ((!isNode && !isElectronMain) || !supportsIpV6()) {
239+
if (!LISTEN_SUPPORTED || !supportsIpV6()) {
229240
return this.skip()
230241
}
231242

@@ -268,7 +279,7 @@ describe('WebRTCDirect Transport', () => {
268279
})
269280

270281
it('can start multiple wildcard listeners', async function () {
271-
if ((!isNode && !isElectronMain) || !supportsIpV6()) {
282+
if (!LISTEN_SUPPORTED || !supportsIpV6()) {
272283
return this.skip()
273284
}
274285

0 commit comments

Comments
 (0)