From d77a4f1d43f8ff74b7d0d69e10179293fca0447c Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Tue, 19 Oct 2021 12:50:13 +0100 Subject: [PATCH] fix(cli/tests): flaky Deno.watchFs() tests (#12485) --- cli/tests/unit/fs_events_test.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/cli/tests/unit/fs_events_test.ts b/cli/tests/unit/fs_events_test.ts index 497c421faa..a839e64f1d 100644 --- a/cli/tests/unit/fs_events_test.ts +++ b/cli/tests/unit/fs_events_test.ts @@ -1,5 +1,11 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals, assertThrows, unitTest } from "./test_util.ts"; +import { + assert, + assertEquals, + assertThrows, + delay, + unitTest, +} from "./test_util.ts"; // TODO(ry) Add more tests to specify format. @@ -36,10 +42,18 @@ async function getTwoEvents( return events; } +async function makeTempDir(): Promise { + const testDir = await Deno.makeTempDir(); + // The watcher sometimes witnesses the creation of it's own root + // directory. Delay a bit. + await delay(100); + return testDir; +} + unitTest( { permissions: { read: true, write: true } }, async function watchFsBasic() { - const testDir = Deno.makeTempDirSync(); + const testDir = await makeTempDir(); const iter = Deno.watchFs(testDir); // Asynchornously capture two fs events. @@ -66,7 +80,7 @@ unitTest( unitTest( { permissions: { read: true, write: true } }, async function watchFsReturn() { - const testDir = Deno.makeTempDirSync(); + const testDir = await makeTempDir(); const iter = Deno.watchFs(testDir); // Asynchronously loop events. @@ -84,14 +98,14 @@ unitTest( unitTest( { permissions: { read: true, write: true } }, async function watchFsClose() { - const testDir = Deno.makeTempDirSync(); + const testDir = await makeTempDir(); const iter = Deno.watchFs(testDir); // Asynchronously loop events. const eventsPromise = getTwoEvents(iter); // Close the watcher. - await iter.close(); + iter.close(); // Expect zero events. const events = await eventsPromise;