From 16cea0b7c86e3374b3691250896fe30c481f54b8 Mon Sep 17 00:00:00 2001 From: shmck Date: Sat, 4 Apr 2020 17:46:03 -0700 Subject: [PATCH] fix multiple watcher firings --- src/actions/utils/loadWatchers.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/actions/utils/loadWatchers.ts b/src/actions/utils/loadWatchers.ts index 2e4d640a..c1d54c94 100644 --- a/src/actions/utils/loadWatchers.ts +++ b/src/actions/utils/loadWatchers.ts @@ -34,11 +34,18 @@ const loadWatchers = (watchers: string[], workspaceUri: vscode.Uri) => { interval: 1000, }) + // prevent firing tests within 1 second of last test check + const lastFire: Date | null = null + + // run tests on watcher change fsWatcher.on('change', (path, event) => { - vscode.commands.executeCommand(COMMANDS.RUN_TEST, null, () => { - // cleanup watcher on success - disposeWatcher(watcher) - }) + const now = +new Date() + if (!lastFire || lastFire - now > 1000) { + vscode.commands.executeCommand(COMMANDS.RUN_TEST, null, () => { + // cleanup watcher on success + disposeWatcher(watcher) + }) + } }) // key fs watcher on name