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

ssr-db.spec.ts

93 lines3.2 KB

1import { expect, test } from '@playwright/test'
2​
3test(`TanStack Start hydrates, reconciles, and incrementally applies DB rows`, async ({
4 page,
5 request,
6}) => {
7 const response = await request.get(`/ssr-db`)
8 expect(response.ok()).toBe(true)
9​
10 const html = await response.text()
11 expect(html).toContain(`Pay invoices`)
12 expect(html).not.toContain(`Pay invoices (reconciled from sync)`)
13 expect(html).toContain(`Review pull requests`)
14 expect(html).toContain(`ssr`)
15 expect(html).not.toContain(`Streamed from collection chunk`)
16​
17 const browserErrors: Array<string> = []
18 page.on(`console`, (message) => {
19 if (message.type() === `error`) {
20 browserErrors.push(message.text())
21 }
22 })
23 page.on(`pageerror`, (error) => {
24 browserErrors.push(error.message)
25 })
26​
27 await page.goto(`/ssr-db`)
28​
29 await expect(page.getByTestId(`hydration-state`)).toHaveText(`hydrated`)
30 await expect(page.getByTestId(`ready-state`)).toHaveText(`ready`)
31 await expect(page.getByTestId(`streamed-status`)).toHaveText(`waiting`)
32 await expect(page.getByTestId(`ssr-row-count`)).toHaveText(`2`)
33 await expect(page.getByTestId(`ssr-todo-list`)).toContainText(
34 `Pay invoices (reconciled from sync)`,
35 )
36 await expect(page.getByTestId(`ssr-todo-server-1`)).toContainText(`(sync)`)
37 await expect(page.getByTestId(`ssr-todo-list`)).toContainText(
38 `Review pull requests`,
39 )
40 await expect(page.getByTestId(`ssr-todo-list`)).not.toContainText(
41 `Archived roadmap`,
42 )
43​
44 await page.getByTestId(`apply-stream-chunk`).click()
45​
46 await expect(page.getByTestId(`streamed-status`)).toHaveText(`streamed`)
47 await expect(page.getByTestId(`ssr-row-count`)).toHaveText(`3`)
48 await expect(page.getByTestId(`ssr-todo-streamed-1`)).toBeVisible()
49 await expect(page.getByTestId(`ssr-todo-streamed-1`)).toContainText(
50 `Streamed from collection chunk`,
51 )
52 expect(browserErrors).toEqual([])
53})
54​
55test(`TanStack Start streams a DB result snapshot and hands off to browser sync`, async ({
56 page,
57 request,
58}) => {
59 const response = await request.get(`/ssr-db-stream`)
60 expect(response.ok()).toBe(true)
61 const html = await response.text()
62 expect(html).toContain(`Streamed while rendering`)
63 expect(html).not.toContain(`SOURCE_ONLY_DO_NOT_TRANSPORT`)
64​
65 const browserErrors: Array<string> = []
66 page.on(`console`, (message) => {
67 if (message.type() === `error`) {
68 browserErrors.push(message.text())
69 }
70 })
71 page.on(`pageerror`, (error) => {
72 browserErrors.push(error.message)
73 })
74​
75 await page.goto(`/ssr-db-stream`, { waitUntil: `commit` })
76​
77 await expect(page.getByTestId(`critical-todo-server-1`)).toContainText(
78 `Pay invoices`,
79 )
80 await expect(page.getByTestId(`stream-fallback`)).toBeVisible()
81 await expect(page.getByTestId(`streamed-todo-list`)).not.toBeVisible()
82 await expect(page.getByTestId(`streamed-todo-streamed-server-1`)).toHaveText(
83 `Streamed while rendering`,
84 )
85 await expect(page.getByTestId(`stream-fallback`)).not.toBeVisible()
86 await expect(
87 page.getByTestId(`streamed-todo-streamed-server-1`),
88 ).not.toBeVisible()
89 await expect(page.getByTestId(`streamed-todo-streamed-browser-1`)).toHaveText(
90 `Reconciled from browser sync`,
91 )
92 expect(browserErrors).toEqual([])
93})