Skip to content

Commit dfd80b3

Browse files
committed
test(e2e): make server->client probe deterministic (re-emit until delivered)
1 parent 3155e68 commit dfd80b3

3 files changed

Lines changed: 33 additions & 39 deletions

File tree

e2e/apps/react-cloudflare/tests/cloudflare.spec.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,15 @@ test('cloudflare: server-emitted event reaches the client devtools via the runti
3535
// Activate the Event Probe plugin so its panel (and its server-ping listener) mounts.
3636
await page.getByText('Event Probe', { exact: true }).click()
3737

38-
// Give the client bus a moment to open its WebSocket to the ServerEventBus so the
39-
// broadcast has a live subscriber when the server emit lands.
40-
await page.waitForTimeout(2000)
41-
42-
// Trigger the server route handler, which emits 'server-ping' from the isolated
43-
// server runtime.
44-
await page.request.get('/emit-server-ping')
45-
46-
// The bridged event arrives over the bus; the panel's `on('server-ping')` renders
47-
// the server row.
48-
await expect(page.getByTestId(SELECTORS.probeServerRow)).toBeVisible({
49-
timeout: 15000,
50-
})
38+
// The ServerEventBus does not replay to late joiners, so the client WebSocket must
39+
// already be connected when the emit lands. CI opens the socket slower than a local
40+
// run, so re-emit until the bridged server row appears rather than relying on a fixed
41+
// delay — deterministic and flake-free. Re-emitting yields multiple identical rows
42+
// once connected, hence `.first()`.
43+
await expect(async () => {
44+
await page.request.get('/emit-server-ping')
45+
await expect(
46+
page.getByTestId(SELECTORS.probeServerRow).first(),
47+
).toBeVisible({ timeout: 1000 })
48+
}).toPass({ timeout: 20000 })
5149
})

e2e/apps/react-nitro/tests/nitro.spec.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,15 @@ test('nitro server-emitted event reaches the client devtools via the runtime bri
3030
// Activate the Event Probe plugin so its panel (and its server-ping listener) mounts.
3131
await page.getByText('Event Probe', { exact: true }).click()
3232

33-
// Give the client bus a moment to open its WebSocket to the ServerEventBus so the
34-
// broadcast has a live subscriber when the server emit lands.
35-
await page.waitForTimeout(2000)
36-
37-
// Trigger the server route handler, which emits 'server-ping' from the isolated
38-
// server runtime.
39-
await page.request.get('/emit-server-ping')
40-
41-
// The bridged event arrives over the bus; the panel's `on('server-ping')` renders
42-
// the server row.
43-
await expect(page.getByTestId(SELECTORS.probeServerRow)).toBeVisible({
44-
timeout: 15000,
45-
})
33+
// The ServerEventBus does not replay to late joiners, so the client WebSocket must
34+
// already be connected when the emit lands. CI opens the socket slower than a local
35+
// run, so re-emit until the bridged server row appears rather than relying on a fixed
36+
// delay — deterministic and flake-free. Re-emitting yields multiple identical rows
37+
// once connected, hence `.first()`.
38+
await expect(async () => {
39+
await page.request.get('/emit-server-ping')
40+
await expect(
41+
page.getByTestId(SELECTORS.probeServerRow).first(),
42+
).toBeVisible({ timeout: 1000 })
43+
}).toPass({ timeout: 20000 })
4644
})

e2e/apps/react-start/tests/start.spec.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,15 @@ test('server-emitted event reaches the client devtools via the runtime bridge',
2828
// Activate the Event Probe plugin so its panel (and its server-ping listener) mounts.
2929
await page.getByText('Event Probe', { exact: true }).click()
3030

31-
// Give the client bus a moment to open its WebSocket to the ServerEventBus so the
32-
// broadcast has a live subscriber when the server emit lands.
33-
await page.waitForTimeout(2000)
34-
35-
// Trigger the server route handler, which emits 'server-ping' from the isolated
36-
// server runtime.
37-
await page.request.get('/emit-server-ping')
38-
39-
// The bridged event arrives over the bus; the panel's `on('server-ping')` renders
40-
// the server row.
41-
await expect(page.getByTestId(SELECTORS.probeServerRow)).toBeVisible({
42-
timeout: 15000,
43-
})
31+
// The ServerEventBus does not replay to late joiners, so the client WebSocket must
32+
// already be connected when the emit lands. CI opens the socket slower than a local
33+
// run, so re-emit until the bridged server row appears rather than relying on a fixed
34+
// delay — deterministic and flake-free. Re-emitting yields multiple identical rows
35+
// once connected, hence `.first()`.
36+
await expect(async () => {
37+
await page.request.get('/emit-server-ping')
38+
await expect(
39+
page.getByTestId(SELECTORS.probeServerRow).first(),
40+
).toBeVisible({ timeout: 1000 })
41+
}).toPass({ timeout: 20000 })
4442
})

0 commit comments

Comments
 (0)