From 9fb720d51820be359a04156abb8a0530a963a096 Mon Sep 17 00:00:00 2001 From: "Xin Du (Clark)" Date: Mon, 29 Apr 2019 19:20:38 +0100 Subject: [PATCH] fix(builder): call `watch:restart` after `watch:fileChanged` hook (#5620) --- packages/builder/src/builder.js | 6 +++--- packages/builder/test/builder.watch.test.js | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) 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)