Unverified Commit fc977d6d authored by Will Binns-Smith's avatar Will Binns-Smith Committed by GitHub

Skip bundler config validation in next/jest and under test (#98392)

## Summary

Skip active-bundler config validation when `next/jest` loads
`next.config.*` under `PHASE_TEST`. Jest uses the Next.js SWC
transformer without running Turbopack or webpack, so bundler-specific
options should remain available without requiring phase-dependent user
config.

Add regression coverage for `experimental.turbopackRustReactCompiler`
and `experimental.cssChunking: 'graph'` in the test phase.

## Verification

- `pnpm test-unit test/unit/isolated/config.test.ts -t "Should allow
bundler-specific options during the test phase"`

<!-- NEXT_JS_LLM -->
parent 9db9b8ef
...@@ -12,6 +12,7 @@ import { ...@@ -12,6 +12,7 @@ import {
PHASE_PRODUCTION_BUILD, PHASE_PRODUCTION_BUILD,
PHASE_PRODUCTION_SERVER, PHASE_PRODUCTION_SERVER,
PHASE_INFO, PHASE_INFO,
PHASE_TEST,
type PHASE_TYPE, type PHASE_TYPE,
} from '../shared/lib/constants' } from '../shared/lib/constants'
import { import {
...@@ -554,7 +555,11 @@ function assignDefaultsAndValidate( ...@@ -554,7 +555,11 @@ function assignDefaultsAndValidate(
// Turbopack-only; strict mode and `false` (single-chunk-per-module) are webpack-only. // Turbopack-only; strict mode and `false` (single-chunk-per-module) are webpack-only.
// Only validate during build/dev — `next start` doesn't pick a bundler and would otherwise // Only validate during build/dev — `next start` doesn't pick a bundler and would otherwise
// see `process.env.TURBOPACK` unset and reject a valid `cssChunking: "graph"` config. // see `process.env.TURBOPACK` unset and reject a valid `cssChunking: "graph"` config.
if (phase !== PHASE_PRODUCTION_SERVER && phase !== PHASE_INFO) { if (
phase !== PHASE_PRODUCTION_SERVER &&
phase !== PHASE_INFO &&
phase !== PHASE_TEST
) {
if (result.experimental.durableUseCacheEntries && !process.env.TURBOPACK) { if (result.experimental.durableUseCacheEntries && !process.env.TURBOPACK) {
throw new Error( throw new Error(
`\`experimental.durableUseCacheEntries: true\` is only supported with Turbopack. ` + `\`experimental.durableUseCacheEntries: true\` is only supported with Turbopack. ` +
......
/* eslint-env jest */ /* eslint-env jest */
import { join } from 'path' import { join } from 'path'
import { PHASE_DEVELOPMENT_SERVER } from 'next/constants' import { PHASE_DEVELOPMENT_SERVER, PHASE_TEST } from 'next/constants'
const pathToConfig = join(__dirname, '_resolvedata', 'without-function') const pathToConfig = join(__dirname, '_resolvedata', 'without-function')
const pathToConfigFn = join(__dirname, '_resolvedata', 'with-function') const pathToConfigFn = join(__dirname, '_resolvedata', 'with-function')
...@@ -108,6 +108,21 @@ describe('config', () => { ...@@ -108,6 +108,21 @@ describe('config', () => {
expect(disabledConfig.experimental.devMemoryThresholdRestart).toBe(false) expect(disabledConfig.experimental.devMemoryThresholdRestart).toBe(false)
}) })
it('Should allow bundler-specific options during the test phase', async () => {
const config = await loadConfig(PHASE_TEST, '<rootDir>-test-phase', {
customConfig: {
reactCompiler: true,
experimental: {
cssChunking: 'graph',
turbopackRustReactCompiler: true,
},
},
})
expect(config.experimental.cssChunking).toBe('graph')
expect(config.experimental.turbopackRustReactCompiler).toBe(true)
})
it('Should allow setting objects which do not have defaults', async () => { it('Should allow setting objects which do not have defaults', async () => {
const config = await loadConfig(PHASE_DEVELOPMENT_SERVER, '<rootDir>', { const config = await loadConfig(PHASE_DEVELOPMENT_SERVER, '<rootDir>', {
customConfig: { customConfig: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment