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:
Shu Ding 2021-11-09 13:46:45 +01:00 committed by GitHub
parent a0a08ae9e5
commit 57b4134c88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 0 deletions

View 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>
)
}

View file

@ -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 }) {