diff --git a/test/integration/react-streaming-and-server-components/app/pages/streaming.js b/test/integration/react-streaming-and-server-components/app/pages/streaming.js new file mode 100644 index 0000000000000..ac58f5e9e2c38 --- /dev/null +++ b/test/integration/react-streaming-and-server-components/app/pages/streaming.js @@ -0,0 +1,23 @@ +import { Suspense } from 'react' + +let result +let promise +function Data() { + if (result) return result + if (!promise) + promise = new Promise((res) => { + setTimeout(() => { + result = 'next_streaming_data' + res() + }, 500) + }) + throw promise +} + +export default function Page() { + return ( + + + + ) +} diff --git a/test/integration/react-streaming-and-server-components/test/index.test.js b/test/integration/react-streaming-and-server-components/test/index.test.js index d8dcfe043d2ea..4a6ca0119a0ac 100644 --- a/test/integration/react-streaming-and-server-components/test/index.test.js +++ b/test/integration/react-streaming-and-server-components/test/index.test.js @@ -253,6 +253,40 @@ async function runBasicTests(context) { expect(html).toContain('bar.server.js:') expect(html).toContain('foo.client') }) + + it('should support streaming', async () => { + await fetchViaHTTP(context.appPort, '/streaming', null, {}).then( + async (response) => { + let result = '' + let gotFallback = false + let gotData = false + + await new Promise((resolve) => { + response.body.on('data', (chunk) => { + result += chunk.toString() + + gotData = result.includes('next_streaming_data') + if (!gotFallback) { + gotFallback = result.includes('next_streaming_fallback') + if (gotFallback) { + expect(gotData).toBe(false) + } + } + }) + + response.body.on('end', () => resolve()) + }) + + expect(gotFallback).toBe(true) + expect(gotData).toBe(true) + } + ) + + // Should end up with "next_streaming_data". + const browser = await webdriver(context.appPort, '/streaming') + const content = await browser.eval(`window.document.body.innerText`) + expect(content).toMatchInlineSnapshot('"next_streaming_data"') + }) } function runSuite(suiteName, env, { runTests, before, after }) {