-
Notifications
You must be signed in to change notification settings - Fork 27.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test to assert on current build output tree view (#76342)
This allows us to better track fixes and changes to the build output tree view. To avoid flakiness, and needing to update the snapshots frequently, I've stubbed to file sizes and omitted the chunks from the snapshotted output. Because those details affect the column sizes, we can't just blank them out when reading the CLI output (which was [my first approach](d7ee6b4)). So instead, we already stub them during the generation of the output if `__NEXT_PRIVATE_DETERMINISTIC_BUILD_OUTPUT` is defined.
- Loading branch information
1 parent
b84bd52
commit 3d065cf
Showing
20 changed files
with
246 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
test/production/app-dir/build-output-tree-view/build-output-tree-view.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
import path from 'path' | ||
|
||
describe('build-output-tree-view', () => { | ||
describe('with mixed static and dynamic pages and app router routes', () => { | ||
const { next } = nextTestSetup({ | ||
files: path.join(__dirname, 'fixtures/mixed'), | ||
skipStart: true, | ||
env: { | ||
__NEXT_PRIVATE_DETERMINISTIC_BUILD_OUTPUT: '1', | ||
}, | ||
}) | ||
|
||
beforeAll(() => next.build()) | ||
|
||
it('should show info about prerendered and dynamic routes in a tree view', async () => { | ||
// TODO: Show cache info (revalidate/expire) for app router, and use the | ||
// same for pages router instead of the ISR addendum. | ||
|
||
// TODO: Fix double-listing of the /ppr/[slug] fallback. | ||
|
||
expect(getTreeView(next.cliOutput)).toMatchInlineSnapshot(` | ||
"Route (app) Size First Load JS | ||
┌ ○ /_not-found N/A kB N/A kB | ||
├ ƒ /api N/A kB N/A kB | ||
├ ○ /api/force-static N/A kB N/A kB | ||
├ ○ /app-static N/A kB N/A kB | ||
├ ○ /cache-life N/A kB N/A kB | ||
├ ƒ /dynamic N/A kB N/A kB | ||
├ ◐ /ppr/[slug] N/A kB N/A kB | ||
├ ├ /ppr/[slug] | ||
├ ├ /ppr/[slug] | ||
├ ├ /ppr/days | ||
├ └ /ppr/weeks | ||
└ ○ /revalidate N/A kB N/A kB | ||
+ First Load JS shared by all N/A kB | ||
Route (pages) Size First Load JS | ||
┌ ƒ /api/hello N/A kB N/A kB | ||
├ ● /gsp-revalidate (ISR: 300 Seconds) N/A kB N/A kB | ||
├ ƒ /gssp N/A kB N/A kB | ||
└ ○ /static N/A kB N/A kB | ||
+ First Load JS shared by all N/A kB | ||
○ (Static) prerendered as static content | ||
● (SSG) prerendered as static HTML (uses generateStaticParams) | ||
(ISR) incremental static regeneration (uses revalidate in generateStaticParams) | ||
◐ (Partial Prerender) prerendered as static HTML with dynamic server-streamed content | ||
ƒ (Dynamic) server-rendered on demand" | ||
`) | ||
}) | ||
}) | ||
|
||
describe('with only a few static routes', () => { | ||
const { next } = nextTestSetup({ | ||
files: path.join(__dirname, 'fixtures/minimal-static'), | ||
skipStart: true, | ||
env: { | ||
__NEXT_PRIVATE_DETERMINISTIC_BUILD_OUTPUT: '1', | ||
}, | ||
}) | ||
|
||
beforeAll(() => next.build()) | ||
|
||
it('should show info about prerendered routes in a compact tree view', async () => { | ||
expect(getTreeView(next.cliOutput)).toMatchInlineSnapshot(` | ||
"Route (app) Size First Load JS | ||
┌ ○ / N/A kB N/A kB | ||
└ ○ /_not-found N/A kB N/A kB | ||
+ First Load JS shared by all N/A kB | ||
Route (pages) Size First Load JS | ||
─ ○ /static N/A kB N/A kB | ||
+ First Load JS shared by all N/A kB | ||
○ (Static) prerendered as static content" | ||
`) | ||
}) | ||
}) | ||
}) | ||
|
||
function getTreeView(cliOutput: string): string { | ||
let foundBuildTracesLine = false | ||
const lines: string[] = [] | ||
|
||
for (const line of cliOutput.split('\n')) { | ||
if (foundBuildTracesLine) { | ||
lines.push(line) | ||
} | ||
|
||
foundBuildTracesLine ||= line.includes('Collecting build traces') | ||
} | ||
|
||
return lines.join('\n').trim() | ||
} |
8 changes: 8 additions & 0 deletions
8
test/production/app-dir/build-output-tree-view/fixtures/minimal-static/app/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ReactNode } from 'react' | ||
export default function Root({ children }: { children: ReactNode }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
test/production/app-dir/build-output-tree-view/fixtures/minimal-static/app/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return <p>hello world</p> | ||
} |
6 changes: 6 additions & 0 deletions
6
test/production/app-dir/build-output-tree-view/fixtures/minimal-static/next.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = {} | ||
|
||
module.exports = nextConfig |
3 changes: 3 additions & 0 deletions
3
test/production/app-dir/build-output-tree-view/fixtures/minimal-static/pages/static.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return <p>hello world</p> | ||
} |
5 changes: 5 additions & 0 deletions
5
test/production/app-dir/build-output-tree-view/fixtures/mixed/app/api/force-static/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const dynamic = 'force-static' | ||
|
||
export async function GET() { | ||
return Response.json({ message: 'hello world' }) | ||
} |
3 changes: 3 additions & 0 deletions
3
test/production/app-dir/build-output-tree-view/fixtures/mixed/app/api/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export async function GET() { | ||
return Response.json({ message: 'hello world' }) | ||
} |
3 changes: 3 additions & 0 deletions
3
test/production/app-dir/build-output-tree-view/fixtures/mixed/app/app-static/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return <p>hello world</p> | ||
} |
9 changes: 9 additions & 0 deletions
9
test/production/app-dir/build-output-tree-view/fixtures/mixed/app/cache-life/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use cache' | ||
|
||
import { unstable_cacheLife } from 'next/cache' | ||
|
||
export default async function Page() { | ||
unstable_cacheLife('weeks') | ||
|
||
return <p>hello world</p> | ||
} |
7 changes: 7 additions & 0 deletions
7
test/production/app-dir/build-output-tree-view/fixtures/mixed/app/dynamic/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { headers } from 'next/headers' | ||
|
||
export default async function Page() { | ||
await headers() | ||
|
||
return <p>hello world</p> | ||
} |
8 changes: 8 additions & 0 deletions
8
test/production/app-dir/build-output-tree-view/fixtures/mixed/app/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ReactNode } from 'react' | ||
export default function Root({ children }: { children: ReactNode }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
25 changes: 25 additions & 0 deletions
25
test/production/app-dir/build-output-tree-view/fixtures/mixed/app/ppr/[slug]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { unstable_cacheLife } from 'next/cache' | ||
|
||
type CacheLife = Parameters<typeof unstable_cacheLife>[0] | ||
|
||
async function getCachedValue(cacheLife: CacheLife) { | ||
'use cache' | ||
|
||
unstable_cacheLife(cacheLife) | ||
|
||
return Math.random() | ||
} | ||
|
||
export default async function Page({ | ||
params, | ||
}: { | ||
params: Promise<{ slug: CacheLife }> | ||
}) { | ||
const { slug } = await params | ||
|
||
return <p>hello world {await getCachedValue(slug)}</p> | ||
} | ||
|
||
export function generateStaticParams() { | ||
return [{ slug: 'days' }, { slug: 'weeks' }] | ||
} |
5 changes: 5 additions & 0 deletions
5
test/production/app-dir/build-output-tree-view/fixtures/mixed/app/revalidate/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const revalidate = 900 | ||
|
||
export default function Page() { | ||
return <p>hello world</p> | ||
} |
11 changes: 11 additions & 0 deletions
11
test/production/app-dir/build-output-tree-view/fixtures/mixed/next.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = { | ||
experimental: { | ||
useCache: true, | ||
ppr: true, | ||
}, | ||
} | ||
|
||
module.exports = nextConfig |
5 changes: 5 additions & 0 deletions
5
test/production/app-dir/build-output-tree-view/fixtures/mixed/pages/api/hello.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { NextApiRequest, NextApiResponse } from 'next' | ||
|
||
export default function handler(req: NextApiRequest, res: NextApiResponse) { | ||
res.status(200).json({ message: 'hello world' }) | ||
} |
7 changes: 7 additions & 0 deletions
7
test/production/app-dir/build-output-tree-view/fixtures/mixed/pages/gsp-revalidate.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Page() { | ||
return <p>hello world</p> | ||
} | ||
|
||
export async function getStaticProps() { | ||
return { props: {}, revalidate: 300 } | ||
} |
7 changes: 7 additions & 0 deletions
7
test/production/app-dir/build-output-tree-view/fixtures/mixed/pages/gssp.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Page() { | ||
return <p>hello world</p> | ||
} | ||
|
||
export async function getServerSideProps() { | ||
return { props: {} } | ||
} |
3 changes: 3 additions & 0 deletions
3
test/production/app-dir/build-output-tree-view/fixtures/mixed/pages/static.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return <p>hello world</p> | ||
} |