From e6f5abb165264a7ef50ae9b52b54f00ec229e94f Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Thu, 27 Jan 2022 12:38:34 +0200 Subject: [PATCH] test: make fs watch test more stable --- test/pummel/test-fs-watch-non-recursive.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/test/pummel/test-fs-watch-non-recursive.js b/test/pummel/test-fs-watch-non-recursive.js index 49071a965f1737..4bcdf1cb9bc091 100644 --- a/test/pummel/test-fs-watch-non-recursive.js +++ b/test/pummel/test-fs-watch-non-recursive.js @@ -28,7 +28,7 @@ if (common.isIBMi) { const path = require('path'); const fs = require('fs'); - +const assert = require('assert'); const tmpdir = require('../common/tmpdir'); tmpdir.refresh(); @@ -38,13 +38,12 @@ const filepath = path.join(testsubdir, 'watch.txt'); fs.mkdirSync(testsubdir, 0o700); -// Need a grace period, else the mkdirSync() above fires off an event. +const watcher = fs.watch(testDir, { persistent: true }, (event, filename) => { + assert.equal(filename, 'testsubdir'); +}); +setTimeout(function() { + fs.writeFileSync(filepath, 'test'); +}, 100); setTimeout(function() { - const watcher = fs.watch(testDir, { persistent: true }, common.mustNotCall()); - setTimeout(function() { - fs.writeFileSync(filepath, 'test'); - }, 100); - setTimeout(function() { - watcher.close(); - }, 500); -}, 50); + watcher.close(); +}, 500);