diff options
author | Andreu Botella <abb@randomunok.com> | 2021-12-16 12:57:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-16 12:57:26 +0100 |
commit | 01a6b66034b53dbeffaa12d1d408066a1bc28643 (patch) | |
tree | 020291ed0b71562b6376bda2989925f105f6fadd /cli/tests/unit/read_text_file_test.ts | |
parent | 9ffc7edc23444be8bdcc1befd3709b309780e3d1 (diff) |
feat: support abort reasons in Deno APIs and `WebSocketStream` (#13066)
Diffstat (limited to 'cli/tests/unit/read_text_file_test.ts')
-rw-r--r-- | cli/tests/unit/read_text_file_test.ts | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/cli/tests/unit/read_text_file_test.ts b/cli/tests/unit/read_text_file_test.ts index 6e7dce73e..169972cb4 100644 --- a/cli/tests/unit/read_text_file_test.ts +++ b/cli/tests/unit/read_text_file_test.ts @@ -4,6 +4,7 @@ import { assertRejects, assertThrows, pathToAbsoluteFileUrl, + unreachable, } from "./test_util.ts"; Deno.test({ permissions: { read: true } }, function readTextFileSyncSuccess() { @@ -88,11 +89,52 @@ Deno.test( async function readTextFileWithAbortSignal() { const ac = new AbortController(); queueMicrotask(() => ac.abort()); - await assertRejects(async () => { + await assertRejects( + async () => { + await Deno.readFile("cli/tests/testdata/fixture.json", { + signal: ac.signal, + }); + }, + (error: Error) => { + assert(error instanceof DOMException); + assertEquals(error.name, "AbortError"); + }, + ); + }, +); + +Deno.test( + { permissions: { read: true } }, + async function readTextFileWithAbortSignalReason() { + const ac = new AbortController(); + const abortReason = new Error(); + queueMicrotask(() => ac.abort(abortReason)); + await assertRejects( + async () => { + await Deno.readFile("cli/tests/testdata/fixture.json", { + signal: ac.signal, + }); + }, + (error: Error) => { + assertEquals(error, abortReason); + }, + ); + }, +); + +Deno.test( + { permissions: { read: true } }, + async function readTextFileWithAbortSignalPrimitiveReason() { + const ac = new AbortController(); + queueMicrotask(() => ac.abort("Some string")); + try { await Deno.readFile("cli/tests/testdata/fixture.json", { signal: ac.signal, }); - }); + unreachable(); + } catch (e) { + assertEquals(e, "Some string"); + } }, ); |