Repository: vercel/next.js
Pull request: test: Port clean-distdir integration test to the modern e2e test framework

@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.

Changed files:
filename: test/integration/clean-distdir/test/index.test.ts
patch: @@ -1,64 +0,0 @@
-/* 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)
-        })
-      })
-    }
-  )
-})

filename: test/production/clean-distdir/index.test.ts
patch: @@ -0,0 +1,55 @@
+/* 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)
+        }
+      )
+    })
+  })
+})