Skip to content

Commit

Permalink
Add snapshots for Turbopack
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed Feb 21, 2025
1 parent 26becbd commit bd42ee3
Showing 1 changed file with 117 additions and 54 deletions.
171 changes: 117 additions & 54 deletions test/production/app-dir/cli-build-output/cli-build-output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path'

describe('cli-build-output', () => {
describe('with mixed static and dynamic pages and app router routes', () => {
const { next } = nextTestSetup({
const { next, isTurbopack } = nextTestSetup({
files: path.join(__dirname, 'fixtures/mixed'),
skipStart: true,
env: {
Expand All @@ -21,45 +21,82 @@ describe('cli-build-output', () => {

// TODO: Fix double-listing of the /ppr/[slug] fallback.

expect(getTreeView(next.cliOutput)).toMatchInlineSnapshot(`
"Route (app) Size First Load JS
┌ ○ /_not-found ····· ······
├ ƒ /api ····· ······
├ ○ /api/force-static ····· ······
├ ○ /app-static ····· ······
├ ○ /cache-life ····· ······
├ ƒ /dynamic ····· ······
├ ◐ /ppr/[slug] ····· ······
├ ├ /ppr/[slug]
├ ├ /ppr/[slug]
├ ├ /ppr/days
├ └ /ppr/weeks
└ ○ /revalidate ····· ······
+ First Load JS shared by all ······
├ chunks/main-app-················.js ······
└ other shared chunks (total) ·······
Route (pages) Size First Load JS
┌ ƒ /api/hello ··· ·······
├ ● /gsp-revalidate (ISR: 300 Seconds) ····· ·······
├ ƒ /gssp ····· ·······
└ ○ /static ····· ·······
+ First Load JS shared by all ·······
├ chunks/framework-················.js ·······
├ chunks/main-················.js ·······
└ other shared chunks (total) ·······
○ (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"
`)
if (isTurbopack) {
expect(getTreeView(next.cliOutput)).toMatchInlineSnapshot(`
"Route (app) Size First Load JS
┌ ○ /_not-found ··· ······
├ ƒ /api ··· ···
├ ○ /api/force-static ··· ···
├ ○ /app-static ··· ······
├ ○ /cache-life ··· ······
├ ƒ /dynamic ··· ······
├ ◐ /ppr/[slug] ··· ······
├ ├ /ppr/[slug]
├ ├ /ppr/[slug]
├ ├ /ppr/days
├ └ /ppr/weeks
└ ○ /revalidate ··· ······
+ First Load JS shared by all ······
├ chunks/_······._.js ·····
├ chunks/_······._.js ·······
└ other shared chunks (total) ·······
Route (pages) Size First Load JS
┌ ƒ /api/hello ··· ·······
├ ● /gsp-revalidate (ISR: 300 Seconds) ······· ······
├ ƒ /gssp ······· ······
└ ○ /static ······· ······
+ First Load JS shared by all ·······
└ chunks/_······._.js ·····
└ other shared chunks (total) ·······
○ (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"
`)
} else {
expect(getTreeView(next.cliOutput)).toMatchInlineSnapshot(`
"Route (app) Size First Load JS
┌ ○ /_not-found ····· ······
├ ƒ /api ····· ······
├ ○ /api/force-static ····· ······
├ ○ /app-static ····· ······
├ ○ /cache-life ····· ······
├ ƒ /dynamic ····· ······
├ ◐ /ppr/[slug] ····· ······
├ ├ /ppr/[slug]
├ ├ /ppr/[slug]
├ ├ /ppr/days
├ └ /ppr/weeks
└ ○ /revalidate ····· ······
+ First Load JS shared by all ······
├ chunks/main-app-················.js ······
└ other shared chunks (total) ·······
Route (pages) Size First Load JS
┌ ƒ /api/hello ··· ·······
├ ● /gsp-revalidate (ISR: 300 Seconds) ····· ·······
├ ƒ /gssp ····· ·······
└ ○ /static ····· ·······
+ First Load JS shared by all ·······
├ chunks/framework-················.js ·······
├ chunks/main-················.js ·······
└ other shared chunks (total) ·······
○ (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({
const { next, isTurbopack } = nextTestSetup({
files: path.join(__dirname, 'fixtures/minimal-static'),
skipStart: true,
env: {
Expand All @@ -72,23 +109,43 @@ describe('cli-build-output', () => {
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
┌ ○ / ····· ······
└ ○ /_not-found ····· ······
+ First Load JS shared by all ······
├ chunks/main-app-················.js ······
└ other shared chunks (total) ·······
Route (pages) Size First Load JS
─ ○ /static ····· ·······
+ First Load JS shared by all ·······
├ chunks/framework-················.js ·······
├ chunks/main-················.js ·······
└ other shared chunks (total) ·······
○ (Static) prerendered as static content"
`)
if (isTurbopack) {
expect(getTreeView(next.cliOutput)).toMatchInlineSnapshot(`
"Route (app) Size First Load JS
┌ ○ / ··· ······
└ ○ /_not-found ··· ······
+ First Load JS shared by all ······
├ chunks/_······._.js ·······
├ chunks/_······._.js ·······
└ other shared chunks (total) ·······
Route (pages) Size First Load JS
─ ○ /static ······· ······
+ First Load JS shared by all ·······
└ chunks/_······._.js ·······
└ other shared chunks (total) ·······
○ (Static) prerendered as static content"
`)
} else {
expect(getTreeView(next.cliOutput)).toMatchInlineSnapshot(`
"Route (app) Size First Load JS
┌ ○ / ····· ······
└ ○ /_not-found ····· ······
+ First Load JS shared by all ······
├ chunks/main-app-················.js ······
└ other shared chunks (total) ·······
Route (pages) Size First Load JS
─ ○ /static ····· ·······
+ First Load JS shared by all ·······
├ chunks/framework-················.js ·······
├ chunks/main-················.js ·······
└ other shared chunks (total) ·······
○ (Static) prerendered as static content"
`)
}
})
})
})
Expand Down Expand Up @@ -118,11 +175,17 @@ function normalizeCliOutputLine(line: string): string {
(match) => '·'.repeat(match.length)
)

// Replace file hashes with a placeholder.
// Replace Webpack file hashes (main-4e582c6ad2d38ddc.js) with a placeholder.
line = line.replace(
/-([a-f0-9]{8,})(\.js)/g,
(match, p1, p2) => '-' + '·'.repeat(p1.length) + p2
)

// Replace Turbopack file hashes (chunks/_4d77e8._.js) with a placeholder.
line = line.replace(
/_([a-f0-9]{6,})(\._\.js)/g,
(match, p1, p2) => '_' + '·'.repeat(p1.length) + p2
)

return line
}

0 comments on commit bd42ee3

Please sign in to comment.