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

nitro.spec.ts

44 lines2.0 KB

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