Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test for basic dynamic import with react 18 hydration #35772

Merged
merged 1 commit into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions test/integration/react-18/app/components/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => 'foo'
9 changes: 9 additions & 0 deletions test/integration/react-18/app/pages/dynamic-imports.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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