diff --git a/packages/builder/src/builder.js b/packages/builder/src/builder.js index 09aa77a99c..561e15d9a9 100644 --- a/packages/builder/src/builder.js +++ b/packages/builder/src/builder.js @@ -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') ) diff --git a/packages/builder/test/builder.watch.test.js b/packages/builder/test/builder.watch.test.js index 3cbab9e7eb..ab9e2dd5b3 100644 --- a/packages/builder/test/builder.watch.test.js +++ b/packages/builder/test/builder.watch.test.js @@ -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)