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

raw-stream.spec.ts

714 lines23.8 KB

1import { expect } from '@playwright/test'
2import { test } from '@tanstack/router-e2e-utils'
3import { isPrerender } from './utils/isPrerender'
4​
5/**
6 * These tests verify the RawStream binary streaming functionality.
7 *
8 * RawStream allows returning ReadableStream<Uint8Array> from server functions
9 * with efficient binary encoding:
10 * - Server functions (RPC): Binary framing protocol
11 * - SSR loaders: Base64 encoding via seroval's stream mechanism
12 */
13​
14// Wait time for hydration to complete after page load
15// This needs to be long enough for React hydration to attach event handlers
16const HYDRATION_WAIT = 1000
17​
18test.describe('RawStream - Client RPC Tests', () => {
19 test('Single raw stream - returns stream with binary data', async ({
20 page,
21 }) => {
22 await page.goto('/raw-stream/client-call')
23 await page.waitForURL('/raw-stream/client-call')
24​
25 // Wait for hydration
26 await page.getByTestId('test1-btn').waitFor({ state: 'visible' })
27 await page.waitForTimeout(HYDRATION_WAIT)
28​
29 await page.getByTestId('test1-btn').click()
30 await page
31 .getByTestId('test1-result')
32 .waitFor({ state: 'visible', timeout: 10000 })
33​
34 const result = await page.getByTestId('test1-result').textContent()
35​
36 expect(result).toContain('chunk1chunk2chunk3')
37 expect(result).toContain('Single stream test')
38 })
39​
40 test('Multiple raw streams - returns multiple independent streams', async ({
41 page,
42 }) => {
43 await page.goto('/raw-stream/client-call')
44 await page.waitForURL('/raw-stream/client-call')
45​
46 await page.getByTestId('test2-btn').waitFor({ state: 'visible' })
47 await page.waitForTimeout(HYDRATION_WAIT)
48​
49 await page.getByTestId('test2-btn').click()
50 await page
51 .getByTestId('test2-result')
52 .waitFor({ state: 'visible', timeout: 10000 })
53​
54 const result = await page.getByTestId('test2-result').textContent()
55​
56 expect(result).toContain('stream1-astream1-b')
57 expect(result).toContain('stream2-astream2-b')
58 expect(result).toContain('Multiple streams test')
59 })
60​
61 test('JSON ends before raw stream - handles timing correctly', async ({
62 page,
63 }) => {
64 await page.goto('/raw-stream/client-call')
65 await page.waitForURL('/raw-stream/client-call')
66​
67 await page.getByTestId('test3-btn').waitFor({ state: 'visible' })
68 await page.waitForTimeout(HYDRATION_WAIT)
69​
70 await page.getByTestId('test3-btn').click()
71 await page
72 .getByTestId('test3-result')
73 .waitFor({ state: 'visible', timeout: 10000 })
74 const result = await page.getByTestId('test3-result').textContent()
75​
76 expect(result).toContain('slow-1slow-2slow-3slow-4')
77 expect(result).toContain('JSON ends first test')
78 expect(result).toContain('hasTimestamp')
79 })
80​
81 test('Raw stream ends before JSON - handles timing correctly', async ({
82 page,
83 }) => {
84 await page.goto('/raw-stream/client-call')
85 await page.waitForURL('/raw-stream/client-call')
86​
87 await page.getByTestId('test4-btn').waitFor({ state: 'visible' })
88 await page.waitForTimeout(HYDRATION_WAIT)
89​
90 await page.getByTestId('test4-btn').click()
91 await page
92 .getByTestId('test4-result')
93 .waitFor({ state: 'visible', timeout: 10000 })
94 const result = await page.getByTestId('test4-result').textContent()
95​
96 expect(result).toContain('fast-done')
97 expect(result).toContain('deferred-json-data')
98 expect(result).toContain('Raw ends first test')
99 })
100​
101 test('Large binary data - handles 3KB of binary correctly', async ({
102 page,
103 }) => {
104 await page.goto('/raw-stream/client-call')
105 await page.waitForURL('/raw-stream/client-call')
106​
107 await page.getByTestId('test5-btn').waitFor({ state: 'visible' })
108 await page.waitForTimeout(HYDRATION_WAIT)
109​
110 await page.getByTestId('test5-btn').click()
111 await page
112 .getByTestId('test5-result')
113 .waitFor({ state: 'visible', timeout: 10000 })
114 const result = await page.getByTestId('test5-result').textContent()
115​
116 expect(result).toContain('"sizeMatch":true')
117 expect(result).toContain('"actualSize":3072')
118 expect(result).toContain('Large binary test')
119 })
120​
121 test('Mixed streaming - Promise and RawStream together', async ({ page }) => {
122 await page.goto('/raw-stream/client-call')
123 await page.waitForURL('/raw-stream/client-call')
124​
125 await page.getByTestId('test6-btn').waitFor({ state: 'visible' })
126 await page.waitForTimeout(HYDRATION_WAIT)
127​
128 await page.getByTestId('test6-btn').click()
129 await page
130 .getByTestId('test6-result')
131 .waitFor({ state: 'visible', timeout: 10000 })
132 const result = await page.getByTestId('test6-result').textContent()
133​
134 expect(result).toContain('immediate-value')
135 expect(result).toContain('deferred-value')
136 expect(result).toContain('mixed-raw-1mixed-raw-2')
137 })
138})
139​
140test.describe('RawStream - SSR Loader Tests', () => {
141 test('SSR single stream - direct navigation', async ({ page }) => {
142 // Direct navigation = full SSR with base64 encoding
143 await page.goto('/raw-stream/ssr-single')
144 await page.waitForURL('/raw-stream/ssr-single')
145​
146 // Wait for stream to be consumed (SSR tests need hydration + stream consumption)
147 await expect(page.getByTestId('ssr-single-stream')).toContainText(
148 'ssr-chunk1ssr-chunk2ssr-chunk3',
149 { timeout: 10000 },
150 )
151 await expect(page.getByTestId('ssr-single-message')).toContainText(
152 'SSR Single Stream Test',
153 )
154 await expect(page.getByTestId('ssr-single-timestamp')).toContainText(
155 'Has Timestamp: true',
156 )
157 })
158​
159 test('SSR multiple streams - direct navigation', async ({ page }) => {
160 await page.goto('/raw-stream/ssr-multiple')
161 await page.waitForURL('/raw-stream/ssr-multiple')
162​
163 await expect(page.getByTestId('ssr-multiple-first')).toContainText(
164 'multi-1amulti-1b',
165 { timeout: 10000 },
166 )
167 await expect(page.getByTestId('ssr-multiple-second')).toContainText(
168 'multi-2amulti-2b',
169 )
170 await expect(page.getByTestId('ssr-multiple-message')).toContainText(
171 'SSR Multiple Streams Test',
172 )
173 })
174​
175 // Skip in prerender mode: RawStream + deferred data causes stream chunks to be
176 // missing from prerendered HTML. This is a known limitation where the prerender
177 // process doesn't properly capture streaming data when deferred promises are present.
178 ;(isPrerender ? test.skip : test)(
179 'SSR mixed streaming - RawStream with deferred data',
180 async ({ page }) => {
181 await page.goto('/raw-stream/ssr-mixed')
182 await page.waitForURL('/raw-stream/ssr-mixed')
183​
184 await expect(page.getByTestId('ssr-mixed-immediate')).toContainText(
185 'immediate-ssr-value',
186 )
187 await expect(page.getByTestId('ssr-mixed-stream')).toContainText(
188 'mixed-ssr-1mixed-ssr-2',
189 { timeout: 10000 },
190 )
191 // Deferred promise should also resolve
192 await expect(page.getByTestId('ssr-mixed-deferred')).toContainText(
193 'deferred-ssr-value',
194 { timeout: 10000 },
195 )
196 },
197 )
198​
199 test('SSR single stream - client-side navigation', async ({ page }) => {
200 // Start from index, then navigate client-side to SSR route
201 await page.goto('/raw-stream')
202 await page.waitForURL('/raw-stream')
203​
204 // Wait for hydration (use navigation to be specific)
205 await page
206 .getByRole('navigation')
207 .getByRole('link', { name: 'SSR Single' })
208 .waitFor({ state: 'visible' })
209 await page.waitForTimeout(HYDRATION_WAIT)
210​
211 // Client-side navigation
212 await page
213 .getByRole('navigation')
214 .getByRole('link', { name: 'SSR Single' })
215 .click()
216 await page.waitForURL('/raw-stream/ssr-single')
217​
218 // Stream should still work after client navigation
219 await expect(page.getByTestId('ssr-single-stream')).toContainText(
220 'ssr-chunk1ssr-chunk2ssr-chunk3',
221 { timeout: 10000 },
222 )
223 })
224​
225 test('SSR multiple streams - client-side navigation', async ({ page }) => {
226 await page.goto('/raw-stream')
227 await page.waitForURL('/raw-stream')
228​
229 await page
230 .getByRole('navigation')
231 .getByRole('link', { name: 'SSR Multiple' })
232 .waitFor({ state: 'visible' })
233 await page.waitForTimeout(HYDRATION_WAIT)
234​
235 await page
236 .getByRole('navigation')
237 .getByRole('link', { name: 'SSR Multiple' })
238 .click()
239 await page.waitForURL('/raw-stream/ssr-multiple')
240​
241 await expect(page.getByTestId('ssr-multiple-first')).toContainText(
242 'multi-1amulti-1b',
243 { timeout: 10000 },
244 )
245 await expect(page.getByTestId('ssr-multiple-second')).toContainText(
246 'multi-2amulti-2b',
247 )
248 })
249})
250​
251test.describe('RawStream - Hint Parameter (RPC)', () => {
252 test('Text hint with pure text - uses UTF-8 encoding', async ({ page }) => {
253 await page.goto('/raw-stream/client-call')
254 await page.waitForURL('/raw-stream/client-call')
255​
256 await page.getByTestId('test7-btn').waitFor({ state: 'visible' })
257 await page.waitForTimeout(HYDRATION_WAIT)
258​
259 await page.getByTestId('test7-btn').click()
260 await page
261 .getByTestId('test7-result')
262 .waitFor({ state: 'visible', timeout: 10000 })
263 const result = await page.getByTestId('test7-result').textContent()
264​
265 expect(result).toContain('"match":true')
266 expect(result).toContain('Hello, World! This is text.')
267 expect(result).toContain('Text hint with pure text')
268 })
269​
270 test('Text hint with pure binary - fallback to base64', async ({ page }) => {
271 await page.goto('/raw-stream/client-call')
272 await page.waitForURL('/raw-stream/client-call')
273​
274 await page.getByTestId('test8-btn').waitFor({ state: 'visible' })
275 await page.waitForTimeout(HYDRATION_WAIT)
276​
277 await page.getByTestId('test8-btn').click()
278 await page
279 .getByTestId('test8-result')
280 .waitFor({ state: 'visible', timeout: 10000 })
281 const result = await page.getByTestId('test8-result').textContent()
282​
283 expect(result).toContain('"match":true')
284 expect(result).toContain('"expectedLength":12')
285 })
286​
287 test('Text hint with mixed content - handles both', async ({ page }) => {
288 await page.goto('/raw-stream/client-call')
289 await page.waitForURL('/raw-stream/client-call')
290​
291 await page.getByTestId('test9-btn').waitFor({ state: 'visible' })
292 await page.waitForTimeout(HYDRATION_WAIT)
293​
294 await page.getByTestId('test9-btn').click()
295 await page
296 .getByTestId('test9-result')
297 .waitFor({ state: 'visible', timeout: 10000 })
298 const result = await page.getByTestId('test9-result').textContent()
299​
300 expect(result).toContain('"match":true')
301 expect(result).toContain('"expectedLength":30')
302 })
303​
304 test('Binary hint with text data - uses base64', async ({ page }) => {
305 await page.goto('/raw-stream/client-call')
306 await page.waitForURL('/raw-stream/client-call')
307​
308 await page.getByTestId('test10-btn').waitFor({ state: 'visible' })
309 await page.waitForTimeout(HYDRATION_WAIT)
310​
311 await page.getByTestId('test10-btn').click()
312 await page
313 .getByTestId('test10-result')
314 .waitFor({ state: 'visible', timeout: 10000 })
315 const result = await page.getByTestId('test10-result').textContent()
316​
317 expect(result).toContain('"match":true')
318 expect(result).toContain('This is text but using binary hint')
319 })
320​
321 test('Binary hint with binary data - uses base64', async ({ page }) => {
322 await page.goto('/raw-stream/client-call')
323 await page.waitForURL('/raw-stream/client-call')
324​
325 await page.getByTestId('test11-btn').waitFor({ state: 'visible' })
326 await page.waitForTimeout(HYDRATION_WAIT)
327​
328 await page.getByTestId('test11-btn').click()
329 await page
330 .getByTestId('test11-result')
331 .waitFor({ state: 'visible', timeout: 10000 })
332 const result = await page.getByTestId('test11-result').textContent()
333​
334 expect(result).toContain('"match":true')
335 expect(result).toContain('"expectedLength":6')
336 })
337})
338​
339test.describe('RawStream - SSR Hint Parameter Tests', () => {
340 test('SSR text hint with pure text - direct navigation', async ({ page }) => {
341 await page.goto('/raw-stream/ssr-text-hint')
342 await page.waitForURL('/raw-stream/ssr-text-hint')
343​
344 await expect(page.getByTestId('ssr-text-hint-pure-text')).toContainText(
345 'Hello World from SSR!',
346 { timeout: 10000 },
347 )
348 await expect(page.getByTestId('ssr-text-hint-pure-match')).toContainText(
349 'true',
350 )
351 await expect(page.getByTestId('ssr-text-hint-mixed-match')).toContainText(
352 'true',
353 )
354 await expect(
355 page.getByTestId('ssr-text-hint-pure-binary-match'),
356 ).toContainText('true')
357 })
358​
359 test('SSR text hint - byte-by-byte verification', async ({ page }) => {
360 await page.goto('/raw-stream/ssr-text-hint')
361 await page.waitForURL('/raw-stream/ssr-text-hint')
362​
363 // Wait for streams to be fully consumed
364 await expect(page.getByTestId('ssr-text-hint-result')).toContainText(
365 '"match":true',
366 { timeout: 10000 },
367 )
368 // Check pure text, mixed content, and pure binary all match
369 const result = await page.getByTestId('ssr-text-hint-result').textContent()
370 const parsed = JSON.parse(result || '{}')
371 expect(parsed.pureTextMatch?.match).toBe(true)
372 expect(parsed.mixedMatch?.match).toBe(true)
373 expect(parsed.pureBinaryMatch?.match).toBe(true)
374 })
375​
376 test('SSR binary hint with text - direct navigation', async ({ page }) => {
377 await page.goto('/raw-stream/ssr-binary-hint')
378 await page.waitForURL('/raw-stream/ssr-binary-hint')
379​
380 await expect(page.getByTestId('ssr-binary-hint-text')).toContainText(
381 'Binary hint with text',
382 { timeout: 10000 },
383 )
384 await expect(page.getByTestId('ssr-binary-hint-text-match')).toContainText(
385 'true',
386 )
387 await expect(
388 page.getByTestId('ssr-binary-hint-binary-match'),
389 ).toContainText('true')
390 })
391​
392 test('SSR binary hint - byte-by-byte verification', async ({ page }) => {
393 await page.goto('/raw-stream/ssr-binary-hint')
394 await page.waitForURL('/raw-stream/ssr-binary-hint')
395​
396 // Wait for streams to be fully consumed
397 await expect(page.getByTestId('ssr-binary-hint-result')).toContainText(
398 '"match":true',
399 { timeout: 10000 },
400 )
401 // Check both text and binary data match
402 const result = await page
403 .getByTestId('ssr-binary-hint-result')
404 .textContent()
405 const parsed = JSON.parse(result || '{}')
406 expect(parsed.textMatch?.match).toBe(true)
407 expect(parsed.binaryMatch?.match).toBe(true)
408 })
409​
410 test('SSR text hint - client-side navigation', async ({ page }) => {
411 await page.goto('/raw-stream')
412 await page.waitForURL('/raw-stream')
413​
414 await page
415 .getByRole('navigation')
416 .getByRole('link', { name: 'SSR Text Hint' })
417 .waitFor({ state: 'visible' })
418 await page.waitForTimeout(HYDRATION_WAIT)
419​
420 await page
421 .getByRole('navigation')
422 .getByRole('link', { name: 'SSR Text Hint' })
423 .click()
424 await page.waitForURL('/raw-stream/ssr-text-hint')
425​
426 await expect(page.getByTestId('ssr-text-hint-pure-match')).toContainText(
427 'true',
428 { timeout: 10000 },
429 )
430 await expect(page.getByTestId('ssr-text-hint-mixed-match')).toContainText(
431 'true',
432 )
433 await expect(
434 page.getByTestId('ssr-text-hint-pure-binary-match'),
435 ).toContainText('true')
436 })
437​
438 test('SSR binary hint - client-side navigation', async ({ page }) => {
439 await page.goto('/raw-stream')
440 await page.waitForURL('/raw-stream')
441​
442 await page
443 .getByRole('navigation')
444 .getByRole('link', { name: 'SSR Binary Hint' })
445 .waitFor({ state: 'visible' })
446 await page.waitForTimeout(HYDRATION_WAIT)
447​
448 await page
449 .getByRole('navigation')
450 .getByRole('link', { name: 'SSR Binary Hint' })
451 .click()
452 await page.waitForURL('/raw-stream/ssr-binary-hint')
453​
454 await expect(page.getByTestId('ssr-binary-hint-text-match')).toContainText(
455 'true',
456 { timeout: 10000 },
457 )
458 await expect(
459 page.getByTestId('ssr-binary-hint-binary-match'),
460 ).toContainText('true')
461 })
462})
463​
464test.describe('RawStream - Multiplexing Tests (RPC)', () => {
465 test('Interleaved streams - two concurrent streams with variable delays', async ({
466 page,
467 }) => {
468 await page.goto('/raw-stream/client-call')
469 await page.waitForURL('/raw-stream/client-call')
470​
471 await page.getByTestId('test12-btn').waitFor({ state: 'visible' })
472 await page.waitForTimeout(HYDRATION_WAIT)
473​
474 await page.getByTestId('test12-btn').click()
475 await page
476 .getByTestId('test12-result')
477 .waitFor({ state: 'visible', timeout: 15000 })
478 const result = await page.getByTestId('test12-result').textContent()
479​
480 // Both streams should have matching bytes
481 expect(result).toContain('"match":true')
482 // Verify both streams match
483 const parsed = JSON.parse(result || '{}')
484 expect(parsed.streamA?.match).toBe(true)
485 expect(parsed.streamB?.match).toBe(true)
486 })
487​
488 test('Burst-pause-burst - single stream with variable timing', async ({
489 page,
490 }) => {
491 await page.goto('/raw-stream/client-call')
492 await page.waitForURL('/raw-stream/client-call')
493​
494 await page.getByTestId('test13-btn').waitFor({ state: 'visible' })
495 await page.waitForTimeout(HYDRATION_WAIT)
496​
497 await page.getByTestId('test13-btn').click()
498 await page
499 .getByTestId('test13-result')
500 .waitFor({ state: 'visible', timeout: 15000 })
501 const result = await page.getByTestId('test13-result').textContent()
502​
503 expect(result).toContain('"match":true')
504 expect(result).toContain('Burst-pause-burst test')
505 })
506​
507 test('Three concurrent streams - different timing patterns', async ({
508 page,
509 }) => {
510 await page.goto('/raw-stream/client-call')
511 await page.waitForURL('/raw-stream/client-call')
512​
513 await page.getByTestId('test14-btn').waitFor({ state: 'visible' })
514 await page.waitForTimeout(HYDRATION_WAIT)
515​
516 await page.getByTestId('test14-btn').click()
517 await page
518 .getByTestId('test14-result')
519 .waitFor({ state: 'visible', timeout: 15000 })
520 const result = await page.getByTestId('test14-result').textContent()
521​
522 // All three streams should match
523 expect(result).toContain('"match":true')
524 // Verify all three streams match
525 const parsed = JSON.parse(result || '{}')
526 expect(parsed.fast?.match).toBe(true)
527 expect(parsed.slow?.match).toBe(true)
528 expect(parsed.burst?.match).toBe(true)
529 })
530})
531​
532test.describe('RawStream - Cross Navigation', () => {
533 test('Client RPC works after navigating from SSR route', async ({ page }) => {
534 // Start with SSR route
535 await page.goto('/raw-stream/ssr-single')
536 await page.waitForURL('/raw-stream/ssr-single')
537​
538 // Wait for SSR stream to complete (ensures hydration is done)
539 await expect(page.getByTestId('ssr-single-stream')).toContainText(
540 'ssr-chunk1ssr-chunk2ssr-chunk3',
541 { timeout: 10000 },
542 )
543​
544 // Navigate to client-call route (use first() to avoid strict mode on multiple matches)
545 await page
546 .getByRole('navigation')
547 .getByRole('link', { name: 'Client Calls' })
548 .click()
549 await page.waitForURL('/raw-stream/client-call')
550​
551 // Wait for hydration
552 await page.getByTestId('test1-btn').waitFor({ state: 'visible' })
553 await page.waitForTimeout(HYDRATION_WAIT)
554​
555 // Run RPC test
556 await page.getByTestId('test1-btn').click()
557​
558 await expect(page.getByTestId('test1-result')).toContainText(
559 'chunk1chunk2chunk3',
560 { timeout: 10000 },
561 )
562 })
563​
564 test('Navigation from home to raw-stream routes', async ({ page }) => {
565 // Start from home
566 await page.goto('/')
567 await page.waitForURL('/')
568​
569 // Wait for hydration
570 await page
571 .getByRole('link', { name: 'Raw Stream' })
572 .waitFor({ state: 'visible' })
573 await page.waitForTimeout(HYDRATION_WAIT)
574​
575 // Navigate via client-side to raw-stream
576 await page.getByRole('link', { name: 'Raw Stream' }).click()
577 await page.waitForURL('/raw-stream')
578​
579 // Wait for hydration on the new page
580 await page.waitForTimeout(HYDRATION_WAIT)
581​
582 // Then to client-call (use navigation area to avoid duplicates)
583 await page
584 .getByRole('navigation')
585 .getByRole('link', { name: 'Client Calls' })
586 .click()
587 await page.waitForURL('/raw-stream/client-call')
588​
589 // Wait for button
590 await page.getByTestId('test1-btn').waitFor({ state: 'visible' })
591 await page.waitForTimeout(HYDRATION_WAIT)
592​
593 // Run a test
594 await page.getByTestId('test1-btn').click()
595​
596 await expect(page.getByTestId('test1-result')).toContainText(
597 'chunk1chunk2chunk3',
598 { timeout: 10000 },
599 )
600 })
601})
602​
603test.describe('RawStream - Edge Cases (RPC)', () => {
604 test('Empty stream - handles zero-byte stream correctly', async ({
605 page,
606 }) => {
607 await page.goto('/raw-stream/client-call')
608 await page.waitForURL('/raw-stream/client-call')
609​
610 await page.getByTestId('test15-btn').waitFor({ state: 'visible' })
611 await page.waitForTimeout(HYDRATION_WAIT)
612​
613 await page.getByTestId('test15-btn').click()
614​
615 await page
616 .getByTestId('test15-result')
617 .waitFor({ state: 'visible', timeout: 10000 })
618​
619 const result = await page.getByTestId('test15-result').textContent()
620 expect(result).toContain('"isEmpty":true')
621 expect(result).toContain('"byteCount":0')
622 expect(result).toContain('Empty stream test')
623 })
624​
625 test('Stream error - propagates error to client', async ({ page }) => {
626 await page.goto('/raw-stream/client-call')
627 await page.waitForURL('/raw-stream/client-call')
628​
629 await page.getByTestId('test16-btn').waitFor({ state: 'visible' })
630 await page.waitForTimeout(HYDRATION_WAIT)
631​
632 await page.getByTestId('test16-btn').click()
633​
634 await page
635 .getByTestId('test16-result')
636 .waitFor({ state: 'visible', timeout: 10000 })
637​
638 const result = await page.getByTestId('test16-result').textContent()
639​
640 expect(result).toContain('"errorCaught":true')
641 expect(result).toContain('Intentional stream error')
642 expect(result).toContain('Error stream test')
643 })
644})
645​
646test.describe('RawStream - Late RawStream Tests (RPC)', () => {
647 test('Single late RawStream - Promise<RawStream> resolves correctly', async ({
648 page,
649 }) => {
650 await page.goto('/raw-stream/client-call')
651 await page.waitForURL('/raw-stream/client-call')
652​
653 await page.getByTestId('test17-btn').waitFor({ state: 'visible' })
654 await page.waitForTimeout(HYDRATION_WAIT)
655​
656 await page.getByTestId('test17-btn').click()
657​
658 await expect(page.getByTestId('test17-result')).toContainText(
659 '"match":true',
660 { timeout: 15000 },
661 )
662 await expect(page.getByTestId('test17-result')).toContainText(
663 'Late stream test',
664 )
665 })
666​
667 test('Multiple late RawStreams - different Promise delays', async ({
668 page,
669 }) => {
670 await page.goto('/raw-stream/client-call')
671 await page.waitForURL('/raw-stream/client-call')
672​
673 await page.getByTestId('test18-btn').waitFor({ state: 'visible' })
674 await page.waitForTimeout(HYDRATION_WAIT)
675​
676 await page.getByTestId('test18-btn').click()
677​
678 // Both streams should match
679 await expect(page.getByTestId('test18-result')).toContainText(
680 '"match":true',
681 { timeout: 15000 },
682 )
683 // Verify both streams match by checking result
684 const result = await page.getByTestId('test18-result').textContent()
685 const parsed = JSON.parse(result || '{}')
686 expect(parsed.streamA?.match).toBe(true)
687 expect(parsed.streamB?.match).toBe(true)
688 expect(parsed.message).toBe('Multiple late streams test')
689 })
690​
691 test('Mixed immediate and late RawStreams - both work correctly', async ({
692 page,
693 }) => {
694 await page.goto('/raw-stream/client-call')
695 await page.waitForURL('/raw-stream/client-call')
696​
697 await page.getByTestId('test19-btn').waitFor({ state: 'visible' })
698 await page.waitForTimeout(HYDRATION_WAIT)
699​
700 await page.getByTestId('test19-btn').click()
701​
702 // Both immediate and late streams should match
703 await expect(page.getByTestId('test19-result')).toContainText(
704 '"match":true',
705 { timeout: 15000 },
706 )
707 // Verify both streams match by checking result
708 const result = await page.getByTestId('test19-result').textContent()
709 const parsed = JSON.parse(result || '{}')
710 expect(parsed.immediate?.match).toBe(true)
711 expect(parsed.late?.match).toBe(true)
712 expect(parsed.message).toBe('Mixed immediate and late test')
713 })
714})