test(cli): refactor the usages of delay (#11098)

This PR refactors the usages of delay utility in js unit testing. The same
utiliy is defined in several places with different names. This PR replaces those
usages with the one provided in std/async/delay.ts to improve the readability
and consistency of test code.
This commit is contained in:
Yoshiya Hinosawa 2021-06-25 10:44:14 +09:00 committed by GitHub
parent dd4ed82576
commit 66c5f41c5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 32 deletions

View file

@ -4,15 +4,10 @@ import {
assertEquals,
assertThrows,
deferred,
delay,
unitTest,
} from "./test_util.ts";
function defer(n: number): Promise<void> {
return new Promise((resolve: () => void, _) => {
setTimeout(resolve, n);
});
}
unitTest(
{ ignore: Deno.build.os !== "windows" },
function signalsNotImplemented(): void {
@ -113,11 +108,11 @@ unitTest(
let c = 0;
const sig = Deno.signal(Deno.Signal.SIGUSR1);
setTimeout(async () => {
await defer(20);
await delay(20);
for (const _ of Array(3)) {
// Sends SIGUSR1 3 times.
Deno.kill(Deno.pid, Deno.Signal.SIGUSR1);
await defer(20);
await delay(20);
}
sig.dispose();
resolvable.resolve();