mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
### What?
Converts every test under `test/integration/` to an isolated test
running through `nextTestSetup` (under `test/e2e/`, `test/production/`,
`test/development/`, or `test/unit/`), then deletes `test/integration/`
along with the legacy CI orchestration that was specific to it.
- `test/integration/` removed entirely (~327 test suites)
- New isolated suites added across the existing folders:
- `test/e2e/` — 175
- `test/production/` — 130
- `test/development/` — 43
- `test/unit/` — 1
- `.github/workflows/build_and_test.yml` and `run-tests.js` no longer
have any `integration` branches
- `nextTestSetup` gained a `baseUrl` option on `next.browser()` so a
small number of tests that drive their own proxy/static-export server
can keep using `next.browser(...)` instead of importing `next-webdriver`
directly
### Why?
`test/integration/` predated `nextTestSetup` and ran tests directly
against the source checkout via custom helpers (`launchApp`,
`nextBuild`, `nextStart`, `runNextCommand`, `webdriver`, `fetchViaHTTP`,
…). Each suite hand-rolled its own dev/start/build orchestration,
fixture mutation, and process management.
The isolated test model used by the rest of the repo gives each suite an
isolated working directory containing a packed `next.tgz` install, a
uniform `next.start()` / `next.build()` / `next.fetch()` /
`next.browser()` API, and the same lifecycle for dev, start, and deploy
modes — so a single set of assertions covers all three. Deploy-mode
skips and per-feature gates are expressed declaratively
(`skipDeployment`, `disableAutoSkewProtection`, `if (skipped) return`)
instead of branching on `process.env`.
Removing `test/integration/` lets us:
- Delete the bespoke orchestration code in the CI workflow and
`run-tests.js`
- Run every converted suite consistently in dev, start, and deploy modes
(where applicable)
- Reproduce every test locally with the same `pnpm
test-{dev,start}-{turbo,webpack}` commands; no separate `integration`
path
- Open the door to running `test/production` against deployments in the
future (the converted suites already declare `skipDeployment` so they
can be flipped on)
### How?
Mechanical conversion per suite, with targeted clean-ups:
1. **Per-suite conversion.** Each
`test/integration/<name>/test/index.test.{js,ts}` was rewritten into a
single `<name>.test.ts` under the right folder based on what the
original exercised:
- `launchApp` / dev-only assertions → `test/development/`
- `nextBuild` + `nextStart` / start-only assertions → `test/production/`
- Both → `test/e2e/`
- The one pure jsdom render check (`link-without-router`) → `test/unit/`
2. **API mapping.** Custom helpers were replaced by `nextTestSetup`
equivalents: `launchApp` → `next.start()`, `nextBuild` → `next.build()`,
`runNextCommand` → `next.runCommand`, `fetchViaHTTP` → `next.fetch`,
`webdriver(...)` → `next.browser(...)`. Fixture mutations switched from
raw `fs.writeFile`/`fs.rename` to `next.patchFile` (with the 3-arg
`runWithTempContent` callback when the change has a defined scope) and
`next.deleteFile`.
3. **Deploy-mode handling.** Suites that can't run in deploy mode (use
`patchFile` / `next.build()` / depend on local CLI output) declare
`skipDeployment: true` and early-return on the `skipped` boolean. Suites
where Vercel's edge mutates URLs (`&dpl=`, immutable assets) declare
`disableAutoSkewProtection: true`.
4. **`next.browser({ baseUrl })`.** A handful of tests
(`prerender-export`, `cdn-cache-busting`, `preload-viewport`, both
`react-virtualized` suites) need to drive a separate server (a
static-export server or an `http-proxy` instance) rather than the
Next.js process. Instead of importing `next-webdriver` directly, those
tests now pass `{ baseUrl: <port|url> }` to `next.browser()`. For the
proxy cases, the proxy was moved into `server.js` inside the fixture and
`http-proxy` declared via the `dependencies` option of `nextTestSetup`,
so the test runs with a fully isolated dependency graph.
5. **CI clean-up.** With `test/integration` gone, the `test
integration*` jobs and `integration-tests-manifest`-related logic in
`.github/workflows/build_and_test.yml` were removed, and `run-tests.js`
no longer has the `integration` test-folder branch.
6. **Validation.** The PR was iterated against multiple full CI runs;
the remaining failures on the latest run are pre-existing flakes
(segment-cache 60s `act` timeouts in turbopack-prod) or transient
infrastructure issues unrelated to the conversion.
341 lines
10 KiB
TypeScript
341 lines
10 KiB
TypeScript
import { nextTestSetup } from 'e2e-utils'
|
|
import { join } from 'path'
|
|
import fs from 'fs'
|
|
|
|
describe('Build Output', () => {
|
|
describe('Basic Application Output (default config)', () => {
|
|
const { next } = nextTestSetup({
|
|
files: join(__dirname, 'fixtures', 'basic-app'),
|
|
skipStart: true,
|
|
})
|
|
|
|
let stdout: string
|
|
|
|
beforeAll(async () => {
|
|
const result = await next.build()
|
|
stdout = result.cliOutput
|
|
})
|
|
|
|
it('should not include internal pages', () => {
|
|
expect(stdout).toMatch(/\//)
|
|
expect(stdout).not.toContain(' /_document')
|
|
expect(stdout).not.toContain(' /_app')
|
|
expect(stdout).not.toContain(' /_error')
|
|
expect(stdout).not.toContain('<buildId>')
|
|
expect(stdout).toContain('○ /')
|
|
})
|
|
|
|
// TODO: change format of this test to be more reliable
|
|
it.skip('should not deviate from snapshot', () => {
|
|
console.log(stdout)
|
|
|
|
if (process.env.NEXT_PRIVATE_SKIP_SIZE_TESTS) {
|
|
return
|
|
}
|
|
|
|
const parsePageSize = (page: string) =>
|
|
stdout.match(
|
|
new RegExp(` ${page} .*?((?:\\d|\\.){1,} (?:\\w{1,})) `)
|
|
)![1]
|
|
|
|
const parsePageFirstLoad = (page: string) =>
|
|
stdout.match(
|
|
new RegExp(
|
|
` ${page} .*?(?:(?:\\d|\\.){1,}) .*? ((?:\\d|\\.){1,} (?:\\w{1,}))`
|
|
)
|
|
)![1]
|
|
|
|
const parseSharedSize = (sharedPartName: string) => {
|
|
const matches = stdout.match(
|
|
new RegExp(`${sharedPartName} .*? ((?:\\d|\\.){1,} (?:\\w{1,}))`)
|
|
)
|
|
|
|
if (!matches) {
|
|
throw new Error(`Could not match ${sharedPartName}`)
|
|
}
|
|
|
|
return matches[1]
|
|
}
|
|
|
|
const indexSize = parsePageSize('/')
|
|
const indexFirstLoad = parsePageFirstLoad('/')
|
|
|
|
const err404Size = parsePageSize('/404')
|
|
const err404FirstLoad = parsePageFirstLoad('/404')
|
|
|
|
const sharedByAll = parseSharedSize('shared by all')
|
|
const _appSize = parseSharedSize('_app-.*?\\.js')
|
|
const webpackSize = parseSharedSize('webpack-.*?\\.js')
|
|
const mainSize = parseSharedSize('main-.*?\\.js')
|
|
const frameworkSize = parseSharedSize('framework-.*?\\.js')
|
|
|
|
for (const size of [
|
|
indexSize,
|
|
indexFirstLoad,
|
|
err404Size,
|
|
err404FirstLoad,
|
|
sharedByAll,
|
|
_appSize,
|
|
webpackSize,
|
|
mainSize,
|
|
frameworkSize,
|
|
]) {
|
|
expect(parseFloat(size)).toBeGreaterThan(0)
|
|
}
|
|
|
|
expect(indexSize.endsWith('B')).toBe(true)
|
|
expect(indexFirstLoad.endsWith('kB')).toBe(true)
|
|
expect(err404Size.endsWith('B')).toBe(true)
|
|
expect(err404FirstLoad.endsWith('kB')).toBe(true)
|
|
expect(sharedByAll.endsWith('kB')).toBe(true)
|
|
expect(_appSize.endsWith('kB') || _appSize.endsWith(' B')).toBe(true)
|
|
expect(webpackSize.endsWith('kB') || webpackSize.endsWith(' B')).toBe(
|
|
true
|
|
)
|
|
expect(mainSize.endsWith('kB')).toBe(true)
|
|
expect(frameworkSize.endsWith('kB')).toBe(true)
|
|
})
|
|
|
|
it('should print duration when rendering or get static props takes long', () => {
|
|
const matches = stdout.match(
|
|
/ \/slow-static\/.+\/.+(?: \(\d+ ms\))?| \[\+\d+ more paths\]/g
|
|
)
|
|
|
|
for (const check of [
|
|
expect.stringMatching(
|
|
/\/\[propsDuration\]\/\[renderDuration\] \(\d+ ms\)/
|
|
),
|
|
expect.stringMatching(/\/2000\/10 \(\d+ ms\)$/),
|
|
expect.stringMatching(/\/10\/1000 \(\d+ ms\)$/),
|
|
expect.stringMatching(/\/300\/10 \(\d+ ms\)$/),
|
|
' [+2 more paths]',
|
|
]) {
|
|
expect(matches).toContainEqual(check)
|
|
}
|
|
})
|
|
|
|
it('should not emit extracted comments', () => {
|
|
const nextDir = join(next.testDir, '.next')
|
|
const allFiles: string[] = []
|
|
|
|
function walk(dir: string) {
|
|
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
const full = join(dir, entry.name)
|
|
if (entry.isDirectory()) walk(full)
|
|
else allFiles.push(full)
|
|
}
|
|
}
|
|
walk(nextDir)
|
|
|
|
const txtOrLicenseFiles = allFiles.filter((f) =>
|
|
/\.txt|\.LICENSE\./.test(f)
|
|
)
|
|
expect(txtOrLicenseFiles).toEqual([])
|
|
})
|
|
})
|
|
|
|
describe('Basic Application Output (gzipSize: false)', () => {
|
|
const { next } = nextTestSetup({
|
|
files: join(__dirname, 'fixtures', 'basic-app'),
|
|
skipStart: true,
|
|
nextConfig: {
|
|
experimental: {
|
|
gzipSize: false,
|
|
},
|
|
},
|
|
})
|
|
|
|
let stdout: string
|
|
|
|
beforeAll(async () => {
|
|
const result = await next.build()
|
|
stdout = result.cliOutput
|
|
})
|
|
|
|
it('should not include internal pages', () => {
|
|
expect(stdout).toMatch(/\//)
|
|
expect(stdout).not.toContain(' /_document')
|
|
expect(stdout).not.toContain(' /_app')
|
|
expect(stdout).not.toContain(' /_error')
|
|
expect(stdout).not.toContain('<buildId>')
|
|
expect(stdout).toContain('○ /')
|
|
})
|
|
|
|
// TODO: change format of this test to be more reliable
|
|
it.skip('should not deviate from snapshot', () => {
|
|
console.log(stdout)
|
|
|
|
if (process.env.NEXT_PRIVATE_SKIP_SIZE_TESTS) {
|
|
return
|
|
}
|
|
|
|
const parsePageSize = (page: string) =>
|
|
stdout.match(
|
|
new RegExp(` ${page} .*?((?:\\d|\\.){1,} (?:\\w{1,})) `)
|
|
)![1]
|
|
|
|
const parsePageFirstLoad = (page: string) =>
|
|
stdout.match(
|
|
new RegExp(
|
|
` ${page} .*?(?:(?:\\d|\\.){1,}) .*? ((?:\\d|\\.){1,} (?:\\w{1,}))`
|
|
)
|
|
)![1]
|
|
|
|
const parseSharedSize = (sharedPartName: string) => {
|
|
const matches = stdout.match(
|
|
new RegExp(`${sharedPartName} .*? ((?:\\d|\\.){1,} (?:\\w{1,}))`)
|
|
)
|
|
|
|
if (!matches) {
|
|
throw new Error(`Could not match ${sharedPartName}`)
|
|
}
|
|
|
|
return matches[1]
|
|
}
|
|
|
|
const indexSize = parsePageSize('/')
|
|
const indexFirstLoad = parsePageFirstLoad('/')
|
|
|
|
const err404Size = parsePageSize('/404')
|
|
const err404FirstLoad = parsePageFirstLoad('/404')
|
|
|
|
const sharedByAll = parseSharedSize('shared by all')
|
|
const _appSize = parseSharedSize('_app-.*?\\.js')
|
|
const webpackSize = parseSharedSize('webpack-.*?\\.js')
|
|
const mainSize = parseSharedSize('main-.*?\\.js')
|
|
const frameworkSize = parseSharedSize('framework-.*?\\.js')
|
|
|
|
for (const size of [
|
|
indexSize,
|
|
indexFirstLoad,
|
|
err404Size,
|
|
err404FirstLoad,
|
|
sharedByAll,
|
|
_appSize,
|
|
webpackSize,
|
|
mainSize,
|
|
frameworkSize,
|
|
]) {
|
|
expect(parseFloat(size)).toBeGreaterThan(0)
|
|
}
|
|
|
|
expect(indexSize.endsWith('B')).toBe(true)
|
|
expect(indexFirstLoad.endsWith('kB')).toBe(true)
|
|
expect(err404Size.endsWith('B')).toBe(true)
|
|
expect(err404FirstLoad.endsWith('kB')).toBe(true)
|
|
expect(sharedByAll.endsWith('kB')).toBe(true)
|
|
expect(_appSize.endsWith('kB') || _appSize.endsWith(' B')).toBe(true)
|
|
expect(webpackSize.endsWith('kB') || webpackSize.endsWith(' B')).toBe(
|
|
true
|
|
)
|
|
expect(mainSize.endsWith('kB')).toBe(true)
|
|
expect(frameworkSize.endsWith('kB')).toBe(true)
|
|
})
|
|
|
|
it('should print duration when rendering or get static props takes long', () => {
|
|
const matches = stdout.match(
|
|
/ \/slow-static\/.+\/.+(?: \(\d+ ms\))?| \[\+\d+ more paths\]/g
|
|
)
|
|
|
|
for (const check of [
|
|
expect.stringMatching(
|
|
/\/\[propsDuration\]\/\[renderDuration\] \(\d+ ms\)/
|
|
),
|
|
expect.stringMatching(/\/2000\/10 \(\d+ ms\)$/),
|
|
expect.stringMatching(/\/10\/1000 \(\d+ ms\)$/),
|
|
expect.stringMatching(/\/300\/10 \(\d+ ms\)$/),
|
|
' [+2 more paths]',
|
|
]) {
|
|
expect(matches).toContainEqual(check)
|
|
}
|
|
})
|
|
|
|
it('should not emit extracted comments', () => {
|
|
const nextDir = join(next.testDir, '.next')
|
|
const allFiles: string[] = []
|
|
|
|
function walk(dir: string) {
|
|
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
const full = join(dir, entry.name)
|
|
if (entry.isDirectory()) walk(full)
|
|
else allFiles.push(full)
|
|
}
|
|
}
|
|
walk(nextDir)
|
|
|
|
const txtOrLicenseFiles = allFiles.filter((f) =>
|
|
/\.txt|\.LICENSE\./.test(f)
|
|
)
|
|
expect(txtOrLicenseFiles).toEqual([])
|
|
})
|
|
})
|
|
|
|
describe('Custom App Output', () => {
|
|
const { next } = nextTestSetup({
|
|
files: join(__dirname, 'fixtures', 'with-app'),
|
|
skipStart: true,
|
|
})
|
|
|
|
it('should not include custom error', async () => {
|
|
const { cliOutput: stdout } = await next.build()
|
|
|
|
expect(stdout).toMatch(/\//)
|
|
expect(stdout).toMatch(/\/_app/)
|
|
|
|
expect(stdout).not.toContain(' /_document')
|
|
expect(stdout).not.toContain(' /_error')
|
|
expect(stdout).not.toContain('<buildId>')
|
|
|
|
expect(stdout).toContain(' /_app')
|
|
expect(stdout).toContain('○ /')
|
|
})
|
|
})
|
|
|
|
describe('Custom Error Output', () => {
|
|
const { next } = nextTestSetup({
|
|
files: join(__dirname, 'fixtures', 'with-error'),
|
|
skipStart: true,
|
|
})
|
|
|
|
it('should not include custom app', async () => {
|
|
const { cliOutput: stdout } = await next.build()
|
|
|
|
expect(stdout).toMatch(/\//)
|
|
expect(stdout).toMatch(/ƒ \/404/)
|
|
|
|
expect(stdout).not.toContain(' /_document')
|
|
expect(stdout).not.toContain(' /_app')
|
|
expect(stdout).not.toContain('<buildId>')
|
|
|
|
expect(stdout).not.toContain(' /_error')
|
|
expect(stdout).toContain('○ /')
|
|
})
|
|
})
|
|
|
|
describe('Custom Static Error Output', () => {
|
|
const { next } = nextTestSetup({
|
|
files: join(__dirname, 'fixtures', 'with-error-static'),
|
|
skipStart: true,
|
|
})
|
|
|
|
it('should not specify /404 as lambda when static', async () => {
|
|
const { cliOutput: stdout } = await next.build()
|
|
expect(stdout).toContain('○ /404')
|
|
expect(stdout).not.toContain('ƒ /_error')
|
|
expect(stdout).not.toContain('<buildId>')
|
|
})
|
|
})
|
|
|
|
describe('With Parallel Routes', () => {
|
|
const { next } = nextTestSetup({
|
|
files: join(__dirname, 'fixtures', 'with-parallel-routes'),
|
|
skipStart: true,
|
|
})
|
|
|
|
it('should not have duplicate paths that resolve to the same route', async () => {
|
|
const { cliOutput: stdout } = await next.build()
|
|
expect(stdout.match(/○ \/root-page/g)!.length).toBe(1)
|
|
})
|
|
})
|
|
})
|