@@ -42,6 +42,37 @@ describe('ReactFlightDOMEdge', () => {
4242 use = React . use ;
4343 } ) ;
4444
45+ function passThrough ( stream ) {
46+ // Simulate more realistic network by splitting up and rejoining some chunks.
47+ // This lets us test that we don't accidentally rely on particular bounds of the chunks.
48+ return new ReadableStream ( {
49+ async start ( controller ) {
50+ const reader = stream . getReader ( ) ;
51+ let prevChunk = new Uint8Array ( 0 ) ;
52+ function push ( ) {
53+ reader . read ( ) . then ( ( { done, value} ) => {
54+ if ( done ) {
55+ controller . enqueue ( prevChunk ) ;
56+ controller . close ( ) ;
57+ return ;
58+ }
59+ const chunk = new Uint8Array ( prevChunk . length + value . length ) ;
60+ chunk . set ( prevChunk , 0 ) ;
61+ chunk . set ( value , prevChunk . length ) ;
62+ if ( chunk . length > 50 ) {
63+ controller . enqueue ( chunk . subarray ( 0 , chunk . length - 50 ) ) ;
64+ prevChunk = chunk . subarray ( chunk . length - 50 ) ;
65+ } else {
66+ prevChunk = chunk ;
67+ }
68+ push ( ) ;
69+ } ) ;
70+ }
71+ push ( ) ;
72+ } ,
73+ } ) ;
74+ }
75+
4576 async function readResult ( stream ) {
4677 const reader = stream . getReader ( ) ;
4778 let result = '' ;
@@ -101,15 +132,17 @@ describe('ReactFlightDOMEdge', () => {
101132
102133 it ( 'should encode long string in a compact format' , async ( ) => {
103134 const testString = '"\n\t' . repeat ( 500 ) + '🙃' ;
135+ const testString2 = 'hello' . repeat ( 400 ) ;
104136
105137 const stream = ReactServerDOMServer . renderToReadableStream ( {
106138 text : testString ,
139+ text2 : testString2 ,
107140 } ) ;
108- const [ stream1 , stream2 ] = stream . tee ( ) ;
141+ const [ stream1 , stream2 ] = passThrough ( stream ) . tee ( ) ;
109142
110143 const serializedContent = await readResult ( stream1 ) ;
111144 // The content should be compact an unescaped
112- expect ( serializedContent . length ) . toBeLessThan ( 2000 ) ;
145+ expect ( serializedContent . length ) . toBeLessThan ( 4000 ) ;
113146 expect ( serializedContent ) . not . toContain ( '\\n' ) ;
114147 expect ( serializedContent ) . not . toContain ( '\\t' ) ;
115148 expect ( serializedContent ) . not . toContain ( '\\"' ) ;
@@ -118,5 +151,6 @@ describe('ReactFlightDOMEdge', () => {
118151 const result = await ReactServerDOMClient . createFromReadableStream ( stream2 ) ;
119152 // Should still match the result when parsed
120153 expect ( result . text ) . toBe ( testString ) ;
154+ expect ( result . text2 ) . toBe ( testString2 ) ;
121155 } ) ;
122156} ) ;
0 commit comments