diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2021-11-01 15:29:46 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-01 15:29:46 +1100 |
commit | d3662e487d9ff94a09a2fa96598bf0a41666a7f2 (patch) | |
tree | ef44499ca2e38c4005de1a5b566695ebb0526aed /cli/tests/unit/fetch_test.ts | |
parent | d080f1c9651b34a2887473bd468495b72ea8f8b4 (diff) |
feat(ext/fetch): support fetching local files (#12545)
Closes #11925
Closes #2150
Co-authored-by: Bert Belder <bertbelder@gmail.com>
Diffstat (limited to 'cli/tests/unit/fetch_test.ts')
-rw-r--r-- | cli/tests/unit/fetch_test.ts | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index bc61d67b5..98134728e 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -23,7 +23,7 @@ unitTest( unitTest({ permissions: { net: true } }, async function fetchProtocolError() { await assertRejects( async () => { - await fetch("file:///"); + await fetch("ftp://localhost:21/a/file"); }, TypeError, "not supported", @@ -1360,3 +1360,59 @@ unitTest( client.close(); }, ); + +unitTest(async function fetchFilePerm() { + await assertRejects(async () => { + await fetch(new URL("../testdata/subdir/json_1.json", import.meta.url)); + }, Deno.errors.PermissionDenied); +}); + +unitTest(async function fetchFilePermDoesNotExist() { + await assertRejects(async () => { + await fetch(new URL("./bad.json", import.meta.url)); + }, Deno.errors.PermissionDenied); +}); + +unitTest( + { permissions: { read: true } }, + async function fetchFileBadMethod() { + await assertRejects( + async () => { + await fetch( + new URL("../testdata/subdir/json_1.json", import.meta.url), + { + method: "POST", + }, + ); + }, + TypeError, + "Fetching files only supports the GET method. Received POST.", + ); + }, +); + +unitTest( + { permissions: { read: true } }, + async function fetchFileDoesNotExist() { + await assertRejects( + async () => { + await fetch(new URL("./bad.json", import.meta.url)); + }, + TypeError, + ); + }, +); + +unitTest( + { permissions: { read: true } }, + async function fetchFile() { + const res = await fetch( + new URL("../testdata/subdir/json_1.json", import.meta.url), + ); + assert(res.ok); + const fixture = await Deno.readTextFile( + "cli/tests/testdata/subdir/json_1.json", + ); + assertEquals(await res.text(), fixture); + }, +); |