summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorAndreu Botella <abb@randomunok.com>2021-12-16 12:58:24 +0100
committerGitHub <noreply@github.com>2021-12-16 12:58:24 +0100
commit8efe829fca5ddea855b7f569c74b67c161ec4b06 (patch)
tree23d26621701c4ff9290c4f4711abab345c3d4219 /cli
parent01a6b66034b53dbeffaa12d1d408066a1bc28643 (diff)
feat(fetch): support abort reasons in fetch (#13106)
Diffstat (limited to 'cli')
-rw-r--r--cli/tests/unit/fetch_test.ts55
1 files changed, 54 insertions, 1 deletions
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts
index c22fc5226..cbd0139a3 100644
--- a/cli/tests/unit/fetch_test.ts
+++ b/cli/tests/unit/fetch_test.ts
@@ -1272,7 +1272,60 @@ Deno.test(
} catch (error) {
assert(error instanceof DOMException);
assertEquals(error.name, "AbortError");
- assertEquals(error.message, "Ongoing fetch was aborted.");
+ assertEquals(error.message, "The signal has been aborted");
+ }
+ },
+);
+
+Deno.test(
+ { permissions: { net: true } },
+ async function fetchAbortWhileUploadStreamingWithReason(): Promise<void> {
+ const abortController = new AbortController();
+ const abortReason = new Error();
+ try {
+ await fetch(
+ "http://localhost:5552/echo_server",
+ {
+ method: "POST",
+ body: new ReadableStream({
+ pull(controller) {
+ abortController.abort(abortReason);
+ controller.enqueue(new Uint8Array([1, 2, 3, 4]));
+ },
+ }),
+ signal: abortController.signal,
+ },
+ );
+ fail("Fetch didn't reject.");
+ } catch (error) {
+ assertEquals(error, abortReason);
+ }
+ },
+);
+
+Deno.test(
+ { permissions: { net: true } },
+ async function fetchAbortWhileUploadStreamingWithPrimitiveReason(): Promise<
+ void
+ > {
+ const abortController = new AbortController();
+ try {
+ await fetch(
+ "http://localhost:5552/echo_server",
+ {
+ method: "POST",
+ body: new ReadableStream({
+ pull(controller) {
+ abortController.abort("Abort reason");
+ controller.enqueue(new Uint8Array([1, 2, 3, 4]));
+ },
+ }),
+ signal: abortController.signal,
+ },
+ );
+ fail("Fetch didn't reject.");
+ } catch (error) {
+ assertEquals(error, "Abort reason");
}
},
);