Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
278 lines
9.9 KiB
TypeScript
278 lines
9.9 KiB
TypeScript
import { join } from 'path'
|
|
import { getBrowserBodyText, retry, waitFor } from 'next-test-utils'
|
|
import { nextTestSetup } from 'e2e-utils'
|
|
|
|
export function runHotModuleReloadHmrTest(nextConfig: {
|
|
basePath: string
|
|
assetPrefix: string
|
|
}) {
|
|
const { next } = nextTestSetup({
|
|
files: __dirname,
|
|
nextConfig,
|
|
patchFileDelay: 500,
|
|
})
|
|
const { basePath } = nextConfig
|
|
|
|
describe('delete a page and add it back', () => {
|
|
it('should load the page properly', async () => {
|
|
const contactPagePath = join('pages', 'hmr', 'contact.js')
|
|
const newContactPagePath = join('pages', 'hmr', '_contact.js')
|
|
const browser = await next.browser(basePath + '/hmr/contact')
|
|
try {
|
|
const text = await browser.elementByCss('p').text()
|
|
expect(text).toBe('This is the contact page.')
|
|
|
|
expect(next.cliOutput).toMatch(/GET .*\/hmr\/contact 200/)
|
|
let cliOutputLength = next.cliOutput.length
|
|
|
|
// Rename the file to mimic a deleted page
|
|
await next.renameFile(contactPagePath, newContactPagePath)
|
|
|
|
await retry(async () => {
|
|
expect(await getBrowserBodyText(browser)).toMatch(
|
|
/This page could not be found/
|
|
)
|
|
})
|
|
expect(next.cliOutput.slice(cliOutputLength)).toMatch(
|
|
/GET .*\/hmr\/contact 404/
|
|
)
|
|
cliOutputLength = next.cliOutput.length
|
|
|
|
// Rename the file back to the original filename
|
|
await next.renameFile(newContactPagePath, contactPagePath)
|
|
|
|
// wait until the page comes back
|
|
await retry(async () => {
|
|
expect(await getBrowserBodyText(browser)).toMatch(
|
|
/This is the contact page/
|
|
)
|
|
})
|
|
expect(next.cliOutput.slice(cliOutputLength)).toMatch(
|
|
/GET .*\/hmr\/contact 200/
|
|
)
|
|
} finally {
|
|
await next
|
|
.renameFile(newContactPagePath, contactPagePath)
|
|
.catch(() => {})
|
|
}
|
|
})
|
|
})
|
|
|
|
describe('editing a page', () => {
|
|
it('should detect the changes and display it', async () => {
|
|
const browser = await next.browser(basePath + '/hmr/about')
|
|
const text = await browser.elementByCss('p').text()
|
|
expect(text).toBe('This is the about page.')
|
|
|
|
const aboutPagePath = join('pages', 'hmr', 'about.js')
|
|
|
|
const originalContent = await next.readFile(aboutPagePath)
|
|
const editedContent = originalContent.replace(
|
|
'This is the about page',
|
|
'COOL page'
|
|
)
|
|
|
|
// change the content
|
|
try {
|
|
await next.patchFile(aboutPagePath, editedContent)
|
|
await retry(async () => {
|
|
expect(await getBrowserBodyText(browser)).toMatch(/COOL page/)
|
|
})
|
|
} finally {
|
|
// add the original content
|
|
await next.patchFile(aboutPagePath, originalContent)
|
|
}
|
|
|
|
await retry(async () => {
|
|
expect(await getBrowserBodyText(browser)).toMatch(
|
|
/This is the about page/
|
|
)
|
|
})
|
|
})
|
|
|
|
it('should not reload unrelated pages', async () => {
|
|
const browser = await next.browser(basePath + '/hmr/counter')
|
|
const text = await browser
|
|
.elementByCss('button')
|
|
.click()
|
|
.elementByCss('button')
|
|
.click()
|
|
.elementByCss('p')
|
|
.text()
|
|
expect(text).toBe('COUNT: 2')
|
|
|
|
const aboutPagePath = join('pages', 'hmr', 'about.js')
|
|
|
|
const originalContent = await next.readFile(aboutPagePath)
|
|
const editedContent = originalContent.replace(
|
|
'This is the about page',
|
|
'COOL page'
|
|
)
|
|
|
|
try {
|
|
// Change the about.js page
|
|
await next.patchFile(aboutPagePath, editedContent)
|
|
|
|
// Check whether the this page has reloaded or not.
|
|
await retry(async () => {
|
|
expect(await browser.elementByCss('p').text()).toMatch(/COUNT: 2/)
|
|
})
|
|
} finally {
|
|
// restore the about page content.
|
|
await next.patchFile(aboutPagePath, originalContent)
|
|
}
|
|
})
|
|
|
|
// Added because of a regression in react-hot-loader, see issues: #4246 #4273
|
|
// Also: https://github.com/vercel/styled-jsx/issues/425
|
|
it('should update styles correctly', async () => {
|
|
const browser = await next.browser(basePath + '/hmr/style')
|
|
const pTag = await browser.elementByCss('.hmr-style-page p')
|
|
const initialFontSize = await pTag.getComputedCss('font-size')
|
|
|
|
expect(initialFontSize).toBe('100px')
|
|
|
|
const pagePath = join('pages', 'hmr', 'style.js')
|
|
|
|
const originalContent = await next.readFile(pagePath)
|
|
const editedContent = originalContent.replace('100px', '200px')
|
|
|
|
// Change the page
|
|
await next.patchFile(pagePath, editedContent)
|
|
|
|
try {
|
|
// Check whether the this page has reloaded or not.
|
|
await retry(async () => {
|
|
const editedPTag = await browser.elementByCss('.hmr-style-page p')
|
|
expect(await editedPTag.getComputedCss('font-size')).toBe('200px')
|
|
})
|
|
} finally {
|
|
// Finally is used so that we revert the content back to the original regardless of the test outcome
|
|
// restore the about page content.
|
|
await next.patchFile(pagePath, originalContent)
|
|
}
|
|
})
|
|
|
|
// Added because of a regression in react-hot-loader, see issues: #4246 #4273
|
|
// Also: https://github.com/vercel/styled-jsx/issues/425
|
|
it('should update styles in a stateful component correctly', async () => {
|
|
const browser = await next.browser(
|
|
basePath + '/hmr/style-stateful-component'
|
|
)
|
|
const pagePath = join('pages', 'hmr', 'style-stateful-component.js')
|
|
const originalContent = await next.readFile(pagePath)
|
|
try {
|
|
const pTag = await browser.elementByCss('.hmr-style-page p')
|
|
const initialFontSize = await pTag.getComputedCss('font-size')
|
|
|
|
expect(initialFontSize).toBe('100px')
|
|
const editedContent = originalContent.replace('100px', '200px')
|
|
|
|
// Change the page
|
|
await next.patchFile(pagePath, editedContent)
|
|
|
|
// Check whether the this page has reloaded or not.
|
|
await retry(async () => {
|
|
const editedPTag = await browser.elementByCss('.hmr-style-page p')
|
|
expect(await editedPTag.getComputedCss('font-size')).toBe('200px')
|
|
})
|
|
} finally {
|
|
await next.patchFile(pagePath, originalContent)
|
|
}
|
|
})
|
|
|
|
// Added because of a regression in react-hot-loader, see issues: #4246 #4273
|
|
// Also: https://github.com/vercel/styled-jsx/issues/425
|
|
it('should update styles in a dynamic component correctly', async () => {
|
|
const browser = await next.browser(
|
|
basePath + '/hmr/style-dynamic-component'
|
|
)
|
|
const secondBrowser = await next.browser(
|
|
basePath + '/hmr/style-dynamic-component'
|
|
)
|
|
const pagePath = join('components', 'hmr', 'dynamic.js')
|
|
const originalContent = await next.readFile(pagePath)
|
|
try {
|
|
const div = await browser.elementByCss('#dynamic-component')
|
|
const initialClientClassName = await div.getAttribute('class')
|
|
const initialFontSize = await div.getComputedCss('font-size')
|
|
|
|
expect(initialFontSize).toBe('100px')
|
|
|
|
const initialHtml = await next.render(
|
|
basePath + '/hmr/style-dynamic-component'
|
|
)
|
|
expect(initialHtml.includes('100px')).toBeTruthy()
|
|
|
|
const $initialHtml = await next.render$(
|
|
basePath + '/hmr/style-dynamic-component'
|
|
)
|
|
const initialServerClassName =
|
|
$initialHtml('#dynamic-component').attr('class')
|
|
|
|
expect(initialClientClassName === initialServerClassName).toBeTruthy()
|
|
|
|
const editedContent = originalContent.replace('100px', '200px')
|
|
|
|
// Change the page
|
|
await next.patchFile(pagePath, editedContent)
|
|
|
|
// wait for 5 seconds
|
|
await waitFor(5000)
|
|
|
|
// Check whether the this page has reloaded or not.
|
|
const editedDiv = await secondBrowser.elementByCss('#dynamic-component')
|
|
const editedClientClassName = await editedDiv.getAttribute('class')
|
|
const editedFontSize = await editedDiv.getComputedCss('font-size')
|
|
const browserHtml = await secondBrowser.eval(
|
|
'document.documentElement.innerHTML'
|
|
)
|
|
|
|
expect(editedFontSize).toBe('200px')
|
|
expect(browserHtml.includes('font-size:200px')).toBe(true)
|
|
expect(browserHtml.includes('font-size:100px')).toBe(false)
|
|
|
|
const editedHtml = await next.render(
|
|
basePath + '/hmr/style-dynamic-component'
|
|
)
|
|
expect(editedHtml.includes('200px')).toBeTruthy()
|
|
const $editedHtml = await next.render$(
|
|
basePath + '/hmr/style-dynamic-component'
|
|
)
|
|
const editedServerClassName =
|
|
$editedHtml('#dynamic-component').attr('class')
|
|
|
|
expect(editedClientClassName === editedServerClassName).toBe(true)
|
|
} finally {
|
|
// Finally is used so that we revert the content back to the original regardless of the test outcome
|
|
// restore the about page content.
|
|
await next.patchFile(pagePath, originalContent)
|
|
}
|
|
})
|
|
|
|
it('should not full reload when nonlatin characters are used', async () => {
|
|
const browser = await next.browser(basePath + '/hmr/nonlatin')
|
|
const pagePath = join('pages', 'hmr', 'nonlatin.js')
|
|
const originalContent = await next.readFile(pagePath)
|
|
try {
|
|
const timeOrigin = await browser.eval('performance.timeOrigin')
|
|
const editedContent = originalContent.replace(
|
|
'<div>テスト</div>',
|
|
'<div class="updated">テスト</div>'
|
|
)
|
|
|
|
// Change the page
|
|
await next.patchFile(pagePath, editedContent)
|
|
|
|
await browser.waitForElementByCss('.updated')
|
|
|
|
expect(await browser.eval('performance.timeOrigin')).toEqual(timeOrigin)
|
|
} finally {
|
|
// Finally is used so that we revert the content back to the original regardless of the test outcome
|
|
// restore the about page content.
|
|
await next.patchFile(pagePath, originalContent)
|
|
}
|
|
})
|
|
})
|
|
}
|