Unverified Commit 2c9b484f authored by Jan Kaifer's avatar Jan Kaifer Committed by GitHub

Auto-restart dev server when next.config.js changes (#47912)

This is a follow-up PR on https://github.com/vercel/next.js/pull/46577
after it got nasty conflicts.

Basically, just restart `dev` when `next.config.ts` it will just restart
instead of printing that message asking you to restart.
fix NEXT-639
parent af694f66
This diff is collapsed.
import { createNext } from 'e2e-utils'
import { createNextDescribe } from 'e2e-utils'
import { check } from 'next-test-utils'
import { NextInstance } from 'test/lib/next-modes/base'
describe('watch-config-file', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: {
'pages/index.js': `
createNextDescribe(
'watch-config-file',
{
files: {
'pages/index.js': `
export default function Page() {
return <p>hello world</p>
}
`,
'next.config.js': `
'next.config.js': `
const nextConfig = {
reactStrictMode: true,
}
module.exports = nextConfig
`,
},
dependencies: {},
skipStart: true,
})
})
afterAll(() => next.destroy())
it('should output config file change', async () => {
// next dev test-dir
await next.start(true)
let i = 1
await check(async () => {
},
},
({ next }) => {
it('should output config file change', async () => {
await check(
async () => next.cliOutput,
/compiled client and server successfully/
)
await next.patchFile(
'next.config.js',
`
/** changed - ${i} **/
const nextConfig = {
reactStrictMode: true,
async redirects() {
return [
{
source: '/about',
destination: '/',
permanent: true,
},
]
},
}
module.exports = nextConfig`
)
return next.cliOutput
}, /Found a change in next.config.js. Restart the server to see the changes in effect./)
})
})
await check(
async () => next.cliOutput,
/Found a change in next\.config\.js\. Restarting the server to apply the changes\.\.\./
)
await check(() => next.fetch('/about').then((res) => res.status), 200)
})
}
)
......@@ -88,7 +88,7 @@ export class NextDevInstance extends NextInstance {
msg,
})
}
this.off('stdout', readyCb)
// server might reload so we keep listening
resolve()
}
}
......
......@@ -551,7 +551,7 @@ export async function check(
for (let tries = 0; tries < maxRetries; tries++) {
try {
content = await contentFn()
if (typeof regex === 'string') {
if (typeof regex !== typeof /regex/) {
if (regex === content) {
return 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