first commit
Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled

This commit is contained in:
Arian Tron
2026-03-10 19:37:31 +03:30
commit 61f56f997c
27684 changed files with 2784175 additions and 0 deletions

1
test/unit/isolated/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
test_resolvedata

View File

@@ -0,0 +1 @@
!dist

View File

@@ -0,0 +1 @@
hello world

View File

@@ -0,0 +1,3 @@
module.exports = {
target: 'nonexistent',
}

View File

@@ -0,0 +1,3 @@
module.exports = {
__test__ext: 'js',
}

View File

@@ -0,0 +1,3 @@
{
"__test__ext": "json"
}

View File

@@ -0,0 +1,3 @@
module.exports = {
__test__ext: 'jsx',
}

View File

@@ -0,0 +1,3 @@
module.exports = {
__test__ext: 'ts',
}

View File

@@ -0,0 +1,3 @@
module.exports = {
__test__ext: 'tsx',
}

View File

View File

View File

@@ -0,0 +1,6 @@
{
"/index": "static/development/pages/index.js",
"/world": "static/development/pages/world.js",
"/_error": "static/development/pages/_error.js",
"/non-existent-child": "static/development/pages/non-existent-child.js"
}

View File

@@ -0,0 +1,3 @@
module.exports = {
test: 'error',
}

View File

@@ -0,0 +1,3 @@
module.exports = {
test: 'hello',
}

View File

@@ -0,0 +1,4 @@
const nonExistent = require('./non-existent-module')
module.exports = {
test: nonExistent,
}

View File

@@ -0,0 +1,3 @@
module.exports = {
test: 'world',
}

View File

View File

@@ -0,0 +1,3 @@
module.exports = {
__test__ext: 'ts',
}

View File

@@ -0,0 +1,7 @@
module.exports = (phase, { defaultConfig }) => {
return {
phase,
defaultConfig,
customConfig: true,
}
}

View File

@@ -0,0 +1,3 @@
module.exports = {
customConfig: true,
}

View File

@@ -0,0 +1,226 @@
/* eslint-env jest */
import { join } from 'path'
import { PHASE_DEVELOPMENT_SERVER } from 'next/constants'
const pathToConfig = join(__dirname, '_resolvedata', 'without-function')
const pathToConfigFn = join(__dirname, '_resolvedata', 'with-function')
// force require usage instead of dynamic import in jest
// x-ref: https://github.com/nodejs/node/issues/35889
process.env.__NEXT_TEST_MODE = 'jest'
describe('config', () => {
let loadConfig: typeof import('next/dist/server/config').default
beforeEach(async () => {
// Reset the module cache to ensure each test gets a fresh config load
// This is important because config.ts now has a module-level configCache
jest.resetModules()
// Dynamically import the module after reset to get a fresh instance
const configModule = await import('next/dist/server/config')
loadConfig = configModule.default
})
it('Should get the configuration', async () => {
const config = await loadConfig(PHASE_DEVELOPMENT_SERVER, pathToConfig)
expect((config as any).customConfig).toBe(true)
})
it('Should pass the phase correctly', async () => {
const config = await loadConfig(PHASE_DEVELOPMENT_SERVER, pathToConfigFn)
expect((config as any).phase).toBe(PHASE_DEVELOPMENT_SERVER)
})
it('Should pass the defaultConfig correctly', async () => {
const config = await loadConfig(PHASE_DEVELOPMENT_SERVER, pathToConfigFn)
expect((config as any).defaultConfig).toBeDefined()
})
it('Should assign object defaults deeply to user config', async () => {
const config = await loadConfig(PHASE_DEVELOPMENT_SERVER, pathToConfigFn)
expect(config.distDir.replace(/\\/g, '/')).toEqual('.next/dev')
expect(config.onDemandEntries.maxInactiveAge).toBeDefined()
})
it('Should pass the customConfig correctly', async () => {
const config = await loadConfig(PHASE_DEVELOPMENT_SERVER, '<rootDir>', {
customConfig: {
customConfigKey: 'customConfigValue',
},
})
expect((config as any).customConfigKey).toBe('customConfigValue')
})
it('Should assign object defaults deeply to customConfig', async () => {
const config = await loadConfig(PHASE_DEVELOPMENT_SERVER, '<rootDir>', {
customConfig: {
customConfig: true,
onDemandEntries: { custom: true },
},
})
expect((config as any).customConfig).toBe(true)
expect(config.onDemandEntries.maxInactiveAge).toBeDefined()
})
it('Should allow setting objects which do not have defaults', async () => {
const config = await loadConfig(PHASE_DEVELOPMENT_SERVER, '<rootDir>', {
customConfig: {
bogusSetting: { custom: true },
},
})
expect((config as any).bogusSetting).toBeDefined()
expect((config as any).bogusSetting.custom).toBe(true)
})
it('Should override defaults for arrays from user arrays', async () => {
const config = await loadConfig(PHASE_DEVELOPMENT_SERVER, '<rootDir>', {
customConfig: {
pageExtensions: ['.bogus'],
},
})
expect(config.pageExtensions).toEqual(['.bogus'])
})
it('Should throw when an invalid target is provided', async () => {
await expect(async () => {
await loadConfig(
PHASE_DEVELOPMENT_SERVER,
join(__dirname, '_resolvedata', 'invalid-target')
)
}).rejects.toThrow(/The "target" property is no longer supported/)
})
it('Should throw an error when next.config.(js | mjs | ts) is not present', async () => {
await expect(
async () =>
await loadConfig(
PHASE_DEVELOPMENT_SERVER,
join(__dirname, '_resolvedata', 'missing-config')
)
).rejects.toThrow(
/Configuring Next.js via .+ is not supported. Please replace the file with 'next.config.js'/
)
})
it('Should throw an error when sassOptions.functions is used with Turbopack', async () => {
const originalTurbopack = process.env.TURBOPACK
process.env.TURBOPACK = '1'
try {
await expect(async () => {
// Use a unique directory to avoid cache conflicts
await loadConfig(PHASE_DEVELOPMENT_SERVER, '<rootDir>-turbopack-test', {
customConfig: {
sassOptions: {
functions: {
'get($keys)': function (keys) {
return 'test'
},
},
},
},
})
}).rejects.toThrow(
/The "sassOptions\.functions" option is not supported when using Turbopack/
)
} finally {
if (originalTurbopack === undefined) {
delete process.env.TURBOPACK
} else {
process.env.TURBOPACK = originalTurbopack
}
}
})
it('Should allow sassOptions.functions when not using Turbopack', async () => {
const originalTurbopack = process.env.TURBOPACK
delete process.env.TURBOPACK
try {
const config = await loadConfig(PHASE_DEVELOPMENT_SERVER, '<rootDir>', {
customConfig: {
sassOptions: {
functions: {
'get($keys)': function (keys) {
return 'test'
},
},
},
},
})
expect((config as any).sassOptions.functions).toBeDefined()
} finally {
if (originalTurbopack !== undefined) {
process.env.TURBOPACK = originalTurbopack
}
}
})
it('Should not throw an error when two versions of next.config.js are present', async () => {
const config = await loadConfig(
PHASE_DEVELOPMENT_SERVER,
join(__dirname, '_resolvedata', 'js-ts-config')
)
expect((config as any).__test__ext).toBe('js')
})
it('Should not throw an error when next.config.ts is present', async () => {
const config = await loadConfig(
PHASE_DEVELOPMENT_SERVER,
join(__dirname, '_resolvedata', 'typescript-config')
)
expect((config as any).__test__ext).toBe('ts')
})
describe('outputFileTracingRoot and turbopack.root consistency', () => {
it('Should set both outputFileTracingRoot and turbopack.root to the same value when only outputFileTracingRoot is provided', async () => {
const config = await loadConfig(PHASE_DEVELOPMENT_SERVER, '<rootDir>', {
customConfig: {
outputFileTracingRoot: '/custom/root',
},
})
expect(config.outputFileTracingRoot).toBe('/custom/root')
expect(config.turbopack.root).toBe('/custom/root')
})
it('Should set both outputFileTracingRoot and turbopack.root to the same value when only turbopack.root is provided', async () => {
const config = await loadConfig(PHASE_DEVELOPMENT_SERVER, '<rootDir>', {
customConfig: {
turbopack: { root: '/custom/root' },
},
})
expect(config.outputFileTracingRoot).toBe('/custom/root')
expect(config.turbopack.root).toBe('/custom/root')
})
it('Should use outputFileTracingRoot value when both are provided with different values', async () => {
const config = await loadConfig(PHASE_DEVELOPMENT_SERVER, '<rootDir>', {
customConfig: {
outputFileTracingRoot: '/tracing/root',
turbopack: { root: '/turbo/root' },
},
})
expect(config.outputFileTracingRoot).toBe('/tracing/root')
expect(config.turbopack.root).toBe('/tracing/root')
})
it('Should keep the same value when both are provided with matching values', async () => {
const config = await loadConfig(PHASE_DEVELOPMENT_SERVER, '<rootDir>', {
customConfig: {
outputFileTracingRoot: '/same/root',
turbopack: { root: '/same/root' },
},
})
expect(config.outputFileTracingRoot).toBe('/same/root')
expect(config.turbopack.root).toBe('/same/root')
})
it('Should set both to findRootDir result when neither is provided', async () => {
const config = await loadConfig(PHASE_DEVELOPMENT_SERVER, '<rootDir>', {
customConfig: {},
})
expect(config.outputFileTracingRoot).toBeDefined()
expect(config.turbopack.root).toBe(config.outputFileTracingRoot)
})
})
})

View File

@@ -0,0 +1,114 @@
/* eslint-env jest */
import { join } from 'path'
import { SERVER_DIRECTORY, CLIENT_STATIC_FILES_PATH } from 'next/constants'
import { normalizePagePath } from 'next/dist/shared/lib/page-path/normalize-page-path'
import { requirePage, getPagePath } from 'next/dist/server/require'
import { PageNotFoundError } from 'next/dist/shared/lib/utils'
const sep = '/'
const distDir = join(__dirname, '_resolvedata')
const pathToBundles = join(
distDir,
SERVER_DIRECTORY,
CLIENT_STATIC_FILES_PATH,
'development',
'pages'
)
describe('pageNotFoundError', () => {
it('Should throw error with ENOENT code', () => {
expect.assertions(1)
try {
throw new PageNotFoundError('test')
} catch (err) {
expect(err.code).toBe('ENOENT')
}
})
})
describe('normalizePagePath', () => {
it('Should turn / into /index', () => {
expect(normalizePagePath('/')).toBe(`${sep}index`)
})
it('Should turn _error into /_error', () => {
expect(normalizePagePath('_error')).toBe(`${sep}_error`)
})
it('Should turn /abc into /abc', () => {
expect(normalizePagePath('/abc')).toBe(`${sep}abc`)
})
it('Should turn /abc/def into /abc/def', () => {
expect(normalizePagePath('/abc/def')).toBe(`${sep}abc${sep}def`)
})
it('Should throw on /../../test.js', () => {
expect(() => normalizePagePath('/../../test.js')).toThrow()
})
})
describe('getPagePath', () => {
it('Should not append /index to the / page', () => {
expect(() => getPagePath('/', distDir, undefined, false)).toThrow(
'Cannot find module for page: /'
)
})
it('Should prepend / when a page does not have it', () => {
const pagePath = getPagePath('_error', distDir, undefined, false)
expect(pagePath).toBe(join(pathToBundles, `${sep}_error.js`))
})
it('Should throw with paths containing ../', () => {
expect(() =>
getPagePath('/../../package.json', distDir, undefined, false)
).toThrow()
})
})
describe('requirePage', () => {
it('Should not find page /index when using /', async () => {
await expect(requirePage('/', distDir, false)).rejects.toThrow(
'Cannot find module for page: /'
)
})
it('Should require /index.js when using /index', async () => {
const page = await requirePage('/index', distDir, false)
expect(page.test).toBe('hello')
})
it('Should require /world.js when using /world', async () => {
const page = await requirePage('/world', distDir, false)
expect(page.test).toBe('world')
})
it('Should throw when using /../../test.js', async () => {
expect.assertions(1)
try {
await requirePage('/../../test', distDir, false)
} catch (err) {
expect(err.code).toBe('ENOENT')
}
})
it('Should throw when using non existent pages like /non-existent.js', async () => {
expect.assertions(1)
try {
await requirePage('/non-existent', distDir, false)
} catch (err) {
expect(err.code).toBe('ENOENT')
}
})
it('Should bubble up errors in the child component', async () => {
expect.assertions(1)
try {
await requirePage('/non-existent-child', distDir, false)
} catch (err) {
expect(err.code).toBe('MODULE_NOT_FOUND')
}
})
})