Skip to content

test: adjust assertions for /_not-found being possibly added to prerender manifest #3043

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

Merged
merged 1 commit into from
Aug 12, 2025
Merged
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
61 changes: 35 additions & 26 deletions tests/integration/cache-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import {
getBlobEntries,
startMockBlobStore,
} from '../utils/helpers.js'
import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
import {
nextVersionSatisfies,
shouldHaveAppRouterNotFoundInPrerenderManifest,
} from '../utils/next-version-helpers.mjs'

// Disable the verbose logging of the lambda-local runtime
getLogger().level = 'alert'
Expand Down Expand Up @@ -212,14 +215,17 @@ describe('app router', () => {
console.timeEnd('runPlugin')
// check if the blob entries where successful set on the build plugin
const blobEntries = await getBlobEntries(ctx)
expect(blobEntries.map(({ key }) => decodeBlobKey(key)).sort()).toEqual([
'/404',
'/index',
'/posts/1',
'/posts/2',
'404.html',
'500.html',
])
expect(blobEntries.map(({ key }) => decodeBlobKey(key)).sort()).toEqual(
[
'/404',
shouldHaveAppRouterNotFoundInPrerenderManifest() ? '/_not-found' : undefined,
'/index',
'/posts/1',
'/posts/2',
'404.html',
'500.html',
].filter(Boolean),
)

// test the function call
const post1 = await invokeFunction(ctx, { url: 'posts/1' })
Expand Down Expand Up @@ -362,23 +368,26 @@ describe('plugin', () => {
await runPlugin(ctx)
// check if the blob entries where successful set on the build plugin
const blobEntries = await getBlobEntries(ctx)
expect(blobEntries.map(({ key }) => decodeBlobKey(key)).sort()).toEqual([
'/404',
'/api/revalidate-handler',
'/api/static/first',
'/api/static/second',
'/api/zero-length-response',
'/index',
'/product/事前レンダリング,test',
'/revalidate-fetch',
'/static-fetch-1',
'/static-fetch-2',
'/static-fetch-3',
'/static-fetch/1',
'/static-fetch/2',
'404.html',
'500.html',
])
expect(blobEntries.map(({ key }) => decodeBlobKey(key)).sort()).toEqual(
[
'/404',
shouldHaveAppRouterNotFoundInPrerenderManifest() ? '/_not-found' : undefined,
'/api/revalidate-handler',
'/api/static/first',
'/api/static/second',
'/api/zero-length-response',
'/index',
'/product/事前レンダリング,test',
'/revalidate-fetch',
'/static-fetch-1',
'/static-fetch-2',
'/static-fetch-3',
'/static-fetch/1',
'/static-fetch/2',
'404.html',
'500.html',
].filter(Boolean),
)
})
})

Expand Down
63 changes: 36 additions & 27 deletions tests/integration/simple-app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ import {
getBlobEntries,
startMockBlobStore,
} from '../utils/helpers.js'
import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
import {
nextVersionSatisfies,
shouldHaveAppRouterNotFoundInPrerenderManifest,
} from '../utils/next-version-helpers.mjs'

const mockedCp = cp as Mock<(typeof import('node:fs/promises'))['cp']>

Expand Down Expand Up @@ -95,26 +98,29 @@ test<FixtureTestContext>('Test that the simple next app is working', async (ctx)
await runPlugin(ctx)
// check if the blob entries where successful set on the build plugin
const blobEntries = await getBlobEntries(ctx)
expect(blobEntries.map(({ key }) => decodeBlobKey(key)).sort()).toEqual([
'/404',
'/api/cached-permanent',
'/api/cached-revalidate',
'/config-redirect',
'/config-redirect/dest',
'/config-rewrite',
'/config-rewrite/dest',
'/image/local',
'/image/migration-from-v4-runtime',
'/image/remote-domain',
'/image/remote-pattern-1',
'/image/remote-pattern-2',
'/index',
'/other',
'/route-resolves-to-not-found',
'404.html',
'500.html',
'fully-static.html',
])
expect(blobEntries.map(({ key }) => decodeBlobKey(key)).sort()).toEqual(
[
'/404',
shouldHaveAppRouterNotFoundInPrerenderManifest() ? '/_not-found' : undefined,
'/api/cached-permanent',
'/api/cached-revalidate',
'/config-redirect',
'/config-redirect/dest',
'/config-rewrite',
'/config-rewrite/dest',
'/image/local',
'/image/migration-from-v4-runtime',
'/image/remote-domain',
'/image/remote-pattern-1',
'/image/remote-pattern-2',
'/index',
'/other',
'/route-resolves-to-not-found',
'404.html',
'500.html',
'fully-static.html',
].filter(Boolean),
)

// test the function call
const home = await invokeFunction(ctx)
Expand Down Expand Up @@ -385,12 +391,15 @@ test.skipIf(process.env.NEXT_VERSION !== 'canary')<FixtureTestContext>(
await runPlugin(ctx)
// check if the blob entries where successful set on the build plugin
const blobEntries = await getBlobEntries(ctx)
expect(blobEntries.map(({ key }) => decodeBlobKey(key)).sort()).toEqual([
'/404',
'/index',
'404.html',
'500.html',
])
expect(blobEntries.map(({ key }) => decodeBlobKey(key)).sort()).toEqual(
[
'/404',
shouldHaveAppRouterNotFoundInPrerenderManifest() ? '/_not-found' : undefined,
'/index',
'404.html',
'500.html',
].filter(Boolean),
)

// test the function call
const home = await invokeFunction(ctx)
Expand Down
14 changes: 14 additions & 0 deletions tests/utils/next-version-helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ export function nextVersionSatisfies(condition) {
return satisfies(checkVersion, condition, { includePrerelease: true }) || version === condition
}

export function isNextCanary() {
return [process.env.NEXT_RESOLVED_VERSION, process.env.NEXT_VERSION].some((tagOrVersionOrEmpty) =>
tagOrVersionOrEmpty?.includes('canary'),
)
}

export function shouldHaveAppRouterNotFoundInPrerenderManifest() {
// https://github.com/vercel/next.js/pull/82199

// The canary versions are out of band, as there stable/latest patch versions higher than base of canary versions
// and change was not backported to stable versions
return nextVersionSatisfies('>=15.4.2-canary.33') && isNextCanary()
}

Comment on lines +33 to +40
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really annoying and frankly bad check that will likely need to be adjusted once that change is released in stable, but to me it feels better than doing some kind of filtering in tests themselves. At least it will be somewhat explicit of what full list of generated blobs are (...depending on next version :/ )

/**
* Check if current next version requires React 19
* @param {string} version Next version
Expand Down
Loading