Skip to content

Commit 14aa40f

Browse files
MarcoPoloachingbrainmaschad
authored
test: Add webkit test script (#1627)
Runs test suite on webkit along with other browsers --------- Co-authored-by: Alex Potsides <[email protected]> Co-authored-by: chad <[email protected]>
1 parent 8e5df6f commit 14aa40f

File tree

5 files changed

+46
-22
lines changed

5 files changed

+46
-22
lines changed

.github/workflows/main.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@ jobs:
100100
directory: ./.nyc_output
101101
flags: firefox-webworker
102102

103+
test-webkit:
104+
needs: check
105+
runs-on: ubuntu-latest
106+
steps:
107+
- uses: actions/checkout@v3
108+
- uses: actions/setup-node@v3
109+
with:
110+
node-version: lts/*
111+
- uses: ipfs/aegir/actions/cache-node-modules@master
112+
- run: npx playwright install-deps
113+
- run: npm run --if-present test:webkit
114+
- uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0
115+
with:
116+
directory: ./.nyc_output
117+
flags: webkit
118+
103119
test-electron-main:
104120
needs: check
105121
runs-on: ubuntu-latest

examples/libp2p-in-the-browser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"license": "ISC",
1111
"dependencies": {
12-
"@chainsafe/libp2p-gossipsub": "^7.0.0",
12+
"@chainsafe/libp2p-gossipsub": "^8.0.0",
1313
"@chainsafe/libp2p-noise": "^12.0.0",
1414
"@chainsafe/libp2p-yamux": "^4.0.1",
1515
"@libp2p/bootstrap": "^8.0.0",

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,13 @@
115115
"test:chrome-webworker": "aegir test -t webworker -f \"./dist/test/**/*.spec.js\"",
116116
"test:firefox": "aegir test -t browser -f \"./dist/test/**/*.spec.js\" -- --browser firefox",
117117
"test:firefox-webworker": "aegir test -t webworker -f \"./dist/test/**/*.spec.js\" -- --browser firefox",
118+
"test:webkit": "aegir test -t browser -f \"./dist/test/**/*.spec.js\" -- --browser webkit",
118119
"test:examples": "cd examples && npm run test:all",
119120
"test:interop": "aegir test -t node -f dist/test/interop.js"
120121
},
121122
"dependencies": {
122123
"@achingbrain/nat-port-mapper": "^1.0.3",
123-
"@libp2p/crypto": "^1.0.4",
124+
"@libp2p/crypto": "^1.0.17",
124125
"@libp2p/interface-address-manager": "^3.0.0",
125126
"@libp2p/interface-connection": "^5.0.0",
126127
"@libp2p/interface-connection-encrypter": "^4.0.0",
@@ -142,7 +143,7 @@
142143
"@libp2p/interface-transport": "^4.0.0",
143144
"@libp2p/interfaces": "^3.2.0",
144145
"@libp2p/keychain": "^2.0.0",
145-
"@libp2p/logger": "^2.0.1",
146+
"@libp2p/logger": "^2.1.1",
146147
"@libp2p/multistream-select": "^3.1.8",
147148
"@libp2p/peer-collections": "^3.0.0",
148149
"@libp2p/peer-id": "^2.0.0",

src/autonat/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ class DefaultAutoNATService implements Startable {
508508
// they either told us which address worked/didn't work, or we only sent them one address
509509
const addr = dialResponse.addr == null ? multiaddrs[0] : multiaddr(dialResponse.addr)
510510

511-
log('autonat response for %s is %s', addr, dialResponse.status)
511+
log('autonat response for %a is %s', addr, dialResponse.status)
512512

513513
if (dialResponse.status === Message.ResponseStatus.E_BAD_REQUEST) {
514514
// the remote could not parse our request
@@ -526,7 +526,7 @@ class DefaultAutoNATService implements Startable {
526526
}
527527

528528
if (!multiaddrs.some(ma => ma.equals(addr))) {
529-
log('peer reported %s as %s but it was not in our observed address list', addr, dialResponse.status)
529+
log('peer reported %a as %s but it was not in our observed address list', addr, dialResponse.status)
530530
continue
531531
}
532532

@@ -544,14 +544,14 @@ class DefaultAutoNATService implements Startable {
544544

545545
if (results[addrStr].success === REQUIRED_SUCCESSFUL_DIALS) {
546546
// we are now convinced
547-
log('%s is externally dialable', addr)
547+
log('%a is externally dialable', addr)
548548
addressManager.confirmObservedAddr(addr)
549549
return
550550
}
551551

552552
if (results[addrStr].failure === REQUIRED_SUCCESSFUL_DIALS) {
553553
// we are now unconvinced
554-
log('%s is not externally dialable', addr)
554+
log('%a is not externally dialable', addr)
555555
addressManager.removeObservedAddr(addr)
556556
return
557557
}

test/autonat/index.spec.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33

44
import { start, stop } from '@libp2p/interfaces/startable'
55
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
6-
import { type Multiaddr, multiaddr } from '@multiformats/multiaddr'
6+
import { multiaddr } from '@multiformats/multiaddr'
77
import { expect } from 'aegir/chai'
88
import all from 'it-all'
99
import * as lp from 'it-length-prefixed'
1010
import { pipe } from 'it-pipe'
1111
import { pushable } from 'it-pushable'
1212
import sinon from 'sinon'
13-
import { type StubbedInstance, stubInterface } from 'sinon-ts'
13+
import { stubInterface } from 'sinon-ts'
1414
import { Uint8ArrayList } from 'uint8arraylist'
1515
import { PROTOCOL_NAME, PROTOCOL_PREFIX, PROTOCOL_VERSION } from '../../src/autonat/constants.js'
16-
import { autoNATService, type AutoNATServiceInit } from '../../src/autonat/index.js'
16+
import { autoNATService } from '../../src/autonat/index.js'
1717
import { Message } from '../../src/autonat/pb/index.js'
18-
import { type Components, defaultComponents } from '../../src/components.js'
18+
import { defaultComponents } from '../../src/components.js'
19+
import type { AutoNATServiceInit } from '../../src/autonat/index.js'
20+
import type { Components } from '../../src/components.js'
1921
import type { DefaultConnectionManager } from '../../src/connection-manager/index.js'
2022
import type { AddressManager } from '@libp2p/interface-address-manager'
2123
import type { Connection, Stream } from '@libp2p/interface-connection'
@@ -25,6 +27,8 @@ import type { PeerRouting } from '@libp2p/interface-peer-routing'
2527
import type { PeerStore } from '@libp2p/interface-peer-store'
2628
import type { Registrar } from '@libp2p/interface-registrar'
2729
import type { Transport, TransportManager } from '@libp2p/interface-transport'
30+
import type { Multiaddr } from '@multiformats/multiaddr'
31+
import type { StubbedInstance } from 'sinon-ts'
2832

2933
const defaultInit: AutoNATServiceInit = {
3034
protocolPrefix: 'libp2p',
@@ -92,19 +96,22 @@ describe('autonat', () => {
9296
connection.remoteAddr = multiaddr(`/ip4/${host}/tcp/28319/p2p/${peer.id.toString()}`)
9397
connectionManager.openConnection.withArgs(peer.id).resolves(connection)
9498

95-
// stub autonat protocol stream
96-
const stream = stubInterface<Stream>()
97-
connection.newStream.withArgs(`/${PROTOCOL_PREFIX}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`).resolves(stream)
99+
connection.newStream.withArgs(`/${PROTOCOL_PREFIX}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`).callsFake(async () => {
100+
// stub autonat protocol stream
101+
const stream = stubInterface<Stream>()
98102

99-
// stub autonat response
100-
const response = Message.encode({
101-
type: Message.MessageType.DIAL_RESPONSE,
102-
dialResponse
103+
// stub autonat response
104+
const response = Message.encode({
105+
type: Message.MessageType.DIAL_RESPONSE,
106+
dialResponse
107+
})
108+
stream.source = (async function * () {
109+
yield lp.encode.single(response)
110+
}())
111+
stream.sink.returns(Promise.resolve())
112+
113+
return stream
103114
})
104-
stream.source = (async function * () {
105-
yield lp.encode.single(response)
106-
}())
107-
stream.sink.returns(Promise.resolve())
108115

109116
return peer
110117
}

0 commit comments

Comments
 (0)