summaryrefslogtreecommitdiff
path: root/cli/tests/unit/fetch_test.ts
diff options
context:
space:
mode:
authorYusuke Tanaka <yusuktan@maguro.dev>2023-12-06 16:52:59 +0900
committerGitHub <noreply@github.com>2023-12-06 16:52:59 +0900
commitdadd8b3d660fd2fd56803f29e1d8b6dd7a2adde9 (patch)
tree011a23d81af0ffd123c83cf47ed31c2338f377d9 /cli/tests/unit/fetch_test.ts
parent65993e5efa5931c7a50b1fe926a0fa43eae0ca13 (diff)
feat(ext/fetch): allow `Deno.HttpClient` to be declared with `using` (#21453)
This commit adds a method of `Symbol.dispose` to the object returned from `Deno.createHttpClient`, so we can make use of [explicit resource management](https://github.com/tc39/proposal-explicit-resource-management) by declaring it with `using`.
Diffstat (limited to 'cli/tests/unit/fetch_test.ts')
-rw-r--r--cli/tests/unit/fetch_test.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts
index d12a93867..b4d248440 100644
--- a/cli/tests/unit/fetch_test.ts
+++ b/cli/tests/unit/fetch_test.ts
@@ -1618,6 +1618,33 @@ Deno.test(
},
);
+Deno.test(
+ { permissions: { net: true } },
+ async function createHttpClientExplicitResourceManagement() {
+ using client = Deno.createHttpClient({});
+ const response = await fetch("http://localhost:4545/assets/fixture.json", {
+ client,
+ });
+ const json = await response.json();
+ assertEquals(json.name, "deno");
+ },
+);
+
+Deno.test(
+ { permissions: { net: true } },
+ async function createHttpClientExplicitResourceManagementDoubleClose() {
+ using client = Deno.createHttpClient({});
+ const response = await fetch("http://localhost:4545/assets/fixture.json", {
+ client,
+ });
+ const json = await response.json();
+ assertEquals(json.name, "deno");
+ // Close the client even though we declared it with `using` to confirm that
+ // the cleanup done as per `Symbol.dispose` will not throw any errors.
+ client.close();
+ },
+);
+
Deno.test({ permissions: { read: false } }, async function fetchFilePerm() {
await assertRejects(async () => {
await fetch(import.meta.resolve("../testdata/subdir/json_1.json"));