diff options
author | Asher Gomez <ashersaupingomez@gmail.com> | 2023-11-22 22:11:20 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-22 12:11:20 +0100 |
commit | 616354e76cba0be8af20a0ffefeacfcf6101bafc (patch) | |
tree | c832c81dd93498e196840c8d59c0a4ab76396d07 /cli/tests/unit_node/_fs | |
parent | 0ffcb46e0f60110c07e21151db6066f5a1b5f710 (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/_fs')
-rw-r--r-- | cli/tests/unit_node/_fs/_fs_read_test.ts | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/cli/tests/unit_node/_fs/_fs_read_test.ts b/cli/tests/unit_node/_fs/_fs_read_test.ts index 34b029d9f..3ca303037 100644 --- a/cli/tests/unit_node/_fs/_fs_read_test.ts +++ b/cli/tests/unit_node/_fs/_fs_read_test.ts @@ -10,7 +10,6 @@ import { open, openSync } from "node:fs"; import { Buffer } from "node:buffer"; import * as path from "../../../../test_util/std/path/mod.ts"; import { closeSync } from "node:fs"; -import { deferred } from "../../../../test_util/std/async/deferred.ts"; async function readTest( testData: string, @@ -132,7 +131,7 @@ Deno.test({ Deno.test({ name: "[std/node/fs] Read fs.read(fd, options, cb) signature", async fn() { - const promise = deferred(); + const { promise, reject, resolve } = Promise.withResolvers<void>(); const file = Deno.makeTempFileSync(); Deno.writeTextFileSync(file, "hi there"); const fd = openSync(file, "r+"); @@ -154,10 +153,10 @@ Deno.test({ Buffer.from([104, 105, 32, 116, 104, 101, 114, 101, 0, 0, 0]), ); } catch (e) { - promise.reject(e); + reject(e); return; } - promise.resolve(); + resolve(); }, ); closeSync(fd); @@ -168,7 +167,7 @@ Deno.test({ Deno.test({ name: "[std/node/fs] Read fs.read(fd, cb) signature", async fn() { - const promise = deferred(); + const { promise, resolve, reject } = Promise.withResolvers<void>(); const file = Deno.makeTempFileSync(); Deno.writeTextFileSync(file, "hi deno"); const fd = openSync(file, "r+"); @@ -178,10 +177,10 @@ Deno.test({ assertStrictEquals(bytesRead, 7); assertStrictEquals(data?.byteLength, 16384); } catch (e) { - promise.reject(e); + reject(e); return; } - promise.resolve(); + resolve(); }); closeSync(fd); await promise; @@ -277,27 +276,27 @@ Deno.test({ await Deno.writeTextFile(file, "abc"); await t.step("without position option", async () => { - const promise = deferred<void>(); + const { promise, resolve } = Promise.withResolvers<void>(); let called = false; const fd = openSync(file, "r"); read(fd, () => { called = true; closeSync(fd); - promise.resolve(); + resolve(); }); assertFalse(called); await promise; }); await t.step("with position option", async () => { - const promise = deferred<void>(); + const { promise, resolve } = Promise.withResolvers<void>(); let called = false; const buffer = Buffer.alloc(2); const fd = openSync(file, "r"); read(fd, { position: 1, buffer, offset: 0, length: 2 }, () => { called = true; closeSync(fd); - promise.resolve(); + resolve(); }); assertFalse(called); await promise; |