summaryrefslogtreecommitdiff
path: root/cli/tests/unit_node/internal
diff options
context:
space:
mode:
authorAsher Gomez <ashersaupingomez@gmail.com>2023-11-22 22:11:20 +1100
committerGitHub <noreply@github.com>2023-11-22 12:11:20 +0100
commit616354e76cba0be8af20a0ffefeacfcf6101bafc (patch)
treec832c81dd93498e196840c8d59c0a4ab76396d07 /cli/tests/unit_node/internal
parent0ffcb46e0f60110c07e21151db6066f5a1b5f710 (diff)
refactor: replace `deferred()` from `std/async` with `Promise.withResolvers()` (#21234)
Closes #21041 --------- Signed-off-by: Asher Gomez <ashersaupingomez@gmail.com>
Diffstat (limited to 'cli/tests/unit_node/internal')
-rw-r--r--cli/tests/unit_node/internal/_randomFill_test.ts5
-rw-r--r--cli/tests/unit_node/internal/scrypt_test.ts9
2 files changed, 6 insertions, 8 deletions
diff --git a/cli/tests/unit_node/internal/_randomFill_test.ts b/cli/tests/unit_node/internal/_randomFill_test.ts
index 5e2e154c8..5d56ca65a 100644
--- a/cli/tests/unit_node/internal/_randomFill_test.ts
+++ b/cli/tests/unit_node/internal/_randomFill_test.ts
@@ -6,7 +6,6 @@ import {
assertNotEquals,
assertThrows,
} from "../../../../test_util/std/testing/asserts.ts";
-import { deferred } from "../../../../test_util/std/async/deferred.ts";
const validateNonZero = (buf: Buffer) => {
if (!buf.some((ch) => ch > 0)) throw new Error("Error");
@@ -17,14 +16,14 @@ const validateZero = (buf: Buffer) => {
};
Deno.test("[node/crypto.randomFill]", async () => {
- const promise = deferred();
+ const { promise, resolve } = Promise.withResolvers<boolean>();
const buf = Buffer.alloc(10);
const before = buf.toString("hex");
randomFill(buf, 5, 5, (_err, bufTwo) => {
const after = bufTwo?.toString("hex");
assertEquals(before.slice(0, 10), after?.slice(0, 10));
- promise.resolve(true);
+ resolve(true);
});
await promise;
diff --git a/cli/tests/unit_node/internal/scrypt_test.ts b/cli/tests/unit_node/internal/scrypt_test.ts
index d65cd27ff..83830f8e4 100644
--- a/cli/tests/unit_node/internal/scrypt_test.ts
+++ b/cli/tests/unit_node/internal/scrypt_test.ts
@@ -2,10 +2,9 @@
import { scrypt, scryptSync } from "node:crypto";
import { Buffer } from "node:buffer";
import { assertEquals } from "../../../../test_util/std/testing/asserts.ts";
-import { deferred } from "../../../../test_util/std/async/deferred.ts";
Deno.test("scrypt works correctly", async () => {
- const promise = deferred();
+ const { promise, resolve } = Promise.withResolvers<boolean>();
scrypt("password", "salt", 32, (err, key) => {
if (err) throw err;
@@ -46,14 +45,14 @@ Deno.test("scrypt works correctly", async () => {
115,
]),
);
- promise.resolve(true);
+ resolve(true);
});
await promise;
});
Deno.test("scrypt works with options", async () => {
- const promise = deferred();
+ const { promise, resolve } = Promise.withResolvers<boolean>();
scrypt(
"password",
@@ -101,7 +100,7 @@ Deno.test("scrypt works with options", async () => {
71,
]),
);
- promise.resolve(true);
+ resolve(true);
},
);