Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make createPlayer have a small delay #98

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions features/support/steps/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ After(async function (this: World) {
})

Given('{string} is connected and ready for game {string}', async function (this: World, playerName: string, gameID: string) {
const player = this.createPlayer(playerName, gameID)
const player = await this.createPlayer(playerName, gameID)
const event = await player.waitForEvent('ready')
if (event == null) {
throw new Error(`unable to add player ${playerName} to network`)
Expand Down Expand Up @@ -96,8 +96,8 @@ Given('these lobbies exist:', async function (this: World, lobbies: DataTable) {
})
})

When('{string} creates a network for game {string}', function (this: World, playerName: string, gameID: string) {
this.createPlayer(playerName, gameID)
When('{string} creates a network for game {string}', async function (this: World, playerName: string, gameID: string) {
await this.createPlayer(playerName, gameID)
})

When('{string} creates a lobby', function (this: World, playerName: string) {
Expand Down
19 changes: 13 additions & 6 deletions features/support/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,19 @@ export class World extends CucumberWorld {
}
}

public createPlayer (playerName: string, gameID: string): Player {
const config = this.useTestProxy ? { testproxyURL: this.testproxyURL } : undefined
const network = new Network(gameID, config, this.signalingURL)
const player = new Player(playerName, network)
this.players.set(playerName, player)
return player
public async createPlayer (playerName: string, gameID: string): Promise<Player> {
return await new Promise((resolve) => {
const config = this.useTestProxy ? { testproxyURL: this.testproxyURL } : undefined
const network = new Network(gameID, config, this.signalingURL)
const player = new Player(playerName, network)
this.players.set(playerName, player)

// Give the Network some time to connect to the signaling server.
// Giving this some time makes our test less flaky.
setTimeout(() => {
resolve(player)
}, 50)
})
}
}
setWorldConstructor(World)
Expand Down