Files
Tim NeutkensandGitHub 8141dcf12e Convert test/integration to isolated tests (#93247)
### 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.
2026-05-11 13:55:47 +02:00

1247 lines
34 KiB
TypeScript

import { nextTestSetup } from 'e2e-utils'
const strictRouteTypes =
process.env.__NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES === 'true'
describe('tsconfig.json verifier', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipStart: true,
skipDeployment: true,
})
if (skipped) return
beforeEach(async () => {
await next.deleteFile('tsconfig.json')
await next.deleteFile('tsconfig.base.json')
})
afterEach(async () => {
await next.deleteFile('tsconfig.json')
await next.deleteFile('tsconfig.base.json')
})
it('Creates a default tsconfig.json when one is missing', async () => {
expect(await next.hasFile('tsconfig.json')).toBe(false)
const { exitCode } = await next.build()
expect(exitCode).toBe(0)
if (strictRouteTypes) {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
} else {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
".next/dev/types/**/*.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
}
})
it('Works with an empty tsconfig.json (docs)', async () => {
expect(await next.hasFile('tsconfig.json')).toBe(false)
await next.patchFile('tsconfig.json', '')
await new Promise((resolve) => setTimeout(resolve, 500))
expect(await next.readFile('tsconfig.json')).toBe('')
const { exitCode, cliOutput } = await next.build()
expect(cliOutput).not.toContain('moduleResolution')
expect(exitCode).toBe(0)
if (strictRouteTypes) {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
} else {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
".next/dev/types/**/*.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
}
})
it('Updates an existing tsconfig.json without losing comments', async () => {
expect(await next.hasFile('tsconfig.json')).toBe(false)
await next.patchFile(
'tsconfig.json',
`
// top-level comment
{
// in-object comment 1
"compilerOptions": {
// in-object comment
"esModuleInterop": false, // this should be true
"module": "umd" // should not be umd
// end-object comment
}
// in-object comment 2
}
// end comment
`
)
await new Promise((resolve) => setTimeout(resolve, 500))
const { exitCode } = await next.build()
expect(exitCode).toBe(0)
if (strictRouteTypes) {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(`
"// top-level comment
{
// in-object comment 1
"compilerOptions": {
// in-object comment
"esModuleInterop": true, // this should be true
"module": "esnext" // should not be umd
// end-object comment
,
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
}
// in-object comment 2
,
"include": [
"next-env.d.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
// end comment
"
`)
} else {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(`
"// top-level comment
{
// in-object comment 1
"compilerOptions": {
// in-object comment
"esModuleInterop": true, // this should be true
"module": "esnext" // should not be umd
// end-object comment
,
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
}
// in-object comment 2
,
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
".next/dev/types/**/*.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
// end comment
"
`)
}
})
// `module: commonjs` forces `moduleResolution: node`, which TypeScript 6
// deprecates (TS5107). The commonjs case is tested in a separate describe
// block below that pins TypeScript 5.9 until we stop emitting the deprecated
// resolution. See the `tsconfig.json verifier 5.x` block at the end of this
// file.
it('allows you to set es2020 module mode', async () => {
expect(await next.hasFile('tsconfig.json')).toBe(false)
await next.patchFile(
'tsconfig.json',
`{ "compilerOptions": { "esModuleInterop": false, "module": "es2020" } }`
)
await new Promise((resolve) => setTimeout(resolve, 500))
const { exitCode } = await next.build()
expect(exitCode).toBe(0)
if (strictRouteTypes) {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"esModuleInterop": true,
"module": "es2020",
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
} else {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"esModuleInterop": true,
"module": "es2020",
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
".next/dev/types/**/*.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
}
})
it('allows you to set node16 moduleResolution mode', async () => {
expect(await next.hasFile('tsconfig.json')).toBe(false)
await next.patchFile(
'tsconfig.json',
`{ "compilerOptions": { "esModuleInterop": false, "moduleResolution": "node16", "module": "node16" } }`
)
await new Promise((resolve) => setTimeout(resolve, 500))
const { exitCode, cliOutput } = await next.build()
expect(cliOutput).not.toContain('moduleResolution')
expect(exitCode).toBe(0)
if (strictRouteTypes) {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"esModuleInterop": true,
"moduleResolution": "node16",
"module": "node16",
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
} else {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"esModuleInterop": true,
"moduleResolution": "node16",
"module": "node16",
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
".next/dev/types/**/*.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
}
})
it('allows you to set bundler moduleResolution mode', async () => {
expect(await next.hasFile('tsconfig.json')).toBe(false)
await next.patchFile(
'tsconfig.json',
`{ "compilerOptions": { "esModuleInterop": false, "moduleResolution": "bundler" } }`
)
await new Promise((resolve) => setTimeout(resolve, 500))
const { exitCode, cliOutput } = await next.build()
expect(cliOutput).not.toContain('moduleResolution')
expect(exitCode).toBe(0)
if (strictRouteTypes) {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"esModuleInterop": true,
"moduleResolution": "bundler",
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
} else {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"esModuleInterop": true,
"moduleResolution": "bundler",
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
".next/dev/types/**/*.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
}
})
it('allows you to set target mode', async () => {
expect(await next.hasFile('tsconfig.json')).toBe(false)
await next.patchFile(
'tsconfig.json',
`{ "compilerOptions": { "target": "es2022" } }`
)
await new Promise((resolve) => setTimeout(resolve, 500))
const { exitCode, cliOutput } = await next.build()
expect(cliOutput).not.toContain('target')
expect(exitCode).toBe(0)
if (strictRouteTypes) {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"target": "es2022",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
} else {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"target": "es2022",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
".next/dev/types/**/*.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
}
})
it('allows you to set node16 module mode', async () => {
expect(await next.hasFile('tsconfig.json')).toBe(false)
await next.patchFile(
'tsconfig.json',
`{ "compilerOptions": { "esModuleInterop": false, "module": "node16", "moduleResolution": "node16" } }`
)
await new Promise((resolve) => setTimeout(resolve, 500))
const { exitCode, cliOutput } = await next.build()
expect(cliOutput).not.toContain('moduleResolution')
expect(exitCode).toBe(0)
if (strictRouteTypes) {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"esModuleInterop": true,
"module": "node16",
"moduleResolution": "node16",
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
} else {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"esModuleInterop": true,
"module": "node16",
"moduleResolution": "node16",
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
".next/dev/types/**/*.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
}
})
it('allows you to set verbatimModuleSyntax true without adding isolatedModules', async () => {
expect(await next.hasFile('tsconfig.json')).toBe(false)
await next.patchFile(
'tsconfig.json',
`{ "compilerOptions": { "verbatimModuleSyntax": true } }`
)
await new Promise((resolve) => setTimeout(resolve, 500))
const { exitCode, cliOutput } = await next.build()
expect(cliOutput).not.toContain('isolatedModules')
expect(exitCode).toBe(0)
if (strictRouteTypes) {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"verbatimModuleSyntax": true,
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "bundler",
"resolveJsonModule": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
} else {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"verbatimModuleSyntax": true,
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "bundler",
"resolveJsonModule": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
".next/dev/types/**/*.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
}
})
it('allows you to set verbatimModuleSyntax true via extends without adding isolatedModules', async () => {
expect(await next.hasFile('tsconfig.json')).toBe(false)
expect(await next.hasFile('tsconfig.base.json')).toBe(false)
await next.patchFile(
'tsconfig.base.json',
`{
"compilerOptions": {
"verbatimModuleSyntax": true,
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"module": "esnext",
"esModuleInterop": true,
"moduleResolution": "bundler",
"resolveJsonModule": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}`
)
await next.patchFile(
'tsconfig.json',
`{ "extends": "./tsconfig.base.json" }`
)
await new Promise((resolve) => setTimeout(resolve, 500))
const { exitCode, cliOutput } = await next.build()
expect(cliOutput).not.toContain('isolatedModules')
expect(exitCode).toBe(0)
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(
`"{ "extends": "./tsconfig.base.json" }"`
)
})
it('allows you to extend another configuration file', async () => {
expect(await next.hasFile('tsconfig.json')).toBe(false)
expect(await next.hasFile('tsconfig.base.json')).toBe(false)
await next.patchFile(
'tsconfig.base.json',
`
{
"compilerOptions": {
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
`
)
await new Promise((resolve) => setTimeout(resolve, 500))
await next.patchFile(
'tsconfig.json',
`{ "extends": "./tsconfig.base.json" }`
)
await new Promise((resolve) => setTimeout(resolve, 500))
const { exitCode, cliOutput } = await next.build()
expect(cliOutput).not.toContain('moduleResolution')
expect(exitCode).toBe(0)
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(
`"{ "extends": "./tsconfig.base.json" }"`
)
})
it('creates compilerOptions when you extend another config', async () => {
expect(await next.hasFile('tsconfig.json')).toBe(false)
expect(await next.hasFile('tsconfig.base.json')).toBe(false)
await next.patchFile(
'tsconfig.base.json',
`
{
"compilerOptions": {
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
`
)
await new Promise((resolve) => setTimeout(resolve, 500))
await next.patchFile(
'tsconfig.json',
`{ "extends": "./tsconfig.base.json" }`
)
await new Promise((resolve) => setTimeout(resolve, 500))
const { exitCode, cliOutput } = await next.build()
expect(cliOutput).not.toContain('moduleResolution')
expect(exitCode).toBe(0)
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(
`"{ "extends": "./tsconfig.base.json" }"`
)
})
// TODO: Enable this test when repo has upgraded to TypeScript 5.4. Currently tested as E2E: tsconfig-module-preserve
it.skip('allows you to skip moduleResolution, esModuleInterop and resolveJsonModule when using "module: preserve"', async () => {
expect(await next.hasFile('tsconfig.json')).toBe(false)
await next.patchFile(
'tsconfig.json',
`{ "compilerOptions": { "module": "preserve" } }`
)
await new Promise((resolve) => setTimeout(resolve, 500))
const { exitCode, cliOutput } = await next.build()
expect(cliOutput).not.toContain('moduleResolution')
expect(cliOutput).not.toContain('esModuleInterop')
expect(cliOutput).not.toContain('resolveJsonModule')
expect(exitCode).toBe(0)
if (strictRouteTypes) {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot()
} else {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot()
}
})
})
// `module: commonjs` forces Next.js to emit `moduleResolution: node`, which
// TypeScript 6 deprecates (TS5107). Pin TypeScript 5.9 for this case until we
// stop emitting the deprecated resolution.
describe('tsconfig.json verifier 5.x', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipStart: true,
dependencies: {
typescript: '5.9.3',
},
skipDeployment: true,
})
if (skipped) return
beforeEach(async () => {
await next.deleteFile('tsconfig.json')
await next.deleteFile('tsconfig.base.json')
})
afterEach(async () => {
await next.deleteFile('tsconfig.json')
await next.deleteFile('tsconfig.base.json')
})
it('allows you to set commonjs module mode', async () => {
expect(await next.hasFile('tsconfig.json')).toBe(false)
await next.patchFile(
'tsconfig.json',
`{ "compilerOptions": { "esModuleInterop": false, "module": "commonjs" } }`
)
await new Promise((resolve) => setTimeout(resolve, 500))
const { exitCode } = await next.build()
expect(exitCode).toBe(0)
if (strictRouteTypes) {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"esModuleInterop": true,
"module": "commonjs",
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
} else {
expect(await next.readFile('tsconfig.json')).toMatchInlineSnapshot(`
"{
"compilerOptions": {
"esModuleInterop": true,
"module": "commonjs",
"target": "ES2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"noEmit": true,
"incremental": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
".next/dev/types/**/*.ts",
"**/*.mts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
"
`)
}
})
})