Skip to content

Commit e5396ce

Browse files
committed
chore: make test wait for peer ids
1 parent 638cc46 commit e5396ce

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

examples/js-libp2p-example-browser-pubsub/test/index.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const output = '#output'
2020
const listeningAddresses = '#listening-addresses'
2121
const subscribeInput = '#subscribe-topic-input'
2222
const subscribeBtn = '#subscribe-topic-button'
23+
const topicPeers = '#topic-peers'
24+
const peerId = '#peer-id'
2325

2426
let url
2527

@@ -73,6 +75,10 @@ test.describe('pubsub browser example:', () => {
7375
const pageB = await context.newPage()
7476
await pageB.goto(url)
7577

78+
// load page peer ids
79+
const pageAPeerId = await pageA.textContent(peerId)
80+
const pageBPeerId = await pageB.textContent(peerId)
81+
7682
// connect the first page to the relay
7783
const webRTCAddressA = await dialRelay(pageA, relayNodeAddr)
7884

@@ -88,6 +94,10 @@ test.describe('pubsub browser example:', () => {
8894
await subscribeToTopic(pageA, topicName)
8995
await subscribeToTopic(pageB, topicName)
9096

97+
// wait for peers to appear in topic peers
98+
await waitForTopicPeers(pageA, pageBPeerId)
99+
await waitForTopicPeers(pageB, pageAPeerId)
100+
91101
// send a message from one to the other
92102
await sendMessage(pageA, 'hello A', pageB)
93103
})
@@ -103,6 +113,11 @@ async function subscribeToTopic (page, topic) {
103113
await expect(outputLocator).toContainText(`Subscribing to '${topic}'`)
104114
}
105115

116+
async function waitForTopicPeers (page, otherPeer) {
117+
const outputLocator = page.locator(topicPeers)
118+
await expect(outputLocator).toContainText(otherPeer)
119+
}
120+
106121
async function sendMessage (pageA, message, pageB) {
107122
// subscribe to the topic
108123
await pageA.fill(sendMessageInput, message)

0 commit comments

Comments
 (0)