mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
This PR is AI generated. If this directory is deleted while the dev server is running, we can't reasonably recover, so we should restart the process. Addresses https://vercel.slack.com/archives/C03KAR5DCKC/p1774757692640999
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { nextTestSetup } from 'e2e-utils'
|
|
import { retry } from 'next-test-utils'
|
|
import fs from 'fs'
|
|
import path from 'path'
|
|
|
|
describe('app-dir watch-distdir-deletion', () => {
|
|
const { next } = nextTestSetup({
|
|
files: path.join(__dirname, 'fixture'),
|
|
})
|
|
|
|
it('should restart the server when distDir is deleted', async () => {
|
|
// Wait for the dev server to be ready
|
|
await retry(async () => {
|
|
expect(next.cliOutput).toMatch(/ready/i)
|
|
})
|
|
|
|
// Make a request first to ensure the dev server has compiled
|
|
const warmupRes = await next.fetch('/')
|
|
expect(warmupRes.status).toBe(200)
|
|
|
|
// Delete .next (which also removes .next/dev, the watched distDir)
|
|
await fs.promises.rm(path.join(next.testDir, '.next'), {
|
|
recursive: true,
|
|
force: true,
|
|
})
|
|
|
|
// Wait for restart message and server to come back up
|
|
await retry(
|
|
async () => {
|
|
expect(next.cliOutput).toMatch(/The directory at .* was deleted/)
|
|
},
|
|
30_000,
|
|
1000
|
|
)
|
|
|
|
// Server should come back up and serve pages
|
|
await retry(
|
|
async () => {
|
|
const res = await next.fetch('/')
|
|
expect(res.status).toBe(200)
|
|
},
|
|
30_000,
|
|
1000
|
|
)
|
|
})
|
|
})
|