mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
8141dcf12e
### 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.
457 lines
14 KiB
TypeScript
457 lines
14 KiB
TypeScript
import path from 'path'
|
|
import fs from 'fs-extra'
|
|
import { nextTestSetup } from 'e2e-utils'
|
|
import escapeStringRegexp from 'escape-string-regexp'
|
|
|
|
const BUILD_FAILURE_RE = /Build failed because of (webpack|Rspack) errors/
|
|
|
|
// PostCSS plugins referenced by the `.postcssrc.json` / `postcss.config.js`
|
|
// files under `css-fixtures/` must be resolvable from the isolated test
|
|
// install. The original integration test relied on these being hoisted in the
|
|
// monorepo root, but the isolated next install only sees declared deps.
|
|
const postcssPluginDeps = {
|
|
pixrem: '5.0.0',
|
|
'postcss-pseudoelements': '5.0.0',
|
|
'postcss-short-size': '4.0.0',
|
|
'postcss-trolling': '0.1.7',
|
|
}
|
|
|
|
describe('CSS Customization', () => {
|
|
;(process.env.IS_TURBOPACK_TEST ? describe.skip : describe)(
|
|
'production mode',
|
|
() => {
|
|
describe('Basic CSS', () => {
|
|
const { next } = nextTestSetup({
|
|
files: path.join(__dirname, 'css-fixtures/custom-configuration'),
|
|
skipStart: true,
|
|
dependencies: postcssPluginDeps,
|
|
})
|
|
|
|
beforeAll(async () => {
|
|
await next.build()
|
|
})
|
|
|
|
it('should compile successfully', () => {
|
|
expect(next.cliOutput).toMatch(/Compiled successfully/)
|
|
})
|
|
|
|
it(`should've compiled and prefixed`, async () => {
|
|
const cssFolder = path.join(next.testDir, '.next/static/css')
|
|
|
|
const files = await fs.readdir(cssFolder)
|
|
const cssFiles = files.filter((f: string) => /\.css$/.test(f))
|
|
|
|
expect(cssFiles.length).toBe(1)
|
|
const cssContent = await fs.readFile(
|
|
path.join(cssFolder, cssFiles[0]),
|
|
'utf8'
|
|
)
|
|
expect(
|
|
cssContent.replace(/\/\*.*?\*\//g, '').trim()
|
|
).toMatchInlineSnapshot(
|
|
`"@media (480px <= width < 768px){::placeholder{color:green}}.video{max-width:400px;max-height:300px}"`
|
|
)
|
|
|
|
expect(cssContent).toMatch(
|
|
/\/\*#\s*sourceMappingURL=(.+\.map)\s*\*\//
|
|
)
|
|
})
|
|
|
|
it(`should've emitted a source map`, async () => {
|
|
const cssFolder = path.join(next.testDir, '.next/static/css')
|
|
|
|
const files = await fs.readdir(cssFolder)
|
|
const cssMapFiles = files.filter((f: string) => /\.css\.map$/.test(f))
|
|
|
|
expect(cssMapFiles.length).toBe(1)
|
|
const cssMapContent = (
|
|
await fs.readFile(path.join(cssFolder, cssMapFiles[0]), 'utf8')
|
|
).trim()
|
|
|
|
const { version, mappings, sourcesContent } =
|
|
JSON.parse(cssMapContent)
|
|
expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(`
|
|
{
|
|
"mappings": "AACA,gCACE,cACE,WACF,CACF,CAGA,OACE,eAA0B,CAA1B,gBACF",
|
|
"sourcesContent": [
|
|
"/* this should pass through untransformed */
|
|
@media (480px <= width < 768px) {
|
|
::placeholder {
|
|
color: green;
|
|
}
|
|
}
|
|
|
|
/* this should be transformed to width/height */
|
|
.video {
|
|
-xyz-max-size: 400px 300px;
|
|
}
|
|
",
|
|
],
|
|
"version": 3,
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
|
|
describe('Correct CSS Customization Array', () => {
|
|
const { next } = nextTestSetup({
|
|
files: path.join(__dirname, 'css-fixtures/custom-configuration-arr'),
|
|
skipStart: true,
|
|
dependencies: postcssPluginDeps,
|
|
})
|
|
|
|
beforeAll(async () => {
|
|
await next.build()
|
|
})
|
|
|
|
it('should compile successfully', () => {
|
|
expect(next.cliOutput).toMatch(/Compiled successfully/)
|
|
})
|
|
|
|
it(`should've compiled and prefixed`, async () => {
|
|
const cssFolder = path.join(next.testDir, '.next/static/css')
|
|
|
|
const files = await fs.readdir(cssFolder)
|
|
const cssFiles = files.filter((f: string) => /\.css$/.test(f))
|
|
|
|
expect(cssFiles.length).toBe(1)
|
|
const cssContent = await fs.readFile(
|
|
path.join(cssFolder, cssFiles[0]),
|
|
'utf8'
|
|
)
|
|
expect(
|
|
cssContent.replace(/\/\*.*?\*\//g, '').trim()
|
|
).toMatchInlineSnapshot(
|
|
`"@media (480px <= width < 768px){a:before{content:""}::placeholder{color:green}}.video{max-width:6400px;max-height:4800px;max-width:400rem;max-height:300rem}"`
|
|
)
|
|
|
|
expect(cssContent).toMatch(
|
|
/\/\*#\s*sourceMappingURL=(.+\.map)\s*\*\//
|
|
)
|
|
})
|
|
|
|
it(`should've emitted a source map`, async () => {
|
|
const cssFolder = path.join(next.testDir, '.next/static/css')
|
|
|
|
const files = await fs.readdir(cssFolder)
|
|
const cssMapFiles = files.filter((f: string) => /\.css\.map$/.test(f))
|
|
|
|
expect(cssMapFiles.length).toBe(1)
|
|
const cssMapContent = (
|
|
await fs.readFile(path.join(cssFolder, cssMapFiles[0]), 'utf8')
|
|
).trim()
|
|
|
|
const { version, mappings, sourcesContent } =
|
|
JSON.parse(cssMapContent)
|
|
expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(`
|
|
{
|
|
"mappings": "AACA,gCACE,SACE,UACF,CACA,cACE,WACF,CACF,CAGA,OACE,gBAA4B,CAA5B,iBAA4B,CAA5B,gBAA4B,CAA5B,iBACF",
|
|
"sourcesContent": [
|
|
"/* this should pass through untransformed */
|
|
@media (480px <= width < 768px) {
|
|
a::before {
|
|
content: '';
|
|
}
|
|
::placeholder {
|
|
color: green;
|
|
}
|
|
}
|
|
|
|
/* this should be transformed to width/height */
|
|
.video {
|
|
-xyz-max-size: 400rem 300rem;
|
|
}
|
|
",
|
|
],
|
|
"version": 3,
|
|
}
|
|
`)
|
|
})
|
|
})
|
|
|
|
describe('Correct CSS Customization custom loader', () => {
|
|
const { next } = nextTestSetup({
|
|
files: path.join(
|
|
__dirname,
|
|
'css-fixtures/custom-configuration-loader'
|
|
),
|
|
skipStart: true,
|
|
dependencies: postcssPluginDeps,
|
|
})
|
|
|
|
beforeAll(async () => {
|
|
await next.build()
|
|
})
|
|
|
|
it('should compile successfully', () => {
|
|
expect(next.cliOutput).toMatch(
|
|
/Built-in CSS support is being disabled/
|
|
)
|
|
expect(next.cliOutput).toMatch(/Compiled successfully/)
|
|
})
|
|
|
|
it(`should've applied style`, async () => {
|
|
const pagesFolder = path.join(
|
|
next.testDir,
|
|
'.next/static/chunks/pages'
|
|
)
|
|
|
|
const files = await fs.readdir(pagesFolder)
|
|
const indexFiles = files.filter((f: string) =>
|
|
/^index.+\.js$/.test(f)
|
|
)
|
|
|
|
expect(indexFiles.length).toBe(1)
|
|
const indexContent = await fs.readFile(
|
|
path.join(pagesFolder, indexFiles[0]),
|
|
'utf8'
|
|
)
|
|
expect(indexContent).toMatch(/\.my-text\.jsx-[0-9a-z]+{color:red}/)
|
|
})
|
|
})
|
|
|
|
describe('Bad CSS Customization', () => {
|
|
const { next } = nextTestSetup({
|
|
files: path.join(__dirname, 'css-fixtures/bad-custom-configuration'),
|
|
skipStart: true,
|
|
dependencies: postcssPluginDeps,
|
|
})
|
|
|
|
beforeAll(async () => {
|
|
await next.build()
|
|
})
|
|
|
|
it('should compile successfully', () => {
|
|
expect(next.cliOutput).toMatch(/Compiled successfully/)
|
|
expect(next.cliOutput).toMatch(
|
|
/field which is not supported.*?sourceMap/
|
|
)
|
|
;[
|
|
'postcss-modules-values',
|
|
'postcss-modules-scope',
|
|
'postcss-modules-extract-imports',
|
|
'postcss-modules-local-by-default',
|
|
'postcss-modules',
|
|
].forEach((plugin) => {
|
|
expect(next.cliOutput).toMatch(
|
|
new RegExp(`Please remove the.*?${escapeStringRegexp(plugin)}`)
|
|
)
|
|
})
|
|
})
|
|
|
|
it(`should've compiled and prefixed`, async () => {
|
|
const cssFolder = path.join(next.testDir, '.next/static/css')
|
|
|
|
const files = await fs.readdir(cssFolder)
|
|
const cssFiles = files.filter((f: string) => /\.css$/.test(f))
|
|
|
|
expect(cssFiles.length).toBe(1)
|
|
const cssContent = await fs.readFile(
|
|
path.join(cssFolder, cssFiles[0]),
|
|
'utf8'
|
|
)
|
|
expect(
|
|
cssContent.replace(/\/\*.*?\*\//g, '').trim()
|
|
).toMatchInlineSnapshot(`".video{max-width:400px;max-height:300px}"`)
|
|
|
|
expect(cssContent).toMatch(
|
|
/\/\*#\s*sourceMappingURL=(.+\.map)\s*\*\//
|
|
)
|
|
})
|
|
|
|
it(`should've emitted a source map`, async () => {
|
|
const cssFolder = path.join(next.testDir, '.next/static/css')
|
|
|
|
const files = await fs.readdir(cssFolder)
|
|
const cssMapFiles = files.filter((f: string) => /\.css\.map$/.test(f))
|
|
|
|
expect(cssMapFiles.length).toBe(1)
|
|
})
|
|
})
|
|
|
|
describe('Bad CSS Customization Array (1)', () => {
|
|
const { next } = nextTestSetup({
|
|
files: path.join(
|
|
__dirname,
|
|
'css-fixtures/bad-custom-configuration-arr-1'
|
|
),
|
|
skipStart: true,
|
|
dependencies: postcssPluginDeps,
|
|
})
|
|
|
|
it('should fail the build', async () => {
|
|
await next.build()
|
|
|
|
expect(next.cliOutput).toMatch(
|
|
/A PostCSS Plugin was passed as an array but did not provide its configuration \('postcss-trolling'\)/
|
|
)
|
|
expect(next.cliOutput).toMatch(BUILD_FAILURE_RE)
|
|
})
|
|
})
|
|
|
|
describe('Bad CSS Customization Array (2)', () => {
|
|
const { next } = nextTestSetup({
|
|
files: path.join(
|
|
__dirname,
|
|
'css-fixtures/bad-custom-configuration-arr-2'
|
|
),
|
|
skipStart: true,
|
|
dependencies: postcssPluginDeps,
|
|
})
|
|
|
|
it('should fail the build', async () => {
|
|
await next.build()
|
|
|
|
expect(next.cliOutput).toMatch(
|
|
/Error: Your PostCSS configuration for 'postcss-trolling' cannot have null configuration./
|
|
)
|
|
expect(next.cliOutput).toMatch(
|
|
/To disable 'postcss-trolling', pass false, otherwise, pass true or a configuration object./
|
|
)
|
|
expect(next.cliOutput).toMatch(BUILD_FAILURE_RE)
|
|
})
|
|
})
|
|
|
|
describe('Bad CSS Customization Array (3)', () => {
|
|
const { next } = nextTestSetup({
|
|
files: path.join(
|
|
__dirname,
|
|
'css-fixtures/bad-custom-configuration-arr-3'
|
|
),
|
|
skipStart: true,
|
|
dependencies: postcssPluginDeps,
|
|
})
|
|
|
|
it('should fail the build', async () => {
|
|
await next.build()
|
|
|
|
expect(next.cliOutput).toMatch(
|
|
/A PostCSS Plugin must be provided as a string. Instead, we got: '5'/
|
|
)
|
|
expect(next.cliOutput).toMatch(BUILD_FAILURE_RE)
|
|
})
|
|
})
|
|
|
|
describe('Bad CSS Customization Array (4)', () => {
|
|
const { next } = nextTestSetup({
|
|
files: path.join(
|
|
__dirname,
|
|
'css-fixtures/bad-custom-configuration-arr-4'
|
|
),
|
|
skipStart: true,
|
|
dependencies: postcssPluginDeps,
|
|
})
|
|
|
|
it('should fail the build', async () => {
|
|
await next.build()
|
|
|
|
expect(next.cliOutput).toMatch(
|
|
/An unknown PostCSS plugin was provided \(5\)/
|
|
)
|
|
expect(next.cliOutput).toMatch(BUILD_FAILURE_RE)
|
|
})
|
|
})
|
|
|
|
describe('Bad CSS Customization Array (5)', () => {
|
|
const { next } = nextTestSetup({
|
|
files: path.join(
|
|
__dirname,
|
|
'css-fixtures/bad-custom-configuration-arr-5'
|
|
),
|
|
skipStart: true,
|
|
dependencies: postcssPluginDeps,
|
|
})
|
|
|
|
it('should fail the build', async () => {
|
|
await next.build()
|
|
|
|
expect(next.cliOutput).toMatch(
|
|
/Your custom PostCSS configuration must export a `plugins` key./
|
|
)
|
|
expect(next.cliOutput).toMatch(BUILD_FAILURE_RE)
|
|
})
|
|
})
|
|
|
|
describe('Bad CSS Customization Array (6)', () => {
|
|
const { next } = nextTestSetup({
|
|
files: path.join(
|
|
__dirname,
|
|
'css-fixtures/bad-custom-configuration-arr-6'
|
|
),
|
|
skipStart: true,
|
|
dependencies: postcssPluginDeps,
|
|
})
|
|
|
|
it('should fail the build', async () => {
|
|
await next.build()
|
|
|
|
expect(next.cliOutput).toMatch(
|
|
/Your custom PostCSS configuration must export a `plugins` key./
|
|
)
|
|
expect(next.cliOutput).toMatch(BUILD_FAILURE_RE)
|
|
})
|
|
})
|
|
|
|
describe('Bad CSS Customization Array (7)', () => {
|
|
const { next } = nextTestSetup({
|
|
files: path.join(
|
|
__dirname,
|
|
'css-fixtures/bad-custom-configuration-arr-7'
|
|
),
|
|
skipStart: true,
|
|
dependencies: postcssPluginDeps,
|
|
})
|
|
|
|
it('should fail the build', async () => {
|
|
await next.build()
|
|
|
|
expect(next.cliOutput).toMatch(
|
|
/A PostCSS Plugin was passed as an array but did not provide its configuration \('postcss-trolling'\)/
|
|
)
|
|
expect(next.cliOutput).toMatch(BUILD_FAILURE_RE)
|
|
})
|
|
})
|
|
|
|
describe('Bad CSS Customization Array (8)', () => {
|
|
const { next } = nextTestSetup({
|
|
files: path.join(
|
|
__dirname,
|
|
'css-fixtures/bad-custom-configuration-arr-8'
|
|
),
|
|
skipStart: true,
|
|
dependencies: postcssPluginDeps,
|
|
})
|
|
|
|
it('should fail the build', async () => {
|
|
await next.build()
|
|
|
|
expect(next.cliOutput).toMatch(
|
|
/A PostCSS Plugin was passed as a function using require\(\), but it must be provided as a string/
|
|
)
|
|
expect(next.cliOutput).toMatch(BUILD_FAILURE_RE)
|
|
})
|
|
})
|
|
|
|
describe('Bad CSS Customization Function', () => {
|
|
const { next } = nextTestSetup({
|
|
files: path.join(
|
|
__dirname,
|
|
'css-fixtures/bad-custom-configuration-func'
|
|
),
|
|
skipStart: true,
|
|
dependencies: postcssPluginDeps,
|
|
})
|
|
|
|
it('should fail the build', async () => {
|
|
await next.build()
|
|
|
|
expect(next.cliOutput).toMatch(
|
|
/Your custom PostCSS configuration may not export a function/
|
|
)
|
|
expect(next.cliOutput).toMatch(BUILD_FAILURE_RE)
|
|
})
|
|
})
|
|
}
|
|
)
|
|
})
|