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

Improve `should encode chunk path correctly` test

parent 347adf54
...@@ -13,8 +13,7 @@ import { ...@@ -13,8 +13,7 @@ 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'
...@@ -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.
if (!process.env.IS_TURBOPACK_TEST) {
it('should encode chunk path correctly', async () => { it('should encode chunk path correctly', async () => {
await next.fetch('/dynamic-client/first/second')
const browser = await next.browser('/')
const requests = [] const requests = []
browser.on('request', (req) => { const browser = await next.browser('/dynamic-client/first/second', {
beforePageLoad(page) {
page.on('request', (req) => {
requests.push(req.url()) requests.push(req.url())
}) })
},
await browser.eval( })
'window.location.href = "/dynamic-client/first/second"'
)
await browser.waitForElementByCss('#id-page-params') await browser.waitForElementByCss('#id-page-params')
expect( expect(requests).not.toEqual(
requests.some( expect.arrayContaining([expect.stringContaining('[category]')])
(req) => )
req.includes(
encodeURI(isTurbopack ? '[category]_[id]' : '/[category]/[id]') // Turbopack doesn't recreate the original folder structure for the output chunks
) && req.includes('.js') if (!process.env.IS_TURBOPACK_TEST) {
expect(requests).toEqual(
// e.g. _next/static/chunks/app/dynamic-client/%5Bcategory%5D/%5Bid%5D/page-6e188d657a208f8e.js
expect.arrayContaining([
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