Skip to content

Commit 51ac8f4

Browse files
vrubezhnydatho7561
authored andcommitted
[tests] Fix File Watcher Utility test - close FileWatcher
Also, avoided to watch the whole temp directory because of its possibly very big size in order to not get 'too many open files error Signed-off-by: Victor Rubezhny <[email protected]>
1 parent 4f747b1 commit 51ac8f4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

test/unit/util/watch.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,24 @@ suite('File Watch Utility', () => {
5252
test('emits change message when context changes', async () => {
5353
ensureStub.restore();
5454
watchStub.restore();
55-
const fileToWatch = fs.realpathSync(tmp.fileSync().name);
55+
56+
// Make a temp sub-directory to avoid watching the whole temp directory
57+
const tmpFile = tmp.fileSync({dir:`${path.basename(tmp.dirSync().name)}`});
58+
const fileToWatch = fs.realpathSync(tmpFile.name);
5659
fs.ensureFileSync(fileToWatch);
5760
const notifier = WatchUtil.watchFileForContextChange(path.dirname(fileToWatch), path.basename(fileToWatch));
5861
setTimeout(() => {
5962
fs.writeFileSync(fileToWatch, 'current-context:test2');
6063
}, 1000);
61-
return new Promise((res) => {
64+
return new Promise<void>((res) => {
6265
notifier.emitter.on('file-changed', (file) => {
6366
expect(file).equals(undefined);
6467
res();
6568
});
69+
}).finally(() => {
70+
if (notifier && notifier.watcher) {
71+
notifier.watcher.close();
72+
}
6673
});
6774
});
6875
});

0 commit comments

Comments
 (0)