@@ -86,6 +86,20 @@ async function nextDev(dir, port) {
86
86
} )
87
87
}
88
88
89
+ async function resolveStreamResponse ( response , onData ) {
90
+ let result = ''
91
+ onData = onData || ( ( ) => { } )
92
+ await new Promise ( ( resolve ) => {
93
+ response . body . on ( 'data' , ( chunk ) => {
94
+ result += chunk . toString ( )
95
+ onData ( chunk . toString ( ) , result )
96
+ } )
97
+
98
+ response . body . on ( 'end' , resolve )
99
+ } )
100
+ return result
101
+ }
102
+
89
103
describe ( 'concurrentFeatures - basic' , ( ) => {
90
104
it ( 'should warn user for experimental risk with server components' , async ( ) => {
91
105
const edgeRuntimeWarning =
@@ -296,24 +310,17 @@ async function runBasicTests(context, env) {
296
310
it ( 'should support streaming' , async ( ) => {
297
311
await fetchViaHTTP ( context . appPort , '/streaming' , null , { } ) . then (
298
312
async ( response ) => {
299
- let result = ''
300
313
let gotFallback = false
301
314
let gotData = false
302
315
303
- await new Promise ( ( resolve ) => {
304
- response . body . on ( 'data' , ( chunk ) => {
305
- result += chunk . toString ( )
306
-
307
- gotData = result . includes ( 'next_streaming_data' )
308
- if ( ! gotFallback ) {
309
- gotFallback = result . includes ( 'next_streaming_fallback' )
310
- if ( gotFallback ) {
311
- expect ( gotData ) . toBe ( false )
312
- }
316
+ await resolveStreamResponse ( response , ( _ , result ) => {
317
+ gotData = result . includes ( 'next_streaming_data' )
318
+ if ( ! gotFallback ) {
319
+ gotFallback = result . includes ( 'next_streaming_fallback' )
320
+ if ( gotFallback ) {
321
+ expect ( gotData ) . toBe ( false )
313
322
}
314
- } )
315
-
316
- response . body . on ( 'end' , ( ) => resolve ( ) )
323
+ }
317
324
} )
318
325
319
326
expect ( gotFallback ) . toBe ( true )
@@ -327,6 +334,15 @@ async function runBasicTests(context, env) {
327
334
expect ( content ) . toMatchInlineSnapshot ( '"next_streaming_data"' )
328
335
} )
329
336
337
+ it ( 'should support streaming flight request' , async ( ) => {
338
+ await fetchViaHTTP ( context . appPort , '/?__flight__=1' ) . then (
339
+ async ( response ) => {
340
+ const result = await resolveStreamResponse ( response )
341
+ expect ( result ) . toContain ( 'component:index.server' )
342
+ }
343
+ )
344
+ } )
345
+
330
346
it ( 'should support api routes' , async ( ) => {
331
347
const res = await renderViaHTTP ( context . appPort , '/api/ping' )
332
348
expect ( res ) . toContain ( 'pong' )
0 commit comments