fix(builder): call `watch:restart` after `watch:fileChanged` hook (#5620)

This commit is contained in:
Xin Du (Clark) 2019-04-29 19:20:38 +01:00 committed by Pooya Parsa
parent f831126e27
commit 9fb720d518
2 changed files with 7 additions and 7 deletions

View File

@ -663,12 +663,12 @@ export default class Builder {
this.createFileWatcher(
nuxtRestartWatch,
['all'],
(event, fileName) => {
async (event, fileName) => {
if (['add', 'change', 'unlink'].includes(event) === false) {
return
}
this.nuxt.callHook('watch:fileChanged', this, fileName) // Legacy
this.nuxt.callHook('watch:restart', { event, path: fileName })
await this.nuxt.callHook('watch:fileChanged', this, fileName) // Legacy
await this.nuxt.callHook('watch:restart', { event, path: fileName })
},
this.assignWatcher('restart')
)

View File

@ -244,7 +244,7 @@ describe('builder: builder watch', () => {
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()
nuxt.options.watchers = {
chokidar: { test: true }
@ -259,9 +259,9 @@ describe('builder: builder watch', () => {
const restartHandler = chokidar.on.mock.calls[0][1]
const watchingFile = '/var/nuxt/src/watch/test/index.js'
restartHandler('add', watchingFile)
restartHandler('change', watchingFile)
restartHandler('unlink', watchingFile)
await restartHandler('add', watchingFile)
await restartHandler('change', watchingFile)
await restartHandler('unlink', watchingFile)
expect(nuxt.callHook).toBeCalledTimes(6)
expect(nuxt.callHook).nthCalledWith(1, 'watch:fileChanged', builder, watchingFile)