Unverified Commit f09304af authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

test: Port clean-distdir integration test to the modern e2e test framework (#85828)

@timneutkens pointed out that this test was sometimes flaky with the
lockfile:
https://vercel.slack.com/archives/C07UCHRBWGK/p1762267195472319

I wasn't able to reproduce this locally, but this test looked like it
was in generally rough shape, and the `integration` test directory lacks
test isolation, so this at least ports it to the modern framework. If
nothing else, the test isolation might help.
parent db552831
/* eslint-env jest */
import fs from 'fs-extra'
import { join } from 'path'
import { nextBuild } from 'next-test-utils'
const appDir = join(__dirname, '../')
const nextDir = join(appDir, '.next')
const customFile = join(nextDir, '/extra-file.txt')
const cacheDir = join(nextDir, '/cache')
// const swcCacheDir = join(nextDir, '/cache/swc')
const nextConfig = join(appDir, 'next.config.js')
let nextConfigContent
async function checkFileWrite(existsAfterBuild) {
await nextBuild(appDir, [])
fs.writeFileSync(customFile, 'this is a testing file')
await nextBuild(appDir, [])
expect(fs.existsSync(customFile)).toBe(existsAfterBuild)
// `.next/cache` should be preserved in all cases
expect(fs.existsSync(cacheDir)).toBe(true)
// expect(fs.existsSync(swcCacheDir)).toBe(true)
}
const runTests = () => {
it('should clean up .next before build start', async () => {
await checkFileWrite(false)
})
}
describe('Cleaning distDir', () => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
beforeAll(() => {
fs.removeSync(nextDir)
})
runTests()
describe('disabled write', () => {
beforeAll(async () => {
nextConfigContent = await fs.readFile(nextConfig, 'utf8')
await fs.writeFile(
nextConfig,
`
module.exports = {
cleanDistDir: false
}
`
)
})
afterAll(async () => {
await fs.writeFile(nextConfig, nextConfigContent)
})
it('should not clean up .next before build start', async () => {
await checkFileWrite(true)
})
})
}
)
})
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
describe('Cleaning distDir', () => {
const { next, isTurbopack, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
skipStart: true,
})
if (skipped) return
beforeEach(async () => {
await next.stop()
await next.remove('.next')
})
async function checkFileWrite(existsAfterBuild: boolean) {
await next.build()
const customFile = '.next/extra-file.txt'
await next.patchFile(customFile, 'this is a testing file')
await next.build()
expect(await next.hasFile(customFile)).toBe(existsAfterBuild)
// `.next/cache` should be preserved in all cases
expect(await next.hasFile('.next/cache')).toBe(true)
if (!isTurbopack) {
expect(await next.hasFile('.next/cache/swc')).toBe(true)
}
}
describe('disabled write', () => {
it('should clean up .next before build start', async () => {
await checkFileWrite(false)
})
it('should not clean up .next before build start', async () => {
await next.patchFile(
'next.config.js',
`
module.exports = {
cleanDistDir: false
}
`,
async () => {
await checkFileWrite(true)
}
)
})
})
})
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