@@ -42,6 +42,37 @@ describe('ReactFlightDOMEdge', () => {
42
42
use = React . use ;
43
43
} ) ;
44
44
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
+
45
76
async function readResult ( stream ) {
46
77
const reader = stream . getReader ( ) ;
47
78
let result = '' ;
@@ -101,15 +132,17 @@ describe('ReactFlightDOMEdge', () => {
101
132
102
133
it ( 'should encode long string in a compact format' , async ( ) => {
103
134
const testString = '"\n\t' . repeat ( 500 ) + '🙃' ;
135
+ const testString2 = 'hello' . repeat ( 400 ) ;
104
136
105
137
const stream = ReactServerDOMServer . renderToReadableStream ( {
106
138
text : testString ,
139
+ text2 : testString2 ,
107
140
} ) ;
108
- const [ stream1 , stream2 ] = stream . tee ( ) ;
141
+ const [ stream1 , stream2 ] = passThrough ( stream ) . tee ( ) ;
109
142
110
143
const serializedContent = await readResult ( stream1 ) ;
111
144
// The content should be compact an unescaped
112
- expect ( serializedContent . length ) . toBeLessThan ( 2000 ) ;
145
+ expect ( serializedContent . length ) . toBeLessThan ( 4000 ) ;
113
146
expect ( serializedContent ) . not . toContain ( '\\n' ) ;
114
147
expect ( serializedContent ) . not . toContain ( '\\t' ) ;
115
148
expect ( serializedContent ) . not . toContain ( '\\"' ) ;
@@ -118,5 +151,6 @@ describe('ReactFlightDOMEdge', () => {
118
151
const result = await ReactServerDOMClient . createFromReadableStream ( stream2 ) ;
119
152
// Should still match the result when parsed
120
153
expect ( result . text ) . toBe ( testString ) ;
154
+ expect ( result . text2 ) . toBe ( testString2 ) ;
121
155
} ) ;
122
156
} ) ;
0 commit comments