Unverified Commit 7ac4eae0 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub
parent 3f9f403a
import { runErrorRecoveryHmrTest } from './run-error-recovery-hmr-test.util'
const nextConfig = { basePath: '', assetPrefix: '' }
describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () => {
runErrorRecoveryHmrTest(nextConfig)
})
import { runErrorRecoveryHmrTest } from './run-error-recovery-hmr-test.util'
const nextConfig = { basePath: '', assetPrefix: '/asset-prefix' }
describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () => {
runErrorRecoveryHmrTest(nextConfig)
})
import { runErrorRecoveryHmrTest } from './run-error-recovery-hmr-test.util'
const nextConfig = { basePath: '/docs', assetPrefix: '' }
describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () => {
runErrorRecoveryHmrTest(nextConfig)
})
import { runErrorRecoveryHmrTest } from './run-error-recovery-hmr-test.util'
const nextConfig = { basePath: '/docs', assetPrefix: '/asset-prefix' }
describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () => {
runErrorRecoveryHmrTest(nextConfig)
})
import type { NextConfig } from 'next'
import { join } from 'path'
import {
assertHasRedbox,
......@@ -15,99 +14,95 @@ import {
import { nextTestSetup } from 'e2e-utils'
import { outdent } from 'outdent'
describe.each([
{ basePath: '', assetPrefix: '' },
{ basePath: '', assetPrefix: '/asset-prefix' },
{ basePath: '/docs', assetPrefix: '' },
{ basePath: '/docs', assetPrefix: '/asset-prefix' },
])(
'HMR - Error Recovery, nextConfig: %o',
(nextConfig: Partial<NextConfig>) => {
const { next } = nextTestSetup({
files: __dirname,
nextConfig,
patchFileDelay: 500,
})
const { basePath } = nextConfig
export function runErrorRecoveryHmrTest(nextConfig: {
basePath: string
assetPrefix: string
}) {
const { next } = nextTestSetup({
files: __dirname,
nextConfig,
patchFileDelay: 500,
})
const { basePath } = nextConfig
it('should recover from 404 after a page has been added', async () => {
const newPage = join('pages', 'hmr', 'new-page.js')
try {
const browser = await next.browser(basePath + '/hmr/new-page')
expect(await browser.elementByCss('body').text()).toMatch(
/This page could not be found/
)
it('should recover from 404 after a page has been added', async () => {
const newPage = join('pages', 'hmr', 'new-page.js')
// Add the page
await next.patchFile(
newPage,
'export default () => (<div id="new-page">the-new-page</div>)'
)
try {
const browser = await next.browser(basePath + '/hmr/new-page')
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(/the-new-page/)
})
await next.deleteFile(newPage)
expect(await browser.elementByCss('body').text()).toMatch(
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This page could not be found/
)
})
// Add the page
await next.patchFile(
newPage,
'export default () => (<div id="new-page">the-new-page</div>)'
)
expect(next.cliOutput).toContain('Compiled /_error')
} catch (err) {
await next.deleteFile(newPage)
throw err
}
})
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(/the-new-page/)
})
it('should recover from 404 after a page has been added with dynamic segments', async () => {
const newPage = join('pages', 'hmr', '[foo]', 'page.js')
await next.deleteFile(newPage)
try {
const browser = await next.browser(basePath + '/hmr/foo/page')
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This page could not be found/
)
})
expect(await browser.elementByCss('body').text()).toMatch(
/This page could not be found/
)
expect(next.cliOutput).toContain('Compiled /_error')
} catch (err) {
await next.deleteFile(newPage)
throw err
}
})
// Add the page
await next.patchFile(
newPage,
'export default () => (<div id="new-page">the-new-page</div>)'
)
it('should recover from 404 after a page has been added with dynamic segments', async () => {
const newPage = join('pages', 'hmr', '[foo]', 'page.js')
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(/the-new-page/)
})
try {
const browser = await next.browser(basePath + '/hmr/foo/page')
await next.deleteFile(newPage)
expect(await browser.elementByCss('body').text()).toMatch(
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This page could not be found/
)
})
// Add the page
await next.patchFile(
newPage,
'export default () => (<div id="new-page">the-new-page</div>)'
)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(/the-new-page/)
})
await next.deleteFile(newPage)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This page could not be found/
)
})
expect(next.cliOutput).toContain('Compiled /_error')
} catch (err) {
await next.deleteFile(newPage)
throw err
}
})
;(process.env.IS_TURBOPACK_TEST ? it.skip : it)(
// this test fails frequently with turbopack
'should not continously poll a custom error page',
async () => {
const errorPage = join('pages', '_error.js')
await next.patchFile(
errorPage,
outdent`
expect(next.cliOutput).toContain('Compiled /_error')
} catch (err) {
await next.deleteFile(newPage)
throw err
}
})
;(process.env.IS_TURBOPACK_TEST ? it.skip : it)(
// this test fails frequently with turbopack
'should not continously poll a custom error page',
async () => {
const errorPage = join('pages', '_error.js')
await next.patchFile(
errorPage,
outdent`
function Error({ statusCode, message, count }) {
return (
<div>
......@@ -127,52 +122,50 @@ describe.each([
export default Error
`
)
)
try {
// navigate to a 404 page
await next.browser(basePath + '/does-not-exist')
try {
// navigate to a 404 page
await next.browser(basePath + '/does-not-exist')
await retry(() => {
// eslint-disable-next-line jest/no-standalone-expect
expect(next.cliOutput).toMatch(/getInitialProps called/)
})
await retry(() => {
// eslint-disable-next-line jest/no-standalone-expect
expect(next.cliOutput).toMatch(/getInitialProps called/)
})
const outputIndex = next.cliOutput.length
const outputIndex = next.cliOutput.length
// wait a few seconds to ensure polling didn't happen
await waitFor(3000)
// wait a few seconds to ensure polling didn't happen
await waitFor(3000)
const logOccurrences =
next.cliOutput.slice(outputIndex).split('getInitialProps called')
.length - 1
// eslint-disable-next-line jest/no-standalone-expect
expect(logOccurrences).toBe(0)
} finally {
await next.deleteFile(errorPage)
}
const logOccurrences =
next.cliOutput.slice(outputIndex).split('getInitialProps called')
.length - 1
// eslint-disable-next-line jest/no-standalone-expect
expect(logOccurrences).toBe(0)
} finally {
await next.deleteFile(errorPage)
}
)
it('should detect syntax errors and recover', async () => {
const browser = await next.browser(basePath + '/hmr/about2')
const aboutPage = join('pages', 'hmr', 'about2.js')
const aboutContent = await next.readFile(aboutPage)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
}
)
it('should detect syntax errors and recover', async () => {
const browser = await next.browser(basePath + '/hmr/about2')
const aboutPage = join('pages', 'hmr', 'about2.js')
const aboutContent = await next.readFile(aboutPage)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
await next.patchFile(aboutPage, aboutContent.replace('</div>', 'div'))
await next.patchFile(aboutPage, aboutContent.replace('</div>', 'div'))
await assertHasRedbox(browser)
const source = next.normalizeTestDirContent(
await getRedboxSource(browser)
)
await assertHasRedbox(browser)
const source = next.normalizeTestDirContent(await getRedboxSource(browser))
if (basePath === '' && process.env.IS_TURBOPACK_TEST) {
expect(source).toMatchInlineSnapshot(`
if (basePath === '' && process.env.IS_TURBOPACK_TEST) {
expect(source).toMatchInlineSnapshot(`
"./pages/hmr/about2.js (7:1)
Parsing ecmascript source code failed
5 | div
......@@ -183,8 +176,8 @@ describe.each([
Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`?"
`)
} else if (basePath === '' && process.env.NEXT_RSPACK) {
expect(trimEndMultiline(source)).toMatchInlineSnapshot(`
} else if (basePath === '' && process.env.NEXT_RSPACK) {
expect(trimEndMultiline(source)).toMatchInlineSnapshot(`
"./pages/hmr/about2.js
× Module build failed:
├─▶ ×
......@@ -210,8 +203,8 @@ describe.each([
Import trace for requested module:
./pages/hmr/about2.js"
`)
} else if (basePath === '') {
expect(source).toMatchInlineSnapshot(`
} else if (basePath === '') {
expect(source).toMatchInlineSnapshot(`
"./pages/hmr/about2.js
Error: x Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`?
,-[7:1]
......@@ -234,8 +227,8 @@ describe.each([
Import trace for requested module:
./pages/hmr/about2.js"
`)
} else if (basePath === '/docs' && process.env.IS_TURBOPACK_TEST) {
expect(source).toMatchInlineSnapshot(`
} else if (basePath === '/docs' && process.env.IS_TURBOPACK_TEST) {
expect(source).toMatchInlineSnapshot(`
"./pages/hmr/about2.js (7:1)
Parsing ecmascript source code failed
5 | div
......@@ -246,8 +239,8 @@ describe.each([
Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`?"
`)
} else if (basePath === '/docs' && process.env.NEXT_RSPACK) {
expect(trimEndMultiline(source)).toMatchInlineSnapshot(`
} else if (basePath === '/docs' && process.env.NEXT_RSPACK) {
expect(trimEndMultiline(source)).toMatchInlineSnapshot(`
"./pages/hmr/about2.js
× Module build failed:
├─▶ ×
......@@ -273,8 +266,8 @@ describe.each([
Import trace for requested module:
./pages/hmr/about2.js"
`)
} else if (basePath === '/docs') {
expect(source).toMatchInlineSnapshot(`
} else if (basePath === '/docs') {
expect(source).toMatchInlineSnapshot(`
"./pages/hmr/about2.js
Error: x Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`?
,-[7:1]
......@@ -297,297 +290,297 @@ describe.each([
Import trace for requested module:
./pages/hmr/about2.js"
`)
}
}
await next.patchFile(aboutPage, aboutContent)
await next.patchFile(aboutPage, aboutContent)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
})
if (!process.env.IS_TURBOPACK_TEST) {
// Turbopack doesn't have this restriction
it('should show the error on all pages', async () => {
const aboutPage = join('pages', 'hmr', 'about2.js')
const aboutContent = await next.readFile(aboutPage)
const browser = await next.browser(basePath + '/hmr/contact')
try {
await renderViaHTTP(next.url, basePath + '/hmr/about2')
if (!process.env.IS_TURBOPACK_TEST) {
// Turbopack doesn't have this restriction
it('should show the error on all pages', async () => {
const aboutPage = join('pages', 'hmr', 'about2.js')
const aboutContent = await next.readFile(aboutPage)
const browser = await next.browser(basePath + '/hmr/contact')
try {
await renderViaHTTP(next.url, basePath + '/hmr/about2')
await next.patchFile(aboutPage, aboutContent.replace('</div>', 'div'))
await next.patchFile(aboutPage, aboutContent.replace('</div>', 'div'))
// Ensure dev server has time to break:
await new Promise((resolve) => setTimeout(resolve, 2000))
// Ensure dev server has time to break:
await new Promise((resolve) => setTimeout(resolve, 2000))
await assertHasRedbox(browser)
expect(await getRedboxSource(browser)).toMatch(/Unexpected eof/)
await assertHasRedbox(browser)
expect(await getRedboxSource(browser)).toMatch(/Unexpected eof/)
await next.patchFile(aboutPage, aboutContent)
await next.patchFile(aboutPage, aboutContent)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the contact page/
)
})
} catch (err) {
await next.patchFile(aboutPage, aboutContent)
if (browser) {
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the contact page/
)
})
} catch (err) {
await next.patchFile(aboutPage, aboutContent)
if (browser) {
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the contact page/
)
})
}
throw err
}
})
}
it('should detect runtime errors on the module scope', async () => {
const browser = await next.browser(basePath + '/hmr/about3')
const aboutPage = join('pages', 'hmr', 'about3.js')
const aboutContent = await next.readFile(aboutPage)
try {
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
throw err
}
})
}
await next.patchFile(
aboutPage,
aboutContent.replace('export', 'aa=20;\nexport')
it('should detect runtime errors on the module scope', async () => {
const browser = await next.browser(basePath + '/hmr/about3')
const aboutPage = join('pages', 'hmr', 'about3.js')
const aboutContent = await next.readFile(aboutPage)
try {
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
await assertHasRedbox(browser)
expect(await getRedboxHeader(browser)).toMatch(/aa is not defined/)
await next.patchFile(
aboutPage,
aboutContent.replace('export', 'aa=20;\nexport')
)
await next.patchFile(aboutPage, aboutContent)
await assertHasRedbox(browser)
expect(await getRedboxHeader(browser)).toMatch(/aa is not defined/)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
} finally {
await next.patchFile(aboutPage, aboutContent)
}
})
await next.patchFile(aboutPage, aboutContent)
it('should recover from errors in the render function', async () => {
const browser = await next.browser(basePath + '/hmr/about4')
const aboutPage = join('pages', 'hmr', 'about4.js')
const aboutContent = await next.readFile(aboutPage)
try {
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
} finally {
await next.patchFile(aboutPage, aboutContent)
}
})
await next.patchFile(
aboutPage,
aboutContent.replace(
'return',
'throw new Error("an-expected-error");\nreturn'
)
it('should recover from errors in the render function', async () => {
const browser = await next.browser(basePath + '/hmr/about4')
const aboutPage = join('pages', 'hmr', 'about4.js')
const aboutContent = await next.readFile(aboutPage)
try {
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
await assertHasRedbox(browser)
expect(await getRedboxSource(browser)).toMatch(/an-expected-error/)
await next.patchFile(
aboutPage,
aboutContent.replace(
'return',
'throw new Error("an-expected-error");\nreturn'
)
)
await next.patchFile(aboutPage, aboutContent)
await assertHasRedbox(browser)
expect(await getRedboxSource(browser)).toMatch(/an-expected-error/)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
} catch (err) {
await next.patchFile(aboutPage, aboutContent)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
await next.patchFile(aboutPage, aboutContent)
throw err
}
})
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
} catch (err) {
await next.patchFile(aboutPage, aboutContent)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
it('should recover after exporting an invalid page', async () => {
const browser = await next.browser(basePath + '/hmr/about5')
const aboutPage = join('pages', 'hmr', 'about5.js')
const aboutContent = await next.readFile(aboutPage)
try {
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
throw err
}
})
await next.patchFile(
aboutPage,
aboutContent.replace(
'export default',
'export default {};\nexport const fn ='
)
it('should recover after exporting an invalid page', async () => {
const browser = await next.browser(basePath + '/hmr/about5')
const aboutPage = join('pages', 'hmr', 'about5.js')
const aboutContent = await next.readFile(aboutPage)
try {
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
await assertHasRedbox(browser)
expect(await getRedboxDescription(browser)).toMatchInlineSnapshot(
`"The default export is not a React Component in page: "/hmr/about5""`
await next.patchFile(
aboutPage,
aboutContent.replace(
'export default',
'export default {};\nexport const fn ='
)
)
await next.patchFile(aboutPage, aboutContent)
await assertHasRedbox(browser)
expect(await getRedboxDescription(browser)).toMatchInlineSnapshot(
`"The default export is not a React Component in page: "/hmr/about5""`
)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
} catch (err) {
await next.patchFile(aboutPage, aboutContent)
await next.patchFile(aboutPage, aboutContent)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
} catch (err) {
await next.patchFile(aboutPage, aboutContent)
throw err
}
})
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
it('should recover after a bad return from the render function', async () => {
const browser = await next.browser(basePath + '/hmr/about6')
const aboutPage = join('pages', 'hmr', 'about6.js')
const aboutContent = await next.readFile(aboutPage)
try {
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
throw err
}
})
await next.patchFile(
aboutPage,
aboutContent.replace(
'export default',
'export default () => /search/;\nexport const fn ='
)
it('should recover after a bad return from the render function', async () => {
const browser = await next.browser(basePath + '/hmr/about6')
const aboutPage = join('pages', 'hmr', 'about6.js')
const aboutContent = await next.readFile(aboutPage)
try {
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
await assertHasRedbox(browser)
// TODO: Replace this when webpack 5 is the default
expect(await getRedboxHeader(browser)).toMatch(
`Objects are not valid as a React child (found: [object RegExp]). If you meant to render a collection of children, use an array instead.`
await next.patchFile(
aboutPage,
aboutContent.replace(
'export default',
'export default () => /search/;\nexport const fn ='
)
)
await next.patchFile(aboutPage, aboutContent)
await assertHasRedbox(browser)
// TODO: Replace this when webpack 5 is the default
expect(await getRedboxHeader(browser)).toMatch(
`Objects are not valid as a React child (found: [object RegExp]). If you meant to render a collection of children, use an array instead.`
)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
} catch (err) {
await next.patchFile(aboutPage, aboutContent)
await next.patchFile(aboutPage, aboutContent)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
} catch (err) {
await next.patchFile(aboutPage, aboutContent)
throw err
}
})
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
it('should recover after undefined exported as default', async () => {
const browser = await next.browser(basePath + '/hmr/about7')
const aboutPage = join('pages', 'hmr', 'about7.js')
throw err
}
})
const aboutContent = await next.readFile(aboutPage)
try {
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
it('should recover after undefined exported as default', async () => {
const browser = await next.browser(basePath + '/hmr/about7')
const aboutPage = join('pages', 'hmr', 'about7.js')
await next.patchFile(
aboutPage,
aboutContent.replace(
'export default',
'export default undefined;\nexport const fn ='
)
const aboutContent = await next.readFile(aboutPage)
try {
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
await assertHasRedbox(browser)
expect(await getRedboxDescription(browser)).toMatchInlineSnapshot(
`"The default export is not a React Component in page: "/hmr/about7""`
await next.patchFile(
aboutPage,
aboutContent.replace(
'export default',
'export default undefined;\nexport const fn ='
)
)
await next.patchFile(aboutPage, aboutContent)
await assertHasRedbox(browser)
expect(await getRedboxDescription(browser)).toMatchInlineSnapshot(
`"The default export is not a React Component in page: "/hmr/about7""`
)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
await assertNoRedbox(browser)
} catch (err) {
await next.patchFile(aboutPage, aboutContent)
await next.patchFile(aboutPage, aboutContent)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
await assertNoRedbox(browser)
} catch (err) {
await next.patchFile(aboutPage, aboutContent)
throw err
}
})
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
it('should recover after webpack parse error in an imported file', async () => {
const browser = await next.browser(basePath + '/hmr/about8')
const aboutPage = join('pages', 'hmr', 'about8.js')
throw err
}
})
const aboutContent = await next.readFile(aboutPage)
try {
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
it('should recover after webpack parse error in an imported file', async () => {
const browser = await next.browser(basePath + '/hmr/about8')
const aboutPage = join('pages', 'hmr', 'about8.js')
await next.patchFile(
aboutPage,
aboutContent.replace(
'export default',
'import "../../components/parse-error.xyz"\nexport default'
)
const aboutContent = await next.readFile(aboutPage)
try {
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
await assertHasRedbox(browser)
expect(await getRedboxHeader(browser)).toMatch('Build Error')
await next.patchFile(
aboutPage,
aboutContent.replace(
'export default',
'import "../../components/parse-error.xyz"\nexport default'
)
)
await assertHasRedbox(browser)
expect(await getRedboxHeader(browser)).toMatch('Build Error')
if (process.env.IS_TURBOPACK_TEST) {
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
if (process.env.IS_TURBOPACK_TEST) {
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
"./components/parse-error.xyz
Unknown module type
This module doesn't have an associated type. Use a known file extension, or register a loader for it.
Read more: https://nextjs.org/docs/app/api-reference/next-config-js/turbo#webpack-loaders"
`)
} else if (process.env.NEXT_RSPACK) {
expect(trimEndMultiline(await getRedboxSource(browser)))
.toMatchInlineSnapshot(`
} else if (process.env.NEXT_RSPACK) {
expect(trimEndMultiline(await getRedboxSource(browser)))
.toMatchInlineSnapshot(`
"./components/parse-error.xyz
× Module parse failed:
╰─▶ × JavaScript parsing error: Expression expected
......@@ -607,8 +600,8 @@ describe.each([
./components/parse-error.xyz
./pages/hmr/about8.js"
`)
} else {
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
} else {
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
"./components/parse-error.xyz
Module parse failed: Unexpected token (3:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
......@@ -622,57 +615,57 @@ describe.each([
./components/parse-error.xyz
./pages/hmr/about8.js"
`)
}
}
await next.patchFile(aboutPage, aboutContent)
await next.patchFile(aboutPage, aboutContent)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
await assertNoRedbox(browser)
} catch (err) {
await next.patchFile(aboutPage, aboutContent)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
await assertNoRedbox(browser)
} catch (err) {
await next.patchFile(aboutPage, aboutContent)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
throw err
}
})
throw err
}
})
it('should recover after loader parse error in an imported file', async () => {
const browser = await next.browser(basePath + '/hmr/about9')
const aboutPage = join('pages', 'hmr', 'about9.js')
it('should recover after loader parse error in an imported file', async () => {
const browser = await next.browser(basePath + '/hmr/about9')
const aboutPage = join('pages', 'hmr', 'about9.js')
const aboutContent = await next.readFile(aboutPage)
try {
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
const aboutContent = await next.readFile(aboutPage)
try {
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
await next.patchFile(
aboutPage,
aboutContent.replace(
'export default',
'import "../../components/parse-error.js"\nexport default'
)
await next.patchFile(
aboutPage,
aboutContent.replace(
'export default',
'import "../../components/parse-error.js"\nexport default'
)
)
await assertHasRedbox(browser)
expect(await getRedboxHeader(browser)).toMatch('Build Error')
let redboxSource = await getRedboxSource(browser)
await assertHasRedbox(browser)
expect(await getRedboxHeader(browser)).toMatch('Build Error')
let redboxSource = await getRedboxSource(browser)
redboxSource = redboxSource.replace(`${next.testDir}`, '.')
if (process.env.IS_TURBOPACK_TEST) {
expect(next.normalizeTestDirContent(redboxSource))
.toMatchInlineSnapshot(`
redboxSource = redboxSource.replace(`${next.testDir}`, '.')
if (process.env.IS_TURBOPACK_TEST) {
expect(next.normalizeTestDirContent(redboxSource))
.toMatchInlineSnapshot(`
"./components/parse-error.js (3:1)
Parsing ecmascript source code failed
1 | This
......@@ -684,9 +677,9 @@ describe.each([
Expression expected"
`)
} else if (process.env.NEXT_RSPACK) {
expect(trimEndMultiline(next.normalizeTestDirContent(redboxSource)))
.toMatchInlineSnapshot(`
} else if (process.env.NEXT_RSPACK) {
expect(trimEndMultiline(next.normalizeTestDirContent(redboxSource)))
.toMatchInlineSnapshot(`
"./components/parse-error.js
× Module build failed:
├─▶ ×
......@@ -707,14 +700,11 @@ describe.each([
./components/parse-error.js
./pages/hmr/about9.js"
`)
} else {
redboxSource = redboxSource.substring(
0,
redboxSource.indexOf('`----')
)
} else {
redboxSource = redboxSource.substring(0, redboxSource.indexOf('`----'))
expect(next.normalizeTestDirContent(redboxSource))
.toMatchInlineSnapshot(`
expect(next.normalizeTestDirContent(redboxSource))
.toMatchInlineSnapshot(`
"./components/parse-error.js
Error: x Expression expected
,-[3:1]
......@@ -726,117 +716,116 @@ describe.each([
5 | js
"
`)
}
await next.patchFile(aboutPage, aboutContent)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
await assertNoRedbox(browser)
} catch (err) {
await next.patchFile(aboutPage, aboutContent)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
}
})
it('should recover from errors in getInitialProps in client', async () => {
const browser = await next.browser(basePath + '/hmr')
const erroredPage = join('pages', 'hmr', 'error-in-gip.js')
const errorContent = await next.readFile(erroredPage)
try {
await browser.elementByCss('#error-in-gip-link').click()
await next.patchFile(aboutPage, aboutContent)
await assertHasRedbox(browser)
expect(await getRedboxDescription(browser)).toMatchInlineSnapshot(
`"an-expected-error-in-gip"`
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
await assertNoRedbox(browser)
} catch (err) {
await next.patchFile(aboutPage, aboutContent)
await next.patchFile(
erroredPage,
errorContent.replace('throw error', 'return {}')
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(
/This is the about page/
)
})
}
})
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(/Hello/)
})
it('should recover from errors in getInitialProps in client', async () => {
const browser = await next.browser(basePath + '/hmr')
const erroredPage = join('pages', 'hmr', 'error-in-gip.js')
const errorContent = await next.readFile(erroredPage)
try {
await browser.elementByCss('#error-in-gip-link').click()
await next.patchFile(erroredPage, errorContent)
await assertHasRedbox(browser)
expect(await getRedboxDescription(browser)).toMatchInlineSnapshot(
`"an-expected-error-in-gip"`
)
await retry(async () => {
await browser.refresh()
await waitFor(2000)
const text = await getBrowserBodyText(browser)
if (text.includes('Hello')) {
throw new Error('waiting')
}
return expect(await getRedboxSource(browser)).toMatch(
/an-expected-error-in-gip/
)
})
} catch (err) {
await next.patchFile(erroredPage, errorContent)
await next.patchFile(
erroredPage,
errorContent.replace('throw error', 'return {}')
)
throw err
}
})
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(/Hello/)
})
it('should recover after an error reported via SSR', async () => {
const browser = await next.browser(basePath + '/hmr/error-in-gip')
const erroredPage = join('pages', 'hmr', 'error-in-gip.js')
const errorContent = await next.readFile(erroredPage)
try {
await assertHasRedbox(browser)
expect(await getRedboxDescription(browser)).toMatchInlineSnapshot(
`"an-expected-error-in-gip"`
await next.patchFile(erroredPage, errorContent)
await retry(async () => {
await browser.refresh()
await waitFor(2000)
const text = await getBrowserBodyText(browser)
if (text.includes('Hello')) {
throw new Error('waiting')
}
return expect(await getRedboxSource(browser)).toMatch(
/an-expected-error-in-gip/
)
})
} catch (err) {
await next.patchFile(erroredPage, errorContent)
const erroredPage = join('pages', 'hmr', 'error-in-gip.js')
throw err
}
})
await next.patchFile(
erroredPage,
errorContent.replace('throw error', 'return {}')
)
it('should recover after an error reported via SSR', async () => {
const browser = await next.browser(basePath + '/hmr/error-in-gip')
const erroredPage = join('pages', 'hmr', 'error-in-gip.js')
const errorContent = await next.readFile(erroredPage)
try {
await assertHasRedbox(browser)
expect(await getRedboxDescription(browser)).toMatchInlineSnapshot(
`"an-expected-error-in-gip"`
)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(/Hello/)
})
const erroredPage = join('pages', 'hmr', 'error-in-gip.js')
await next.patchFile(erroredPage, errorContent)
await next.patchFile(
erroredPage,
errorContent.replace('throw error', 'return {}')
)
await retry(async () => {
await browser.refresh()
await waitFor(2000)
const text = await getBrowserBodyText(browser)
if (text.includes('Hello')) {
throw new Error('waiting')
}
return expect(await getRedboxSource(browser)).toMatch(
/an-expected-error-in-gip/
)
})
} catch (err) {
await next.patchFile(erroredPage, errorContent)
await retry(async () => {
expect(await getBrowserBodyText(browser)).toMatch(/Hello/)
})
throw err
}
})
await next.patchFile(erroredPage, errorContent)
if (!process.env.IS_TURBOPACK_TEST) {
it('should have client HMR events in trace file', async () => {
const traceData = await next.readFile('.next/trace')
expect(traceData).toContain('client-hmr-latency')
expect(traceData).toContain('client-error')
expect(traceData).toContain('client-success')
expect(traceData).toContain('client-full-reload')
await retry(async () => {
await browser.refresh()
await waitFor(2000)
const text = await getBrowserBodyText(browser)
if (text.includes('Hello')) {
throw new Error('waiting')
}
return expect(await getRedboxSource(browser)).toMatch(
/an-expected-error-in-gip/
)
})
} catch (err) {
await next.patchFile(erroredPage, errorContent)
throw err
}
})
if (!process.env.IS_TURBOPACK_TEST) {
it('should have client HMR events in trace file', async () => {
const traceData = await next.readFile('.next/trace')
expect(traceData).toContain('client-hmr-latency')
expect(traceData).toContain('client-error')
expect(traceData).toContain('client-success')
expect(traceData).toContain('client-full-reload')
})
}
)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment