Commit 1a9ee198 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig

Improve `should encode chunk path correctly` test

parent 347adf54
...@@ -13,26 +13,25 @@ import { ...@@ -13,26 +13,25 @@ import {
const isPPREnabledByDefault = process.env.__NEXT_EXPERIMENTAL_PPR === 'true' const isPPREnabledByDefault = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
describe('app dir - basic', () => { describe('app dir - basic', () => {
const { next, isNextDev, isNextStart, isNextDeploy, isTurbopack } = const { next, isNextDev, isNextStart, isNextDeploy } = nextTestSetup({
nextTestSetup({ files: __dirname,
files: __dirname, buildCommand: process.env.NEXT_EXPERIMENTAL_COMPILE
buildCommand: process.env.NEXT_EXPERIMENTAL_COMPILE ? 'pnpm compile-mode'
? 'pnpm compile-mode' : undefined,
: undefined, packageJson: {
packageJson: { scripts: {
scripts: { 'compile-mode': process.env.NEXT_EXPERIMENTAL_COMPILE
'compile-mode': process.env.NEXT_EXPERIMENTAL_COMPILE ? `next build --experimental-build-mode=compile && next build --experimental-build-mode=generate-env`
? `next build --experimental-build-mode=compile && next build --experimental-build-mode=generate-env` : undefined,
: undefined,
},
},
dependencies: {
nanoid: '4.0.1',
},
env: {
NEXT_PUBLIC_TEST_ID: Date.now() + '',
}, },
}) },
dependencies: {
nanoid: '4.0.1',
},
env: {
NEXT_PUBLIC_TEST_ID: Date.now() + '',
},
})
if (isNextStart) { if (isNextStart) {
it('should have correct cache-control for SSR routes', async () => { it('should have correct cache-control for SSR routes', async () => {
...@@ -169,32 +168,32 @@ describe('app dir - basic', () => { ...@@ -169,32 +168,32 @@ describe('app dir - basic', () => {
}) })
} }
// Turbopack has different chunking in dev/production which results in the entrypoint name not being included in the outputs. it('should encode chunk path correctly', async () => {
if (!process.env.IS_TURBOPACK_TEST) { const requests = []
it('should encode chunk path correctly', async () => { const browser = await next.browser('/dynamic-client/first/second', {
await next.fetch('/dynamic-client/first/second') beforePageLoad(page) {
const browser = await next.browser('/') page.on('request', (req) => {
const requests = [] requests.push(req.url())
browser.on('request', (req) => { })
requests.push(req.url()) },
}) })
await browser.eval( await browser.waitForElementByCss('#id-page-params')
'window.location.href = "/dynamic-client/first/second"'
)
await browser.waitForElementByCss('#id-page-params') expect(requests).not.toEqual(
expect.arrayContaining([expect.stringContaining('[category]')])
)
expect( // Turbopack doesn't recreate the original folder structure for the output chunks
requests.some( if (!process.env.IS_TURBOPACK_TEST) {
(req) => expect(requests).toEqual(
req.includes( // e.g. _next/static/chunks/app/dynamic-client/%5Bcategory%5D/%5Bid%5D/page-6e188d657a208f8e.js
encodeURI(isTurbopack ? '[category]_[id]' : '/[category]/[id]') expect.arrayContaining([
) && req.includes('.js') expect.stringMatching(/.*%5Bcategory%5D\/%5Bid%5D.*\.js$/),
) ])
).toBe(true) )
}) }
} })
it.each([ it.each([
{ pathname: '/redirect-1' }, { pathname: '/redirect-1' },
...@@ -393,7 +392,7 @@ describe('app dir - basic', () => { ...@@ -393,7 +392,7 @@ describe('app dir - basic', () => {
it('should serve polyfills for browsers that do not support modules', async () => { it('should serve polyfills for browsers that do not support modules', async () => {
const html = await next.render('/dashboard/index') const html = await next.render('/dashboard/index')
expect(html).toMatch( expect(html).toMatch(
isTurbopack process.env.IS_TURBOPACK_TEST
? /<script src="\/_next\/static\/chunks\/([\w-]*polyfill-nomodule|[0-9a-f]+)\.js" noModule="">/ ? /<script src="\/_next\/static\/chunks\/([\w-]*polyfill-nomodule|[0-9a-f]+)\.js" noModule="">/
: /<script src="\/_next\/static\/chunks\/polyfills(-\w+)?\.js" noModule="">/ : /<script src="\/_next\/static\/chunks\/polyfills(-\w+)?\.js" noModule="">/
) )
......
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