From b587277e5a93826a6091e6747c7dd1a88e78c660 Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Tue, 28 Mar 2023 10:46:34 +0200 Subject: [PATCH] test(ext/node): add timers_tests.ts from std/node This PR ports timers_tests.ts from std/node as part of #17840 --- cli/tests/unit_node/timers_test.ts | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 cli/tests/unit_node/timers_test.ts diff --git a/cli/tests/unit_node/timers_test.ts b/cli/tests/unit_node/timers_test.ts new file mode 100644 index 00000000000000..8676edb766ce03 --- /dev/null +++ b/cli/tests/unit_node/timers_test.ts @@ -0,0 +1,52 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. + +import { assert } from "../../../test_util/std/testing/asserts.ts"; +import * as timers from "node:timers"; +import * as timersPromises from "node:timers/promises"; + +Deno.test("[node/timers setTimeout]", () => { + { + const { clearTimeout, setTimeout } = timers; + const id = setTimeout(() => {}); + clearTimeout(id); + } + + { + const id = timers.setTimeout(() => {}); + timers.clearTimeout(id); + } +}); + +Deno.test("[node/timers setInterval]", () => { + { + const { clearInterval, setInterval } = timers; + const id = setInterval(() => {}); + clearInterval(id); + } + + { + const id = timers.setInterval(() => {}); + timers.clearInterval(id); + } +}); + +Deno.test("[node/timers setImmediate]", () => { + { + const { clearImmediate, setImmediate } = timers; + const id = setImmediate(() => {}); + clearImmediate(id); + } + + { + const id = timers.setImmediate(() => {}); + timers.clearImmediate(id); + } +}); + +Deno.test("[node/timers/promises setTimeout]", () => { + const { setTimeout } = timersPromises; + const p = setTimeout(0); + + assert(p instanceof Promise); + return p; +});