summaryrefslogtreecommitdiff
path: root/cli/tests/unit/write_file_test.ts
diff options
context:
space:
mode:
authorBenjamin Gruenbaum <benjamingr@gmail.com>2021-08-06 20:21:29 +0300
committerGitHub <noreply@github.com>2021-08-06 10:21:29 -0700
commit2b53602d3c798b68db4ce986546d3434b986096a (patch)
tree8b8a1bf86d3f890302b50f21ce0632df1e2d9728 /cli/tests/unit/write_file_test.ts
parent466d3df9d1ff43e16e1a2c20b7792de664547b48 (diff)
feat: support AbortSignal in writeFile (#11568)
Diffstat (limited to 'cli/tests/unit/write_file_test.ts')
-rw-r--r--cli/tests/unit/write_file_test.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/cli/tests/unit/write_file_test.ts b/cli/tests/unit/write_file_test.ts
index 4c4cecf43..c4c437708 100644
--- a/cli/tests/unit/write_file_test.ts
+++ b/cli/tests/unit/write_file_test.ts
@@ -239,3 +239,39 @@ unitTest(
assertEquals("Hello", actual);
},
);
+
+unitTest(
+ { perms: { read: true, write: true } },
+ async function writeFileAbortSignal(): Promise<void> {
+ const ac = new AbortController();
+ const enc = new TextEncoder();
+ const data = enc.encode("Hello");
+ const filename = Deno.makeTempDirSync() + "/test.txt";
+ queueMicrotask(() => ac.abort());
+ try {
+ await Deno.writeFile(filename, data, { signal: ac.signal });
+ } catch (e) {
+ assertEquals(e.name, "AbortError");
+ }
+ const stat = Deno.statSync(filename);
+ assertEquals(stat.size, 0);
+ },
+);
+
+unitTest(
+ { perms: { read: true, write: true } },
+ async function writeFileAbortSignalPreAborted(): Promise<void> {
+ const ac = new AbortController();
+ ac.abort();
+ const enc = new TextEncoder();
+ const data = enc.encode("Hello");
+ const filename = Deno.makeTempDirSync() + "/test.txt";
+ try {
+ await Deno.writeFile(filename, data, { signal: ac.signal });
+ } catch (e) {
+ assertEquals(e.name, "AbortError");
+ }
+ const stat = Deno.statSync(filename);
+ assertEquals(stat.size, 0);
+ },
+);