summaryrefslogtreecommitdiff
path: root/std/http/file_server_test.ts
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2020-06-12 20:23:38 +0100
committerGitHub <noreply@github.com>2020-06-12 15:23:38 -0400
commit1fff6f55c3ba98a10018c6d374795e612061e9b6 (patch)
tree12074b6d44736b11513d857e437f9e30a6bf65a4 /std/http/file_server_test.ts
parent26bf56afdaf16634ffbaa23684faf3a44cc10f62 (diff)
refactor: Don't destructure the Deno namespace (#6268)
Diffstat (limited to 'std/http/file_server_test.ts')
-rw-r--r--std/http/file_server_test.ts81
1 files changed, 43 insertions, 38 deletions
diff --git a/std/http/file_server_test.ts b/std/http/file_server_test.ts
index ceea566fa..66c1d7d04 100644
--- a/std/http/file_server_test.ts
+++ b/std/http/file_server_test.ts
@@ -4,7 +4,6 @@ import { BufReader } from "../io/bufio.ts";
import { TextProtoReader } from "../textproto/mod.ts";
import { ServerRequest } from "./server.ts";
import { serveFile } from "./file_server.ts";
-const { test } = Deno;
let fileServer: Deno.Process<Deno.RunOptions & { stdout: "piped" }>;
type FileServerCfg = {
@@ -68,42 +67,48 @@ async function killFileServer(): Promise<void> {
fileServer.stdout!.close();
}
-test("file_server serveFile in ./", async (): Promise<void> => {
- await startFileServer();
- try {
- const res = await fetch("http://localhost:4507/README.md");
- assert(res.headers.has("access-control-allow-origin"));
- assert(res.headers.has("access-control-allow-headers"));
- assertEquals(res.headers.get("content-type"), "text/markdown");
- const downloadedFile = await res.text();
- const localFile = new TextDecoder().decode(
- await Deno.readFile("README.md")
- );
- assertEquals(downloadedFile, localFile);
- } finally {
- await killFileServer();
+Deno.test(
+ "file_server serveFile in ./",
+ async (): Promise<void> => {
+ await startFileServer();
+ try {
+ const res = await fetch("http://localhost:4507/README.md");
+ assert(res.headers.has("access-control-allow-origin"));
+ assert(res.headers.has("access-control-allow-headers"));
+ assertEquals(res.headers.get("content-type"), "text/markdown");
+ const downloadedFile = await res.text();
+ const localFile = new TextDecoder().decode(
+ await Deno.readFile("README.md")
+ );
+ assertEquals(downloadedFile, localFile);
+ } finally {
+ await killFileServer();
+ }
}
-});
+);
-test("file_server serveFile in ./http", async (): Promise<void> => {
- await startFileServer({ target: "./http" });
- try {
- const res = await fetch("http://localhost:4507/README.md");
- assert(res.headers.has("access-control-allow-origin"));
- assert(res.headers.has("access-control-allow-headers"));
- assertEquals(res.headers.get("content-type"), "text/markdown");
- const downloadedFile = await res.text();
- const localFile = new TextDecoder().decode(
- await Deno.readFile("./http/README.md")
- );
- console.log(downloadedFile, localFile);
- assertEquals(downloadedFile, localFile);
- } finally {
- await killFileServer();
+Deno.test(
+ "file_server serveFile in ./http",
+ async (): Promise<void> => {
+ await startFileServer({ target: "./http" });
+ try {
+ const res = await fetch("http://localhost:4507/README.md");
+ assert(res.headers.has("access-control-allow-origin"));
+ assert(res.headers.has("access-control-allow-headers"));
+ assertEquals(res.headers.get("content-type"), "text/markdown");
+ const downloadedFile = await res.text();
+ const localFile = new TextDecoder().decode(
+ await Deno.readFile("./http/README.md")
+ );
+ console.log(downloadedFile, localFile);
+ assertEquals(downloadedFile, localFile);
+ } finally {
+ await killFileServer();
+ }
}
-});
+);
-test("serveDirectory", async function (): Promise<void> {
+Deno.test("serveDirectory", async function (): Promise<void> {
await startFileServer();
try {
const res = await fetch("http://localhost:4507/");
@@ -125,7 +130,7 @@ test("serveDirectory", async function (): Promise<void> {
}
});
-test("serveFallback", async function (): Promise<void> {
+Deno.test("serveFallback", async function (): Promise<void> {
await startFileServer();
try {
const res = await fetch("http://localhost:4507/badfile.txt");
@@ -138,7 +143,7 @@ test("serveFallback", async function (): Promise<void> {
}
});
-test("serveWithUnorthodoxFilename", async function (): Promise<void> {
+Deno.test("serveWithUnorthodoxFilename", async function (): Promise<void> {
await startFileServer();
try {
let res = await fetch("http://localhost:4507/http/testdata/%");
@@ -156,7 +161,7 @@ test("serveWithUnorthodoxFilename", async function (): Promise<void> {
}
});
-test("printHelp", async function (): Promise<void> {
+Deno.test("printHelp", async function (): Promise<void> {
const helpProcess = Deno.run({
cmd: [
Deno.execPath(),
@@ -177,7 +182,7 @@ test("printHelp", async function (): Promise<void> {
helpProcess.stdout.close();
});
-test("contentType", async () => {
+Deno.test("contentType", async () => {
const request = new ServerRequest();
const response = await serveFile(request, "http/testdata/hello.html");
const contentType = response.headers!.get("content-type");
@@ -185,7 +190,7 @@ test("contentType", async () => {
(response.body as Deno.File).close();
});
-test("file_server running as library", async function (): Promise<void> {
+Deno.test("file_server running as library", async function (): Promise<void> {
await startFileServerAsLibrary();
try {
const res = await fetch("http://localhost:8000");