mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
These tests won't ever be run in a deployed environment, so this removes `skipDeployment` so it's easier to grok which tests are intentionally disabled because they don't work when deployed.
89 lines
2.2 KiB
TypeScript
89 lines
2.2 KiB
TypeScript
import { nextTestSetup, isNextStart } from 'e2e-utils'
|
|
import { runNextCommand } from 'next-test-utils'
|
|
import { existsSync } from 'fs'
|
|
import path from 'path'
|
|
|
|
describe('post-build', () => {
|
|
if (!isNextStart) {
|
|
it('skipped for non-start mode', () => {})
|
|
return
|
|
}
|
|
|
|
const { next, isTurbopack, skipped } = nextTestSetup({
|
|
files: __dirname,
|
|
skipStart: true,
|
|
env: {
|
|
NEXT_USE_POST_BUILD: '1',
|
|
},
|
|
})
|
|
|
|
if (skipped) return
|
|
|
|
it('should run post-build compaction on the turbopack cache', async () => {
|
|
if (!isTurbopack) {
|
|
console.log('Skipping: turbopack-only test')
|
|
return
|
|
}
|
|
|
|
// Build with NEXT_USE_POST_BUILD=1 which skips compaction during build
|
|
const buildResult = await next.build()
|
|
expect(buildResult.exitCode).toBe(0)
|
|
|
|
const cachePath = path.join(next.testDir, '.next', 'cache', 'turbopack')
|
|
expect(existsSync(cachePath)).toBe(true)
|
|
|
|
// Run `next internal post-build` to compact the database
|
|
const result = await runNextCommand(['internal', 'post-build'], {
|
|
cwd: next.testDir,
|
|
stderr: true,
|
|
stdout: true,
|
|
})
|
|
|
|
if (result.code !== 0) {
|
|
console.log('post-build stdout:', result.stdout)
|
|
console.log('post-build stderr:', result.stderr)
|
|
}
|
|
expect(result.code).toBe(0)
|
|
expect(result.stdout + result.stderr).toContain(
|
|
'Turbopack database compaction complete.'
|
|
)
|
|
})
|
|
|
|
it('should report nothing to do when persistent caching is disabled', async () => {
|
|
// Override config to disable persistent caching
|
|
await next.patchFile(
|
|
'next.config.js',
|
|
`module.exports = {
|
|
experimental: {
|
|
turbopackFileSystemCacheForBuild: false,
|
|
},
|
|
}`
|
|
)
|
|
|
|
try {
|
|
const result = await runNextCommand(['internal', 'post-build'], {
|
|
cwd: next.testDir,
|
|
stderr: true,
|
|
stdout: true,
|
|
})
|
|
expect(result.code).toBe(0)
|
|
expect(result.stdout + result.stderr).toContain('Nothing to do.')
|
|
} finally {
|
|
// Restore original config
|
|
await next.patchFile(
|
|
'next.config.js',
|
|
`/**
|
|
* @type {import('next').NextConfig}
|
|
*/
|
|
const nextConfig = {
|
|
experimental: {
|
|
turbopackFileSystemCacheForBuild: true,
|
|
},
|
|
}
|
|
|
|
module.exports = nextConfig`
|
|
)
|
|
}
|
|
})
|
|
})
|