Commit 497cbeaf authored by Tobias Koppers's avatar Tobias Koppers

Turbopack: add test case for react lazy in cache components

parent 18e7c84a
'use client'
export default function ClientComponent() {
return <p>Client Component</p>
}
import * as React from 'react'
import UnrelatedComponent from './unrelated'
const LazyClientComponent = React.lazy(() => import('./client'))
async function CachedComponent() {
'use cache'
return (
<>
<LazyClientComponent />
<UnrelatedComponent />
</>
)
}
export default function Page() {
return <CachedComponent />
}
'use client'
export default function UnrelatedComponent() {
return <section>Unrelated Component</section>
}
import { nextTestSetup } from 'e2e-utils'
import { assertNoRedbox, retry } from 'next-test-utils'
describe('cache-components', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
it('should load correctly', async () => {
const browser = await next.browser('/lazy')
expect(await browser.elementByCss('p').text()).toBe('Client Component')
})
if (isNextDev) {
it('should still work after changes', async () => {
{
const browser = await next.browser('/lazy')
expect(await browser.elementByCss('p').text()).toBe('Client Component')
expect(await browser.elementByCss('section').text()).toBe(
'Unrelated Component'
)
await next.patchFile(
'app/lazy/unrelated.tsx',
(content) =>
content.replace(
'Unrelated Component',
'Unrelated Changed Component'
),
async () => {
await retry(async () => {
expect(await browser.elementByCss('section').text()).toBe(
'Unrelated Changed Component'
)
expect(await browser.elementByCss('p').text()).toBe(
'Client Component'
)
assertNoRedbox(browser)
})
{
const browser = await next.browser('/lazy')
expect(await browser.elementByCss('p').text()).toBe(
'Client Component'
)
expect(await browser.elementByCss('section').text()).toBe(
'Unrelated Changed Component'
)
assertNoRedbox(browser)
}
}
)
}
{
const browser = await next.browser('/lazy')
expect(await browser.elementByCss('p').text()).toBe('Client Component')
expect(await browser.elementByCss('section').text()).toBe(
'Unrelated Component'
)
assertNoRedbox(browser)
}
})
}
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment