Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unstable_suspense -> suspense, add concurrent tests
- Loading branch information
Showing
9 changed files
with
109 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
...prerelease/components/dynamic-suspense.js → ...18/prerelease/components/dynamic-hello.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test/integration/react-18/prerelease/pages/suspense/no-thrown.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import DynamicSuspense from '../../components/dynamic-suspense' | ||
import Hello from '../../components/dynamic-hello' | ||
|
||
export default function NoThrown() { | ||
return <DynamicSuspense thrown={false} /> | ||
return <Hello thrown={false} /> | ||
} |
4 changes: 2 additions & 2 deletions
4
test/integration/react-18/prerelease/pages/suspense/thrown.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import DynamicSuspense from '../../components/dynamic-suspense' | ||
import DynamicHello from '../../components/dynamic-hello' | ||
|
||
export default function Thrown() { | ||
return <DynamicSuspense thrown /> | ||
return <DynamicHello thrown /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { join } from 'path' | ||
import webdriver from 'next-webdriver' | ||
import cheerio from 'cheerio' | ||
import { File, check } from 'next-test-utils' | ||
|
||
export default (context, render) => { | ||
const dynamicHello = new File( | ||
join(context.appDir, 'components/dynamic-hello.js') | ||
) | ||
const nextConfig = new File(join(context.appDir, 'next.config.js')) | ||
|
||
async function get$(path, query) { | ||
const html = await render(path, query) | ||
return cheerio.load(html) | ||
} | ||
|
||
describe('concurrentFeatures is enabled', () => { | ||
beforeAll(() => { | ||
dynamicHello.replace('const suspense = false', `const suspense = true`) | ||
nextConfig.replace( | ||
'concurrentFeatures: false', | ||
'concurrentFeatures: true' | ||
) | ||
}) | ||
afterAll(() => { | ||
dynamicHello.restore() | ||
nextConfig.restore() | ||
}) | ||
|
||
it('should render the fallback on server side if not suspended on server', async () => { | ||
const $ = await get$('/suspense/no-thrown') | ||
const html = $('body').html() | ||
expect(html).toContain('loading') | ||
expect(JSON.parse($('#__NEXT_DATA__').text()).dynamicIds).toBeUndefined() | ||
}) | ||
|
||
it('should render the fallback on server side if suspended on server', async () => { | ||
const $ = await get$('/suspense/thrown') | ||
const html = $('body').html() | ||
expect(html).toContain('loading') | ||
expect(JSON.parse($('#__NEXT_DATA__').text()).dynamicIds).toBeUndefined() | ||
}) | ||
|
||
it('should hydrate suspenses on client side if suspended on server', async () => { | ||
let browser | ||
try { | ||
browser = await webdriver(context.appPort, '/suspense/thrown') | ||
await check(() => browser.elementByCss('body').text(), /hello/) | ||
} finally { | ||
if (browser) { | ||
await browser.close() | ||
} | ||
} | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters