mirror of
https://github.com/denoland/deno.git
synced 2025-02-01 20:25:12 -05:00
fix(cli/tests): flaky Deno.watchFs() tests (#12485)
This commit is contained in:
parent
a2f53b105d
commit
d77a4f1d43
1 changed files with 19 additions and 5 deletions
|
@ -1,5 +1,11 @@
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// 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.
|
// TODO(ry) Add more tests to specify format.
|
||||||
|
|
||||||
|
@ -36,10 +42,18 @@ async function getTwoEvents(
|
||||||
return events;
|
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(
|
unitTest(
|
||||||
{ permissions: { read: true, write: true } },
|
{ permissions: { read: true, write: true } },
|
||||||
async function watchFsBasic() {
|
async function watchFsBasic() {
|
||||||
const testDir = Deno.makeTempDirSync();
|
const testDir = await makeTempDir();
|
||||||
const iter = Deno.watchFs(testDir);
|
const iter = Deno.watchFs(testDir);
|
||||||
|
|
||||||
// Asynchornously capture two fs events.
|
// Asynchornously capture two fs events.
|
||||||
|
@ -66,7 +80,7 @@ unitTest(
|
||||||
unitTest(
|
unitTest(
|
||||||
{ permissions: { read: true, write: true } },
|
{ permissions: { read: true, write: true } },
|
||||||
async function watchFsReturn() {
|
async function watchFsReturn() {
|
||||||
const testDir = Deno.makeTempDirSync();
|
const testDir = await makeTempDir();
|
||||||
const iter = Deno.watchFs(testDir);
|
const iter = Deno.watchFs(testDir);
|
||||||
|
|
||||||
// Asynchronously loop events.
|
// Asynchronously loop events.
|
||||||
|
@ -84,14 +98,14 @@ unitTest(
|
||||||
unitTest(
|
unitTest(
|
||||||
{ permissions: { read: true, write: true } },
|
{ permissions: { read: true, write: true } },
|
||||||
async function watchFsClose() {
|
async function watchFsClose() {
|
||||||
const testDir = Deno.makeTempDirSync();
|
const testDir = await makeTempDir();
|
||||||
const iter = Deno.watchFs(testDir);
|
const iter = Deno.watchFs(testDir);
|
||||||
|
|
||||||
// Asynchronously loop events.
|
// Asynchronously loop events.
|
||||||
const eventsPromise = getTwoEvents(iter);
|
const eventsPromise = getTwoEvents(iter);
|
||||||
|
|
||||||
// Close the watcher.
|
// Close the watcher.
|
||||||
await iter.close();
|
iter.close();
|
||||||
|
|
||||||
// Expect zero events.
|
// Expect zero events.
|
||||||
const events = await eventsPromise;
|
const events = await eventsPromise;
|
||||||
|
|
Loading…
Add table
Reference in a new issue