Add integration test for Suspense and streaming (#31197)
Adds a test to ensure that `<Suspense>` and streaming are working properly with `concurrentFeatures` enabled. ## Bug - [ ] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `yarn lint`
This commit is contained in:
parent
a0a08ae9e5
commit
57b4134c88
2 changed files with 57 additions and 0 deletions
23
test/integration/react-streaming-and-server-components/app/pages/streaming.js
vendored
Normal file
23
test/integration/react-streaming-and-server-components/app/pages/streaming.js
vendored
Normal file
|
@ -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 (
|
||||
<Suspense fallback="next_streaming_fallback">
|
||||
<Data />
|
||||
</Suspense>
|
||||
)
|
||||
}
|
|
@ -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 }) {
|
||||
|
|
Loading…
Reference in a new issue