mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-04 11:27:13 +00:00
fix(builder): call watch:restart
after watch:fileChanged
hook (#5620)
This commit is contained in:
parent
f831126e27
commit
9fb720d518
@ -663,12 +663,12 @@ export default class Builder {
|
|||||||
this.createFileWatcher(
|
this.createFileWatcher(
|
||||||
nuxtRestartWatch,
|
nuxtRestartWatch,
|
||||||
['all'],
|
['all'],
|
||||||
(event, fileName) => {
|
async (event, fileName) => {
|
||||||
if (['add', 'change', 'unlink'].includes(event) === false) {
|
if (['add', 'change', 'unlink'].includes(event) === false) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.nuxt.callHook('watch:fileChanged', this, fileName) // Legacy
|
await this.nuxt.callHook('watch:fileChanged', this, fileName) // Legacy
|
||||||
this.nuxt.callHook('watch:restart', { event, path: fileName })
|
await this.nuxt.callHook('watch:restart', { event, path: fileName })
|
||||||
},
|
},
|
||||||
this.assignWatcher('restart')
|
this.assignWatcher('restart')
|
||||||
)
|
)
|
||||||
|
@ -244,7 +244,7 @@ describe('builder: builder watch', () => {
|
|||||||
expect(chokidar.on).toBeCalledWith('all', expect.any(Function))
|
expect(chokidar.on).toBeCalledWith('all', expect.any(Function))
|
||||||
})
|
})
|
||||||
|
|
||||||
test('should trigger restarting when files changed', () => {
|
test('should trigger restarting when files changed', async () => {
|
||||||
const nuxt = createNuxt()
|
const nuxt = createNuxt()
|
||||||
nuxt.options.watchers = {
|
nuxt.options.watchers = {
|
||||||
chokidar: { test: true }
|
chokidar: { test: true }
|
||||||
@ -259,9 +259,9 @@ describe('builder: builder watch', () => {
|
|||||||
|
|
||||||
const restartHandler = chokidar.on.mock.calls[0][1]
|
const restartHandler = chokidar.on.mock.calls[0][1]
|
||||||
const watchingFile = '/var/nuxt/src/watch/test/index.js'
|
const watchingFile = '/var/nuxt/src/watch/test/index.js'
|
||||||
restartHandler('add', watchingFile)
|
await restartHandler('add', watchingFile)
|
||||||
restartHandler('change', watchingFile)
|
await restartHandler('change', watchingFile)
|
||||||
restartHandler('unlink', watchingFile)
|
await restartHandler('unlink', watchingFile)
|
||||||
|
|
||||||
expect(nuxt.callHook).toBeCalledTimes(6)
|
expect(nuxt.callHook).toBeCalledTimes(6)
|
||||||
expect(nuxt.callHook).nthCalledWith(1, 'watch:fileChanged', builder, watchingFile)
|
expect(nuxt.callHook).nthCalledWith(1, 'watch:fileChanged', builder, watchingFile)
|
||||||
|
Loading…
Reference in New Issue
Block a user