diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2021-10-19 12:50:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-19 07:50:13 -0400 |
commit | d77a4f1d43f8ff74b7d0d69e10179293fca0447c (patch) | |
tree | 2a2d05a3c7c99d8971d6307d0a5277340b34a70c | |
parent | a2f53b105def7385e9b2ebae36cd0a2b8f0c89ff (diff) |
fix(cli/tests): flaky Deno.watchFs() tests (#12485)
-rw-r--r-- | cli/tests/unit/fs_events_test.ts | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/cli/tests/unit/fs_events_test.ts b/cli/tests/unit/fs_events_test.ts index 497c421fa..a839e64f1 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<string> { + 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; |