diff options
author | Tareque Md Hanif <tarequemd.hanif@yahoo.com> | 2023-11-11 03:29:09 +0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-10 14:29:09 -0700 |
commit | eff3e432966f6bc9ed909ba22fcafc0978c924d7 (patch) | |
tree | 9081548c2f804f312121673c4070825831605495 /cli/tests/unit/cron_test.ts | |
parent | df14835b83085017e9cf9ae66a71cd523385c5c4 (diff) |
chore(cli): Migrate some unit tests to "Promise.withResolvers()" (#21128)
Migrate to use `Promise.withResolvers()` instead of `deferred` in some
of the tests in `cli/tests/unit/`.
Issue: #21041
Diffstat (limited to 'cli/tests/unit/cron_test.ts')
-rw-r--r-- | cli/tests/unit/cron_test.ts | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/cli/tests/unit/cron_test.ts b/cli/tests/unit/cron_test.ts index 636a04fd2..1d46efdb4 100644 --- a/cli/tests/unit/cron_test.ts +++ b/cli/tests/unit/cron_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertThrows, deferred } from "./test_util.ts"; +import { assertEquals, assertThrows } from "./test_util.ts"; const sleep = (time: number) => new Promise((r) => setTimeout(r, time)); @@ -151,12 +151,12 @@ Deno.test(async function basicTest() { Deno.env.set("DENO_CRON_TEST_SCHEDULE_OFFSET", "100"); let count = 0; - const promise = deferred(); + const { promise, resolve } = Promise.withResolvers<void>(); const ac = new AbortController(); const c = Deno.cron("abc", "*/20 * * * *", () => { count++; if (count > 5) { - promise.resolve(); + resolve(); } }, { signal: ac.signal }); try { @@ -172,19 +172,23 @@ Deno.test(async function multipleCrons() { let count0 = 0; let count1 = 0; - const promise0 = deferred(); - const promise1 = deferred(); + const { promise: promise0, resolve: resolve0 } = Promise.withResolvers< + void + >(); + const { promise: promise1, resolve: resolve1 } = Promise.withResolvers< + void + >(); const ac = new AbortController(); const c0 = Deno.cron("abc", "*/20 * * * *", () => { count0++; if (count0 > 5) { - promise0.resolve(); + resolve0(); } }, { signal: ac.signal }); const c1 = Deno.cron("xyz", "*/20 * * * *", () => { count1++; if (count1 > 5) { - promise1.resolve(); + resolve1(); } }, { signal: ac.signal }); try { @@ -201,11 +205,15 @@ Deno.test(async function overlappingExecutions() { Deno.env.set("DENO_CRON_TEST_SCHEDULE_OFFSET", "100"); let count = 0; - const promise0 = deferred(); - const promise1 = deferred(); + const { promise: promise0, resolve: resolve0 } = Promise.withResolvers< + void + >(); + const { promise: promise1, resolve: resolve1 } = Promise.withResolvers< + void + >(); const ac = new AbortController(); const c = Deno.cron("abc", "*/20 * * * *", async () => { - promise0.resolve(); + resolve0(); count++; await promise1; }, { signal: ac.signal }); @@ -213,7 +221,7 @@ Deno.test(async function overlappingExecutions() { await promise0; } finally { await sleep(2000); - promise1.resolve(); + resolve1(); ac.abort(); await c; } |