react-code-dataset / next.js /test /production /app-dir /build-output-tree-view /build-output-tree-view.test.ts
| 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 () => { | |
| expect(getTreeView(next.cliOutput)).toMatchInlineSnapshot(` | |
| "Route (app) Size First Load JS Revalidate Expire | |
| β β /_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-custom N/A kB N/A kB β7m β2h | |
| β β /cache-life-hours N/A kB N/A kB 1h 1d | |
| β Ζ /dynamic N/A kB N/A kB | |
| β β /ppr/[slug] N/A kB N/A kB 1w 30d | |
| β β /ppr/[slug] 1w 30d | |
| β β /ppr/days 1d 1w | |
| β β /ppr/weeks 1w 30d | |
| β β /revalidate N/A kB N/A kB 15m 1y | |
| + First Load JS shared by all N/A kB | |
| Route (pages) Size First Load JS Revalidate Expire | |
| β Ζ /api/hello N/A kB N/A kB | |
| β β /gsp-revalidate N/A kB N/A kB 5m 1y | |
| β Ζ /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) | |
| β (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() | |
| } | |