Skip to content
Source
Sign inSign up
TanStack/devtools
Open History to see the last commit

cloudflare.spec.ts

49 lines2.2 KB

1import { test, expect } from '@playwright/test'
2import { DevtoolsPage, SELECTORS } from '@tanstack/devtools-e2e'
3​
4test('cloudflare: devtools mount under SSR and demo plugin renders', async ({
5 page,
6}) => {
7 const dt = new DevtoolsPage(page)
8 await dt.goto()
9 await dt.openViaTrigger()
10 await expect(page.getByTestId('demo-plugin')).toBeVisible()
11})
12​
13// Server->client delivery: a GET to /emit-server-ping runs a TanStack Start server
14// route handler inside Cloudflare's workerd dev environment. PR #384's runtime bridge
15// (packages/devtools-vite/src/runtime-bridge.ts) gives non-client Vite environments a
16// real `globalThis.__TANSTACK_EVENT_TARGET__` and bridges it to the Vite dev process
17// over the environment's `import.meta.hot` HotChannel, so the server-side
18// EventClient.emit() reaches the ServerEventBus and is broadcast to all connected
19// browser clients. A visible server row therefore proves the server->client path works
20// end-to-end.
21//
22// if workerd dev doesn't deliver server->client via the #384 bridge, the gate
23// downgrades this to a client-probe assertion (SELECTORS.probeEmitButton ->
24// probeEventRow).
25test('cloudflare: server-emitted event reaches the client devtools via the runtime bridge', async ({
26 page,
27}) => {
28 const dt = new DevtoolsPage(page)
29 await dt.goto()
30 await dt.openViaTrigger()
31​
32 // Hover the plugins tab to expand the plugin sidebar so the names are visible.
33 await dt.tab('plugins').hover()
34​
35 // Activate the Event Probe plugin so its panel (and its server-ping listener) mounts.
36 await page.getByText('Event Probe', { exact: true }).click()
37​
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 })
49})