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

start.spec.ts

42 lines2.0 KB

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