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: replace duplicate test utils to next instance #73624

Open
wants to merge 1 commit into
base: 12-07-test_split_hot_module_reload_hmr_test_into_multiple_files
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
getRedboxHeader,
getRedboxDescription,
getRedboxSource,
renderViaHTTP,
retry,
waitFor,
} from 'next-test-utils'
Expand All @@ -16,7 +15,7 @@ import { outdent } from 'outdent'
const nextConfig = { basePath: '', assetPrefix: '' }

describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () => {
const { next } = nextTestSetup({
const { next, isTurbopack } = nextTestSetup({
files: join(__dirname, '../../fixtures'),
nextConfig,
patchFileDelay: 500,
Expand Down Expand Up @@ -92,7 +91,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =
throw err
}
})
;(process.env.TURBOPACK ? it.skip : it)(
;(isTurbopack ? it.skip : it)(
// this test fails frequently with turbopack
'should not continously poll a custom error page',
async () => {
Expand Down Expand Up @@ -161,7 +160,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =

await assertHasRedbox(browser)
const source = next.normalizeTestDirContent(await getRedboxSource(browser))
if (basePath === '' && !process.env.TURBOPACK) {
if (basePath === '' && !isTurbopack) {
expect(source).toMatchInlineSnapshot(`
"./pages/hmr/about2.js
Error: x Unexpected token. Did you mean \`{'}'}\` or \`}\`?
Expand All @@ -185,7 +184,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =
Import trace for requested module:
./pages/hmr/about2.js"
`)
} else if (basePath === '' && process.env.TURBOPACK) {
} else if (basePath === '' && isTurbopack) {
expect(source).toMatchInlineSnapshot(`
"./pages/hmr/about2.js:7:1
Parsing ecmascript source code failed
Expand All @@ -197,7 +196,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =

Unexpected token. Did you mean \`{'}'}\` or \`}\`?"
`)
} else if (basePath === '/docs' && !process.env.TURBOPACK) {
} else if (basePath === '/docs' && !isTurbopack) {
expect(source).toMatchInlineSnapshot(`
"./pages/hmr/about2.js
Error: x Unexpected token. Did you mean \`{'}'}\` or \`}\`?
Expand All @@ -221,7 +220,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =
Import trace for requested module:
./pages/hmr/about2.js"
`)
} else if (basePath === '/docs' && process.env.TURBOPACK) {
} else if (basePath === '/docs' && isTurbopack) {
expect(source).toMatchInlineSnapshot(`
"./pages/hmr/about2.js:7:1
Parsing ecmascript source code failed
Expand All @@ -244,14 +243,14 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =
})
})

if (!process.env.TURBOPACK) {
if (!isTurbopack) {
// 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.render(basePath + '/hmr/about2')

await next.patchFile(aboutPage, aboutContent.replace('</div>', 'div'))

Expand Down Expand Up @@ -513,7 +512,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =
await assertHasRedbox(browser)
expect(await getRedboxHeader(browser)).toMatch('Failed to compile')

if (process.env.TURBOPACK) {
if (isTurbopack) {
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
"./components/parse-error.xyz
Unknown module type
Expand Down Expand Up @@ -583,7 +582,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =
let redboxSource = await getRedboxSource(browser)

redboxSource = redboxSource.replace(`${next.testDir}`, '.')
if (process.env.TURBOPACK) {
if (isTurbopack) {
expect(next.normalizeTestDirContent(redboxSource))
.toMatchInlineSnapshot(`
"./components/parse-error.js:3:1
Expand Down Expand Up @@ -716,7 +715,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =
}
})

if (!process.env.TURBOPACK) {
if (!isTurbopack) {
it('should have client HMR events in trace file', async () => {
const traceData = await next.readFile('.next/trace')
expect(traceData).toContain('client-hmr-latency')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
getRedboxHeader,
getRedboxDescription,
getRedboxSource,
renderViaHTTP,
retry,
waitFor,
} from 'next-test-utils'
Expand All @@ -16,7 +15,7 @@ import { outdent } from 'outdent'
const nextConfig = { basePath: '', assetPrefix: '/asset-prefix' }

describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () => {
const { next } = nextTestSetup({
const { next, isTurbopack } = nextTestSetup({
files: join(__dirname, '../../fixtures'),
nextConfig,
patchFileDelay: 500,
Expand Down Expand Up @@ -92,7 +91,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =
throw err
}
})
;(process.env.TURBOPACK ? it.skip : it)(
;(isTurbopack ? it.skip : it)(
// this test fails frequently with turbopack
'should not continously poll a custom error page',
async () => {
Expand Down Expand Up @@ -161,7 +160,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =

await assertHasRedbox(browser)
const source = next.normalizeTestDirContent(await getRedboxSource(browser))
if (basePath === '' && !process.env.TURBOPACK) {
if (basePath === '' && !isTurbopack) {
expect(source).toMatchInlineSnapshot(`
"./pages/hmr/about2.js
Error: x Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`?
Expand All @@ -185,7 +184,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =
Import trace for requested module:
./pages/hmr/about2.js"
`)
} else if (basePath === '' && process.env.TURBOPACK) {
} else if (basePath === '' && isTurbopack) {
expect(source).toMatchInlineSnapshot(`
"./pages/hmr/about2.js:7:1
Parsing ecmascript source code failed
Expand All @@ -197,7 +196,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =

Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`?"
`)
} else if (basePath === '/docs' && !process.env.TURBOPACK) {
} else if (basePath === '/docs' && !isTurbopack) {
expect(source).toMatchInlineSnapshot(`
"./pages/hmr/about2.js
Error: x Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`?
Expand All @@ -221,7 +220,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =
Import trace for requested module:
./pages/hmr/about2.js"
`)
} else if (basePath === '/docs' && process.env.TURBOPACK) {
} else if (basePath === '/docs' && isTurbopack) {
expect(source).toMatchInlineSnapshot(`
"./pages/hmr/about2.js:7:1
Parsing ecmascript source code failed
Expand All @@ -244,14 +243,14 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =
})
})

if (!process.env.TURBOPACK) {
if (!isTurbopack) {
// 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.render(basePath + '/hmr/about2')

await next.patchFile(aboutPage, aboutContent.replace('</div>', 'div'))

Expand Down Expand Up @@ -513,7 +512,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =
await assertHasRedbox(browser)
expect(await getRedboxHeader(browser)).toMatch('Failed to compile')

if (process.env.TURBOPACK) {
if (isTurbopack) {
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
"./components/parse-error.xyz
Unknown module type
Expand Down Expand Up @@ -583,7 +582,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =
let redboxSource = await getRedboxSource(browser)

redboxSource = redboxSource.replace(`${next.testDir}`, '.')
if (process.env.TURBOPACK) {
if (isTurbopack) {
expect(next.normalizeTestDirContent(redboxSource))
.toMatchInlineSnapshot(`
"./components/parse-error.js:3:1
Expand Down Expand Up @@ -716,7 +715,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =
}
})

if (!process.env.TURBOPACK) {
if (!isTurbopack) {
it('should have client HMR events in trace file', async () => {
const traceData = await next.readFile('.next/trace')
expect(traceData).toContain('client-hmr-latency')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
getRedboxHeader,
getRedboxDescription,
getRedboxSource,
renderViaHTTP,
retry,
waitFor,
} from 'next-test-utils'
Expand All @@ -16,7 +15,7 @@ import { outdent } from 'outdent'
const nextConfig = { basePath: '/docs', assetPrefix: '' }

describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () => {
const { next } = nextTestSetup({
const { next, isTurbopack } = nextTestSetup({
files: join(__dirname, '../../fixtures'),
nextConfig,
patchFileDelay: 500,
Expand Down Expand Up @@ -92,7 +91,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =
throw err
}
})
;(process.env.TURBOPACK ? it.skip : it)(
;(isTurbopack ? it.skip : it)(
// this test fails frequently with turbopack
'should not continously poll a custom error page',
async () => {
Expand Down Expand Up @@ -161,7 +160,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =

await assertHasRedbox(browser)
const source = next.normalizeTestDirContent(await getRedboxSource(browser))
if (basePath === '' && !process.env.TURBOPACK) {
if (basePath === '' && !isTurbopack) {
expect(source).toMatchInlineSnapshot(`
"./pages/hmr/about2.js
Error: x Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`?
Expand All @@ -185,7 +184,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =
Import trace for requested module:
./pages/hmr/about2.js"
`)
} else if (basePath === '' && process.env.TURBOPACK) {
} else if (basePath === '' && isTurbopack) {
expect(source).toMatchInlineSnapshot(`
"./pages/hmr/about2.js:7:1
Parsing ecmascript source code failed
Expand All @@ -197,7 +196,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =

Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`?"
`)
} else if (basePath === '/docs' && !process.env.TURBOPACK) {
} else if (basePath === '/docs' && !isTurbopack) {
expect(source).toMatchInlineSnapshot(`
"./pages/hmr/about2.js
Error: x Unexpected token. Did you mean \`{'}'}\` or \`&rbrace;\`?
Expand All @@ -221,7 +220,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =
Import trace for requested module:
./pages/hmr/about2.js"
`)
} else if (basePath === '/docs' && process.env.TURBOPACK) {
} else if (basePath === '/docs' && isTurbopack) {
expect(source).toMatchInlineSnapshot(`
"./pages/hmr/about2.js:7:1
Parsing ecmascript source code failed
Expand All @@ -244,14 +243,14 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =
})
})

if (!process.env.TURBOPACK) {
if (!isTurbopack) {
// 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.render(basePath + '/hmr/about2')

await next.patchFile(aboutPage, aboutContent.replace('</div>', 'div'))

Expand Down Expand Up @@ -513,7 +512,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =
await assertHasRedbox(browser)
expect(await getRedboxHeader(browser)).toMatch('Failed to compile')

if (process.env.TURBOPACK) {
if (isTurbopack) {
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
"./components/parse-error.xyz
Unknown module type
Expand Down Expand Up @@ -583,7 +582,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =
let redboxSource = await getRedboxSource(browser)

redboxSource = redboxSource.replace(`${next.testDir}`, '.')
if (process.env.TURBOPACK) {
if (isTurbopack) {
expect(next.normalizeTestDirContent(redboxSource))
.toMatchInlineSnapshot(`
"./components/parse-error.js:3:1
Expand Down Expand Up @@ -716,7 +715,7 @@ describe(`HMR - Error Recovery, nextConfig: ${JSON.stringify(nextConfig)}`, () =
}
})

if (!process.env.TURBOPACK) {
if (!isTurbopack) {
it('should have client HMR events in trace file', async () => {
const traceData = await next.readFile('.next/trace')
expect(traceData).toContain('client-hmr-latency')
Expand Down
Loading
Loading