Skip to content

Commit

Permalink
test: add test for basic dynamic import with react 18 hydration (#35772)
Browse files Browse the repository at this point in the history
x-ref: #35728

The hydration mismatch is fixed by #35732, that document could collect the dyamic imports module ids before the shell is flushed. Add a test for it
  • Loading branch information
huozhi committed Mar 31, 2022
1 parent fbfe430 commit 612cc88
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions test/integration/react-18/app/components/foo.js
@@ -0,0 +1 @@
export default () => 'foo'
9 changes: 9 additions & 0 deletions test/integration/react-18/app/pages/dynamic-imports.js
@@ -0,0 +1,9 @@
import dynamic from 'next/dynamic'

const Foo = dynamic(() => import('../components/foo'))

export default () => (
<div>
<Foo />
</div>
)
14 changes: 13 additions & 1 deletion test/integration/react-18/test/basics.js
Expand Up @@ -4,7 +4,7 @@ import webdriver from 'next-webdriver'
import cheerio from 'cheerio'
import { renderViaHTTP } from 'next-test-utils'

export default (context) => {
export default (context, env) => {
it('no warnings for image related link props', async () => {
await renderViaHTTP(context.appPort, '/')
expect(context.stderr).not.toContain('Warning: Invalid DOM property')
Expand All @@ -27,4 +27,16 @@ export default (context) => {

expect(ssrId).toEqual(csrId)
})

it('should contain dynamicIds in next data for basic dynamic imports', async () => {
const html = await renderViaHTTP(context.appPort, '/dynamic-imports')
const $ = cheerio.load(html)
const { dynamicIds } = JSON.parse($('#__NEXT_DATA__').html())

if (env === 'dev') {
expect(dynamicIds).toContain('dynamic-imports.js -> ../components/foo')
} else {
expect(dynamicIds.length).toBe(1)
}
})
}
4 changes: 3 additions & 1 deletion test/integration/react-18/test/index.test.js
Expand Up @@ -25,7 +25,9 @@ const nextConfig = new File(join(appDir, 'next.config.js'))
const invalidPage = new File(join(appDir, 'pages/invalid.js'))

describe('Basics', () => {
runTests('default setting with react 18', (context) => basics(context))
runTests('default setting with react 18', (context, env) =>
basics(context, env)
)
})

// React 18 with Strict Mode enabled might cause double invocation of lifecycle methods.
Expand Down

0 comments on commit 612cc88

Please sign in to comment.