Unverified Commit 5fb2dc15 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Add determinism test for static shell with asset preload headers (#89826)

```
  ● deterministic build - changing deployment id › build output API - cacheComponents adapter › should produce identical build outputs even when changing deployment id

    File content mismatch for .next/prerender-manifest.json in .vercel/output/functions/[variants].func/.vc-config.json

    - Expected
    + Received

    @@ -80,5 +80,5 @@
          "/abc": {
            "initialHeaders": {
    -         "link": "</_next/static/media/caa3a2e1cccd8315-s.p.853070df.woff2>; rel=preload; as=\"font\"; crossorigin=\"\"; type=\"font/woff2\", </_next/static/chunks/55fd2813a6ce3e20.css?dpl=foo-dpl-id>; rel=preload; as=\"style\"",
    +         "link": "</_next/static/media/caa3a2e1cccd8315-s.p.853070df.woff2>; rel=preload; as=\"font\"; crossorigin=\"\"; type=\"font/woff2\", </_next/static/chunks/55fd2813a6ce3e20.css?dpl=bar-dpl-id>; rel=preload; as=\"style\"",
              "x-nextjs-stale-time": "300",
              "x-nextjs-prerender": "1",

```
parent ccad4853
'use client'
export const Client = ({ children }) => {
const value = Date.now()
return (
<div>
{value}
{children}
</div>
)
}
import { Suspense } from 'react'
import { Geist } from 'next/font/google'
import './styles.css'
import { Client } from './client'
const geistSans = Geist({
variable: '--font-geist-sans',
subsets: ['latin'],
})
export default async function DynamicRootLayout(props) {
await props.params
return (
<html>
<head>
<Suspense>
<meta />
</Suspense>
</head>
<body className={geistSans.variable}>
<Client>{props.children}</Client>
</body>
</html>
)
}
export function generateStaticParams() {
return [{ variants: 'abc' }]
}
import { connection } from 'next/server'
export default async function InternalDesignPage() {
await connection()
return <div>hi</div>
}
/** @type {import("next").NextConfig} */
module.exports = {
cacheComponents: true,
experimental: {
// Enable these when debugging to get readable diffs
// turbopackMinify: false,
// turbopackModuleIds: 'named',
// turbopackScopeHoisting: false,
},
}
...@@ -117,14 +117,17 @@ async function runTest( ...@@ -117,14 +117,17 @@ async function runTest(
next: NextInstance, next: NextInstance,
readFiles: (next: NextInstance) => Promise<Map<string, Map<string, string>>> readFiles: (next: NextInstance) => Promise<Map<string, Map<string, string>>>
) { ) {
// Same for both builds
next.env['__NEXT_IMMUTABLE_ASSET_TOKEN'] = 'imm-token'
// First build // First build
next.env['NEXT_DEPLOYMENT_ID'] = 'foo-dpl-id' next.env['NEXT_DEPLOYMENT_ID'] = 'foo-dpl-id'
await next.build() expect((await next.build()).exitCode).toBe(0)
let run1 = await readFiles(next) let run1 = await readFiles(next)
// Second build // Second build
next.env['NEXT_DEPLOYMENT_ID'] = 'bar-dpl-id' next.env['NEXT_DEPLOYMENT_ID'] = 'bar-dpl-id'
await next.build() expect((await next.build()).exitCode).toBe(0)
let run2 = await readFiles(next) let run2 = await readFiles(next)
// First, compare file names // First, compare file names
...@@ -178,29 +181,36 @@ async function runTest( ...@@ -178,29 +181,36 @@ async function runTest(
} }
const FILES = { const FILES = {
app: new FileRef(path.join(__dirname, 'app')), standard: {
pages: new FileRef(path.join(__dirname, 'pages')), app: new FileRef(path.join(__dirname, 'standard', 'app')),
public: new FileRef(path.join(__dirname, 'public')), pages: new FileRef(path.join(__dirname, 'standard', 'pages')),
'instrumentation.ts': new FileRef(path.join(__dirname, 'instrumentation.ts')), public: new FileRef(path.join(__dirname, 'standard', 'public')),
'middleware.ts': new FileRef(path.join(__dirname, 'middleware.ts')), 'instrumentation.ts': new FileRef(
'next.config.js': `module.exports = { path.join(__dirname, 'standard', 'instrumentation.ts')
experimental: { ),
// Enable these when debugging to get readable diffs 'middleware.ts': new FileRef(
// turbopackMinify: false, path.join(__dirname, 'standard', 'middleware.ts')
// turbopackModuleIds: 'named', ),
// turbopackScopeHoisting: false, 'next.config.js': new FileRef(
}, path.join(__dirname, 'standard', 'next.config.js')
}`, ),
},
cacheComponents: {
app: new FileRef(path.join(__dirname, 'cache-components', 'app')),
'next.config.js': new FileRef(
path.join(__dirname, 'cache-components', 'next.config.js')
),
},
} }
// Webpack itself isn't deterministic // Webpack itself isn't deterministic
;(process.env.IS_TURBOPACK_TEST ? describe : describe.skip)( ;(process.env.IS_TURBOPACK_TEST ? describe : describe.skip)(
'deterministic build - changing deployment id', 'deterministic build - changing deployment id',
() => { () => {
describe('.next folder', () => { describe('standard - .next folder', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
files: { files: {
...FILES, ...FILES.standard,
}, },
env: { env: {
NOW_BUILDER: '1', NOW_BUILDER: '1',
...@@ -215,15 +225,20 @@ const FILES = { ...@@ -215,15 +225,20 @@ const FILES = {
}) })
}) })
describe.each(['builder', 'adapter'])('build output API - %s', (mode) => { describe.each([
{ test: 'standard', mode: 'builder' },
{ test: 'standard', mode: 'adapter' },
{ test: 'cacheComponents', mode: 'builder' },
{ test: 'cacheComponents', mode: 'adapter' },
])('build output API - $test $mode', ({ test, mode }) => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
files: { files: {
// A mock file to be able to run `vercel build` without logging in // A mock file to be able to run `vercel build` without logging in
'.vercel/project.json': `{ "projectId": "prj_", "orgId": "team_", "settings": {} }`, '.vercel/project.json': `{ "projectId": "prj_", "orgId": "team_", "settings": {} }`,
...FILES, ...FILES[test],
}, },
dependencies: { dependencies: {
vercel: '>=50.13.2', vercel: 'latest',
}, },
packageJson: { packageJson: {
scripts: { scripts: {
...@@ -247,18 +262,22 @@ const FILES = { ...@@ -247,18 +262,22 @@ const FILES = {
it('should produce identical build outputs even when changing deployment id', async () => { it('should produce identical build outputs even when changing deployment id', async () => {
let { run1, run2 } = await runTest(next, readFilesBuilder) let { run1, run2 } = await runTest(next, readFilesBuilder)
expect([...run1.keys()]).toIncludeAllMembers([ expect(run1.size).toBeGreaterThan(0)
'.vercel/output/functions/app-page.func/.vc-config.json',
'.vercel/output/functions/app-page.rsc.func/.vc-config.json',
'.vercel/output/functions/app-route.func/.vc-config.json',
'.vercel/output/functions/app-route.rsc.func/.vc-config.json',
'.vercel/output/functions/pages-dynamic.func/.vc-config.json',
'.vercel/output/functions/pages-static-gsp.func/.vc-config.json',
])
expect([...run1.keys()]).toSatisfyAny((k) =>
k.includes('middleware.func')
)
expect([...run1.keys()]).toEqual([...run2.keys()]) expect([...run1.keys()]).toEqual([...run2.keys()])
if (test === 'standard') {
expect([...run1.keys()]).toIncludeAllMembers([
'.vercel/output/functions/app-page.func/.vc-config.json',
'.vercel/output/functions/app-page.rsc.func/.vc-config.json',
'.vercel/output/functions/app-route.func/.vc-config.json',
'.vercel/output/functions/app-route.rsc.func/.vc-config.json',
'.vercel/output/functions/pages-dynamic.func/.vc-config.json',
'.vercel/output/functions/pages-static-gsp.func/.vc-config.json',
])
expect([...run1.keys()]).toSatisfyAny((k) =>
k.includes('middleware.func')
)
}
}) })
}) })
} }
......
import './styles.css'
export default function Layout({ children }) { export default function Layout({ children }) {
return ( return (
<html> <html>
......
body {
background-image: url(./test.jpg);
}
/** @type {import("next").NextConfig} */
module.exports = {
experimental: {
// Enable these when debugging to get readable diffs
// turbopackMinify: false,
// turbopackModuleIds: 'named',
// turbopackScopeHoisting: false,
},
}
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