Skip to content

Commit

Permalink
chore: make test wait for peer ids
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Oct 31, 2023
1 parent 638cc46 commit e5396ce
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions examples/js-libp2p-example-browser-pubsub/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const output = '#output'
const listeningAddresses = '#listening-addresses'
const subscribeInput = '#subscribe-topic-input'
const subscribeBtn = '#subscribe-topic-button'
const topicPeers = '#topic-peers'
const peerId = '#peer-id'

let url

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

// load page peer ids
const pageAPeerId = await pageA.textContent(peerId)
const pageBPeerId = await pageB.textContent(peerId)

// connect the first page to the relay
const webRTCAddressA = await dialRelay(pageA, relayNodeAddr)

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

// wait for peers to appear in topic peers
await waitForTopicPeers(pageA, pageBPeerId)
await waitForTopicPeers(pageB, pageAPeerId)

// send a message from one to the other
await sendMessage(pageA, 'hello A', pageB)
})
Expand All @@ -103,6 +113,11 @@ async function subscribeToTopic (page, topic) {
await expect(outputLocator).toContainText(`Subscribing to '${topic}'`)
}

async function waitForTopicPeers (page, otherPeer) {
const outputLocator = page.locator(topicPeers)
await expect(outputLocator).toContainText(otherPeer)
}

async function sendMessage (pageA, message, pageB) {
// subscribe to the topic
await pageA.fill(sendMessageInput, message)
Expand Down

0 comments on commit e5396ce

Please sign in to comment.