diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2023-08-04 22:29:04 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-04 22:29:04 +0900 |
commit | 8a175a780a43b4cec7adfff5adbc65d8784aa4ed (patch) | |
tree | f341f4624402ded312b0c89659d5a135ac01cd35 /cli | |
parent | 6405b5f454e140b0d79b603b0627debd246c7b9f (diff) |
fix(test): make test runner work when global setTimeout is replaced (#20052)
Diffstat (limited to 'cli')
-rw-r--r-- | cli/js/40_testing.js | 1 | ||||
-rw-r--r-- | cli/tests/integration/test_tests.rs | 5 | ||||
-rw-r--r-- | cli/tests/testdata/test/replace_timers.js | 7 | ||||
-rw-r--r-- | cli/tests/testdata/test/replace_timers.js.out | 7 |
4 files changed, 20 insertions, 0 deletions
diff --git a/cli/js/40_testing.js b/cli/js/40_testing.js index 90a725fca..c073b1c18 100644 --- a/cli/js/40_testing.js +++ b/cli/js/40_testing.js @@ -5,6 +5,7 @@ const ops = core.ops; import { setExitHandler } from "ext:runtime/30_os.js"; import { Console } from "ext:deno_console/01_console.js"; import { serializePermissions } from "ext:runtime/10_permissions.js"; +import { setTimeout } from "ext:deno_web/02_timers.js"; import { assert } from "ext:deno_web/00_infra.js"; const primordials = globalThis.__bootstrap.primordials; const { diff --git a/cli/tests/integration/test_tests.rs b/cli/tests/integration/test_tests.rs index 57acb723e..bcf050adf 100644 --- a/cli/tests/integration/test_tests.rs +++ b/cli/tests/integration/test_tests.rs @@ -529,6 +529,11 @@ itest!(test_no_lock { output: "lockfile/basic/test.nolock.out", }); +itest!(test_replace_timers { + args: "test test/replace_timers.js", + output: "test/replace_timers.js.out", +}); + #[test] fn test_with_glob_config() { let context = TestContextBuilder::new().cwd("test").build(); diff --git a/cli/tests/testdata/test/replace_timers.js b/cli/tests/testdata/test/replace_timers.js new file mode 100644 index 000000000..692f1d671 --- /dev/null +++ b/cli/tests/testdata/test/replace_timers.js @@ -0,0 +1,7 @@ +Deno.test("foo", async (t) => { + globalThis.setTimeout = () => {}; + globalThis.clearTimeout = () => {}; + globalThis.setInterval = () => {}; + globalThis.clearInterval = () => {}; + await t.step("bar", () => {}); +}); diff --git a/cli/tests/testdata/test/replace_timers.js.out b/cli/tests/testdata/test/replace_timers.js.out new file mode 100644 index 000000000..81beb5ebe --- /dev/null +++ b/cli/tests/testdata/test/replace_timers.js.out @@ -0,0 +1,7 @@ +running 1 test from ./test/replace_timers.js +foo ... + bar ... ok ([WILDCARD]) +foo ... ok ([WILDCARD]) + +ok | 1 passed (1 step) | 0 failed ([WILDCARD]) + |