@@ -44,23 +44,19 @@ test('returns the number of active clients in the same runtime', async ({
4444 } )
4545
4646 // Must return 1 after a single client joined.
47- expect (
48- await page . evaluate ( ( ) => {
49- return window . link . clients . size
50- } ) ,
51- ) . toBe ( 1 )
47+ await expect (
48+ page . waitForFunction ( ( ) => window . link . clients . size === 1 ) ,
49+ ) . resolves . toBeTruthy ( )
5250
5351 await page . evaluate ( async ( ) => {
5452 const ws = new WebSocket ( 'wss://example.com' )
5553 await new Promise ( ( done ) => ( ws . onopen = done ) )
5654 } )
5755
5856 // Must return 2 now that another client has joined.
59- expect (
60- await page . evaluate ( ( ) => {
61- return window . link . clients . size
62- } ) ,
63- ) . toBe ( 2 )
57+ await expect (
58+ page . waitForFunction ( ( ) => window . link . clients . size === 2 ) ,
59+ ) . resolves . toBeTruthy ( )
6460} )
6561
6662test ( 'returns the number of active clients across different runtimes' , async ( {
@@ -94,17 +90,25 @@ test('returns the number of active clients across different runtimes', async ({
9490 await new Promise ( ( done ) => ( ws . onopen = done ) )
9591 } )
9692
97- expect ( await pageOne . evaluate ( ( ) => window . link . clients . size ) ) . toBe ( 1 )
98- expect ( await pageTwo . evaluate ( ( ) => window . link . clients . size ) ) . toBe ( 1 )
93+ await expect (
94+ pageOne . waitForFunction ( ( ) => window . link . clients . size === 1 ) ,
95+ ) . resolves . toBeTruthy ( )
96+ await expect (
97+ pageTwo . waitForFunction ( ( ) => window . link . clients . size === 1 ) ,
98+ ) . resolves . toBeTruthy ( )
9999
100100 await pageTwo . bringToFront ( )
101101 await pageTwo . evaluate ( async ( ) => {
102102 const ws = new WebSocket ( 'wss://example.com' )
103103 await new Promise ( ( done ) => ( ws . onopen = done ) )
104104 } )
105105
106- expect ( await pageTwo . evaluate ( ( ) => window . link . clients . size ) ) . toBe ( 2 )
107- expect ( await pageOne . evaluate ( ( ) => window . link . clients . size ) ) . toBe ( 2 )
106+ await expect (
107+ pageTwo . waitForFunction ( ( ) => window . link . clients . size === 2 ) ,
108+ ) . resolves . toBeTruthy ( )
109+ await expect (
110+ pageOne . waitForFunction ( ( ) => window . link . clients . size === 2 ) ,
111+ ) . resolves . toBeTruthy ( )
108112} )
109113
110114test ( 'broadcasts messages across runtimes' , async ( {
@@ -198,7 +202,9 @@ test('clears the list of clients when the worker is stopped', async ({
198202 } )
199203
200204 // Must return the number of joined clients.
201- expect ( await page . evaluate ( ( ) => window . link . clients . size ) ) . toBe ( 1 )
205+ await expect (
206+ page . waitForFunction ( ( ) => window . link . clients . size === 1 ) ,
207+ ) . resolves . toBeTruthy ( )
202208
203209 await page . evaluate ( ( ) => {
204210 window . worker . stop ( )
@@ -239,7 +245,9 @@ test('clears the list of clients when the page is reloaded', async ({
239245 } )
240246
241247 // Must return the number of joined clients.
242- expect ( await page . evaluate ( ( ) => window . link . clients . size ) ) . toBe ( 1 )
248+ await expect (
249+ page . waitForFunction ( ( ) => window . link . clients . size === 1 ) ,
250+ ) . resolves . toBeTruthy ( )
243251
244252 await page . reload ( )
245253 await enableMocking ( )
0 commit comments