-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
Inline tests for integration/react-18 #65199
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...tegration/react-18/app/components/red.tsx → ...ct-current-version/app/components/red.tsx
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
147 changes: 147 additions & 0 deletions
147
test/integration/react-current-version/test/index.test.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 |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/* eslint-env jest */ | ||
|
||
import { join } from 'path' | ||
|
||
import cheerio from 'cheerio' | ||
import { | ||
check, | ||
File, | ||
renderViaHTTP, | ||
runDevSuite, | ||
runProdSuite, | ||
} from 'next-test-utils' | ||
import webdriver from 'next-webdriver' | ||
|
||
const appDir = join(__dirname, '../app') | ||
const indexPage = new File(join(appDir, 'pages/index.js')) | ||
|
||
describe('Basics', () => { | ||
runTests('default setting', (context, env) => { | ||
it('should only render once in SSR', async () => { | ||
await renderViaHTTP(context.appPort, '/') | ||
expect([...context.stdout.matchAll(/__render__/g)].length).toBe(1) | ||
}) | ||
|
||
it('no warnings for image related link props', async () => { | ||
await renderViaHTTP(context.appPort, '/') | ||
expect(context.stderr).not.toContain('Warning: Invalid DOM property') | ||
expect(context.stderr).not.toContain('Warning: React does not recognize') | ||
}) | ||
|
||
it('hydrates correctly for normal page', async () => { | ||
const browser = await webdriver(context.appPort, '/') | ||
expect(await browser.eval('window.didHydrate')).toBe(true) | ||
expect(await browser.elementById('react-dom-version').text()).toMatch( | ||
/18/ | ||
) | ||
}) | ||
|
||
it('useId() values should match on hydration', async () => { | ||
const html = await renderViaHTTP(context.appPort, '/use-id') | ||
const $ = cheerio.load(html) | ||
const ssrId = $('#id').text() | ||
|
||
const browser = await webdriver(context.appPort, '/use-id') | ||
const csrId = await browser.eval( | ||
'document.getElementById("id").innerText' | ||
) | ||
|
||
expect(ssrId).toEqual(csrId) | ||
}) | ||
|
||
it('should contain dynamicIds in next data for dynamic imports', async () => { | ||
async function expectToContainPreload(page) { | ||
const html = await renderViaHTTP(context.appPort, `/${page}`) | ||
const $ = cheerio.load(html) | ||
const { dynamicIds } = JSON.parse($('#__NEXT_DATA__').html()) | ||
|
||
if (env === 'dev') { | ||
expect( | ||
dynamicIds.find((id) => | ||
id.includes(`pages/${page}.js -> ../components/foo`) | ||
) | ||
).toBeTruthy() | ||
} else { | ||
expect(dynamicIds.length).toBe(1) | ||
} | ||
} | ||
await expectToContainPreload('dynamic') | ||
await expectToContainPreload('dynamic-suspense') | ||
}) | ||
}) | ||
}) | ||
|
||
function runTestsAgainstRuntime(runtime) { | ||
runTests( | ||
`Concurrent mode in the ${runtime} runtime`, | ||
(context, env) => { | ||
async function withBrowser(path, cb) { | ||
let browser | ||
try { | ||
browser = await webdriver(context.appPort, path) | ||
await cb(browser) | ||
} finally { | ||
if (browser) { | ||
await browser.close() | ||
} | ||
} | ||
} | ||
|
||
it('flushes styled-jsx styles as the page renders', async () => { | ||
const html = await renderViaHTTP( | ||
context.appPort, | ||
'/use-flush-effect/styled-jsx' | ||
) | ||
const stylesOccurrence = html.match(/color:(\s)*(?:blue|#00f)/g) || [] | ||
expect(stylesOccurrence.length).toBe(1) | ||
|
||
await withBrowser('/use-flush-effect/styled-jsx', async (browser) => { | ||
await check( | ||
() => browser.waitForElementByCss('#__jsx-900f996af369fc74').text(), | ||
/(?:blue|#00f)/ | ||
) | ||
await check( | ||
() => browser.waitForElementByCss('#__jsx-8b0811664c4e575e').text(), | ||
/red/ | ||
) | ||
}) | ||
}) | ||
|
||
describe('<RouteAnnouncer />', () => { | ||
it('should not have the initial route announced', async () => { | ||
const browser = await webdriver(context.appPort, '/') | ||
const title = await browser | ||
.waitForElementByCss('#__next-route-announcer__') | ||
.text() | ||
|
||
expect(title).toBe('') | ||
}) | ||
}) | ||
|
||
it('should not have invalid config warning', async () => { | ||
await renderViaHTTP(context.appPort, '/') | ||
expect(context.stderr).not.toContain('not exist in this version') | ||
}) | ||
}, | ||
{ | ||
beforeAll: (env) => { | ||
indexPage.replace( | ||
"// runtime: 'experimental-edge'", | ||
`runtime: '${runtime}'` | ||
) | ||
}, | ||
afterAll: (env) => { | ||
indexPage.restore() | ||
}, | ||
} | ||
) | ||
} | ||
|
||
runTestsAgainstRuntime('experimental-edge') | ||
runTestsAgainstRuntime('nodejs') | ||
|
||
function runTests(name, fn, opts) { | ||
const suiteOptions = { ...opts, runTests: fn } | ||
runDevSuite(name, appDir, suiteOptions) | ||
runProdSuite(name, appDir, suiteOptions) | ||
} |
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,24 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2017", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": false, | ||
"noEmit": true, | ||
"incremental": true, | ||
"module": "esnext", | ||
"esModuleInterop": true, | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve", | ||
"plugins": [ | ||
{ | ||
"name": "next" | ||
} | ||
] | ||
}, | ||
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"], | ||
"exclude": ["node_modules"] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can make it a e2e test and specify the version? And we can test both 18 and 19 beta?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we planning to support 18 and 19 in Next.js?