2018-08-30 13:49:24 -04:00
|
|
|
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
2018-09-05 02:29:02 -04:00
|
|
|
import { test, testPerm, assert, assertEqual } from "./test_util.ts";
|
2018-08-30 13:49:24 -04:00
|
|
|
import * as deno from "deno";
|
|
|
|
|
|
|
|
testPerm({ net: true }, async function fetchJsonSuccess() {
|
|
|
|
const response = await fetch("http://localhost:4545/package.json");
|
|
|
|
const json = await response.json();
|
|
|
|
assertEqual(json.name, "deno");
|
|
|
|
});
|
2018-09-05 02:29:02 -04:00
|
|
|
|
|
|
|
test(async function fetchPerm() {
|
|
|
|
let err;
|
|
|
|
try {
|
|
|
|
await fetch("http://localhost:4545/package.json");
|
|
|
|
} catch (err_) {
|
|
|
|
err = err_;
|
|
|
|
}
|
2018-09-09 19:28:56 -04:00
|
|
|
assertEqual(err.kind, deno.ErrorKind.PermissionDenied);
|
|
|
|
assertEqual(err.name, "PermissionDenied");
|
2018-09-05 02:29:02 -04:00
|
|
|
});
|
2018-09-12 15:16:42 -04:00
|
|
|
|
|
|
|
testPerm({ net: true }, async function fetchHeaders() {
|
|
|
|
const response = await fetch("http://localhost:4545/package.json");
|
|
|
|
const headers = response.headers;
|
|
|
|
assertEqual(headers.get("Content-Type"), "application/json");
|
|
|
|
assert(headers.get("Server").startsWith("SimpleHTTP"));
|
|
|
|
});
|
|
|
|
|
2018-09-14 13:56:37 -04:00
|
|
|
testPerm({ net: true }, async function fetchBlob() {
|
|
|
|
const response = await fetch("http://localhost:4545/package.json");
|
|
|
|
const headers = response.headers;
|
|
|
|
const blob = await response.blob();
|
|
|
|
assertEqual(blob.type, headers.get("Content-Type"));
|
|
|
|
assertEqual(blob.size, Number(headers.get("Content-Length")));
|
|
|
|
});
|
2018-09-30 10:31:50 -04:00
|
|
|
|
2018-10-21 17:42:18 -04:00
|
|
|
testPerm({ net: true }, async function responseClone() {
|
|
|
|
const response = await fetch("http://localhost:4545/package.json");
|
|
|
|
const response1 = response.clone();
|
|
|
|
assert(response !== response1);
|
|
|
|
assertEqual(response.status, response1.status);
|
|
|
|
assertEqual(response.statusText, response1.statusText);
|
|
|
|
const ab = await response.arrayBuffer();
|
|
|
|
const ab1 = await response1.arrayBuffer();
|
|
|
|
for (let i = 0; i < ab.byteLength; i++) {
|
|
|
|
assertEqual(ab[i], ab1[i]);
|
|
|
|
}
|
|
|
|
});
|