|
| 1 | +import { nextTestSetup } from 'e2e-utils' |
| 2 | +import path from 'path' |
| 3 | + |
| 4 | +describe('cli-build-output', () => { |
| 5 | + describe('with mixed static and dynamic pages and app router routes', () => { |
| 6 | + const { next } = nextTestSetup({ |
| 7 | + files: path.join(__dirname, 'fixtures/mixed'), |
| 8 | + skipStart: true, |
| 9 | + }) |
| 10 | + |
| 11 | + beforeAll(() => next.build()) |
| 12 | + |
| 13 | + it('should show info about prerendered and dynamic routes in a tree view', async () => { |
| 14 | + // TODO: Show cache info (revalidate/expire) for app router, and use the |
| 15 | + // same for pages router instead of the ISR addendum. |
| 16 | + |
| 17 | + // TODO: Fix double-listing of the /ppr/[slug] fallback. |
| 18 | + |
| 19 | + expect(getTreeView(next.cliOutput)).toMatchInlineSnapshot(` |
| 20 | + "Route (app) Size First Load JS |
| 21 | + ┌ ○ /_not-found ····· ······ |
| 22 | + ├ ƒ /api ····· ······ |
| 23 | + ├ ○ /api/force-static ····· ······ |
| 24 | + ├ ○ /app-static ····· ······ |
| 25 | + ├ ○ /cache-life ····· ······ |
| 26 | + ├ ƒ /dynamic ····· ······ |
| 27 | + ├ ◐ /ppr/[slug] ····· ······ |
| 28 | + ├ ├ /ppr/[slug] |
| 29 | + ├ ├ /ppr/[slug] |
| 30 | + ├ ├ /ppr/days |
| 31 | + ├ └ /ppr/weeks |
| 32 | + └ ○ /revalidate ····· ······ |
| 33 | + + First Load JS shared by all ······ |
| 34 | + ├ chunks/main-app-················.js ······ |
| 35 | + └ other shared chunks (total) ······· |
| 36 | +
|
| 37 | + Route (pages) Size First Load JS |
| 38 | + ┌ ƒ /api/hello ··· ······· |
| 39 | + ├ ● /gsp-revalidate (ISR: 300 Seconds) ····· ······· |
| 40 | + ├ ƒ /gssp ····· ······· |
| 41 | + └ ○ /static ····· ······· |
| 42 | + + First Load JS shared by all ······· |
| 43 | + ├ chunks/framework-················.js ······· |
| 44 | + ├ chunks/main-················.js ······· |
| 45 | + └ other shared chunks (total) ······· |
| 46 | +
|
| 47 | + ○ (Static) prerendered as static content |
| 48 | + ● (SSG) prerendered as static HTML (uses generateStaticParams) |
| 49 | + (ISR) incremental static regeneration (uses revalidate in generateStaticParams) |
| 50 | + ◐ (Partial Prerender) prerendered as static HTML with dynamic server-streamed content |
| 51 | + ƒ (Dynamic) server-rendered on demand" |
| 52 | + `) |
| 53 | + }) |
| 54 | + }) |
| 55 | + |
| 56 | + describe('with only a few static routes', () => { |
| 57 | + const { next } = nextTestSetup({ |
| 58 | + files: path.join(__dirname, 'fixtures/minimal-static'), |
| 59 | + skipStart: true, |
| 60 | + }) |
| 61 | + |
| 62 | + beforeAll(() => next.build()) |
| 63 | + |
| 64 | + it('should show info about prerendered routes in a compact tree view', async () => { |
| 65 | + expect(getTreeView(next.cliOutput)).toMatchInlineSnapshot(` |
| 66 | + "Route (app) Size First Load JS |
| 67 | + ┌ ○ / ····· ······ |
| 68 | + └ ○ /_not-found ····· ······ |
| 69 | + + First Load JS shared by all ······ |
| 70 | + ├ chunks/main-app-················.js ······ |
| 71 | + └ other shared chunks (total) ······· |
| 72 | +
|
| 73 | + Route (pages) Size First Load JS |
| 74 | + ─ ○ /static ····· ······· |
| 75 | + + First Load JS shared by all ······· |
| 76 | + ├ chunks/framework-················.js ······· |
| 77 | + ├ chunks/main-················.js ······· |
| 78 | + └ other shared chunks (total) ······· |
| 79 | +
|
| 80 | + ○ (Static) prerendered as static content" |
| 81 | + `) |
| 82 | + }) |
| 83 | + }) |
| 84 | +}) |
| 85 | + |
| 86 | +function getTreeView(cliOutput: string): string { |
| 87 | + let foundBuildTracesLine = false |
| 88 | + const lines: string[] = [] |
| 89 | + |
| 90 | + for (const line of cliOutput.split('\n')) { |
| 91 | + if (foundBuildTracesLine) { |
| 92 | + lines.push(normalizeCliOutputLine(line)) |
| 93 | + } |
| 94 | + |
| 95 | + foundBuildTracesLine ||= line.includes('Collecting build traces') |
| 96 | + } |
| 97 | + |
| 98 | + while (lines.at(0) === '') lines.shift() |
| 99 | + while (lines.at(-1) === '') lines.pop() |
| 100 | + |
| 101 | + return lines.join('\n') |
| 102 | +} |
| 103 | + |
| 104 | +function normalizeCliOutputLine(line: string): string { |
| 105 | + // Replace file sizes with a placeholder. |
| 106 | + line = line.replace( |
| 107 | + /\b\d+(?:\.\d+)?\s*(B|kB|MB|GB|TB|PB|EB|ZB|YB)\b/g, |
| 108 | + (match) => '·'.repeat(match.length) |
| 109 | + ) |
| 110 | + |
| 111 | + // Replace file hashes with a placeholder. |
| 112 | + line = line.replace( |
| 113 | + /-([a-f0-9]{8,})(\.js)/g, |
| 114 | + (match, p1, p2) => '-' + '·'.repeat(p1.length) + p2 |
| 115 | + ) |
| 116 | + |
| 117 | + return line |
| 118 | +} |
0 commit comments