-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathapp.spec.ts
More file actions
213 lines (178 loc) · 6.26 KB
/
Copy pathapp.spec.ts
File metadata and controls
213 lines (178 loc) · 6.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import { expect } from '@playwright/test'
import { test } from '@tanstack/router-e2e-utils'
import type { Page } from '@playwright/test'
async function awaitPageLoaded(page: Page) {
// wait for page to be loaded by waiting for the ClientOnly component to be rendered
await expect(page.getByTestId('router-isLoading')).toContainText('false')
await expect(page.getByTestId('router-status')).toContainText('idle')
}
async function checkData(page: Page, id: string) {
const expectedData = await page
.getByTestId(`${id}-car-expected`)
.textContent()
expect(expectedData).not.toBeNull()
await expect(page.getByTestId(`${id}-car-actual`)).toContainText(
expectedData!,
)
await expect(page.getByTestId(`${id}-foo`)).toContainText(
'{"value":"server"}',
)
}
async function checkNestedData(page: Page) {
const expectedShout = await page
.getByTestId(`shout-expected-state`)
.textContent()
expect(expectedShout).not.toBeNull()
await expect(page.getByTestId(`shout-actual-state`)).toContainText(
expectedShout!,
)
const expectedWhisper = await page
.getByTestId(`whisper-expected-state`)
.textContent()
expect(expectedWhisper).not.toBeNull()
await expect(page.getByTestId(`whisper-actual-state`)).toContainText(
expectedWhisper!,
)
}
test.use({
whitelistErrors: [
'Failed to load resource: the server responded with a status of 499',
],
})
test.describe('SSR serialization adapters', () => {
test(`data-only`, async ({ page }) => {
await page.goto('/ssr/data-only')
await awaitPageLoaded(page)
await Promise.all(
['context', 'loader'].map(async (id) => checkData(page, id)),
)
const expectedHonkData = await page
.getByTestId('honk-expected-state')
.textContent()
expect(expectedHonkData).not.toBeNull()
await expect(page.getByTestId('honk-actual-state')).toContainText(
expectedHonkData!,
)
})
test('stream', async ({ page }) => {
await page.goto('/ssr/stream')
await awaitPageLoaded(page)
await checkData(page, 'stream')
})
test('nested', async ({ page }) => {
await page.goto('/ssr/nested')
await awaitPageLoaded(page)
await checkNestedData(page)
})
})
test.describe('server functions serialization adapters', () => {
test('client entry server functions use custom serialization adapters', async ({
page,
}) => {
await page.goto('/server-function/nested?client-entry-server-fn')
await awaitPageLoaded(page)
const result = await page
.waitForFunction(
() => (window as any).__serializationAdapterClientEntryResult,
)
.then((handle) => handle.jsonValue())
expect(result).toEqual({
status: 'success',
ping: 'ready',
shout: 'HELLO WORLD',
whisper: 'hello world',
})
})
test('custom error', async ({ page }) => {
await page.goto('/server-function/custom-error')
await awaitPageLoaded(page)
await expect(
page.getByTestId('server-function-valid-response'),
).toContainText('null')
await expect(
page.getByTestId('server-function-invalid-response'),
).toContainText('null')
await page.getByTestId('server-function-valid-input').click()
await expect(
page.getByTestId('server-function-valid-response'),
).toContainText('Hello, world!')
await page.getByTestId('server-function-invalid-input').click()
await expect(
page.getByTestId('server-function-invalid-response'),
).toContainText('{"message":"Invalid input","foo":"bar","bar":"123"}')
})
test('nested', async ({ page }) => {
await page.goto('/server-function/nested')
await awaitPageLoaded(page)
await expect(page.getByTestId('waiting-for-response')).toContainText(
'waiting for response...',
)
await page.getByTestId('server-function-trigger').click()
await checkNestedData(page)
})
})
test.describe('late RawStream serialization', () => {
test('single late stream', async ({ page }) => {
await page.goto('/server-function/late-raw-stream')
await awaitPageLoaded(page)
// Verify initial state
await expect(page.getByTestId('late-waiting')).toContainText(
'waiting for trigger...',
)
// Trigger the server function
await page.getByTestId('late-trigger').click()
// Verify immediate data is available
await expect(page.getByTestId('late-immediate')).toContainText(
'immediate-data',
)
await expect(page.getByTestId('late-timestamp')).not.toBeEmpty()
// Verify late stream resolves correctly
await expect(page.getByTestId('late-stream-result')).toContainText(
'chunk1-chunk2-chunk3',
{ timeout: 10000 },
)
})
test('multiple late streams', async ({ page }) => {
await page.goto('/server-function/late-raw-stream')
await awaitPageLoaded(page)
// Verify initial state
await expect(page.getByTestId('multi-waiting')).toContainText(
'waiting for trigger...',
)
// Trigger the server function
await page.getByTestId('multi-trigger').click()
// Verify timestamp
await expect(page.getByTestId('multi-timestamp')).not.toBeEmpty()
// Verify both late streams resolve correctly
await expect(page.getByTestId('multi-stream1-result')).toContainText(
'stream1-a-stream1-b',
{ timeout: 10000 },
)
await expect(page.getByTestId('multi-stream2-result')).toContainText(
'stream2-a-stream2-b',
{ timeout: 10000 },
)
})
test('mixed immediate and late streams', async ({ page }) => {
await page.goto('/server-function/late-raw-stream')
await awaitPageLoaded(page)
// Verify initial state
await expect(page.getByTestId('mixed-waiting')).toContainText(
'waiting for trigger...',
)
// Trigger the server function
await page.getByTestId('mixed-trigger').click()
// Verify timestamp
await expect(page.getByTestId('mixed-timestamp')).not.toBeEmpty()
// Verify immediate stream resolves (discovered during initial serialization)
await expect(page.getByTestId('mixed-immediate-result')).toContainText(
'immediate-a-immediate-b',
{ timeout: 10000 },
)
// Verify late stream resolves (discovered after serialization starts)
await expect(page.getByTestId('mixed-late-result')).toContainText(
'late-a-late-b',
{ timeout: 10000 },
)
})
})