summaryrefslogtreecommitdiff
path: root/file_server_test.ts
diff options
context:
space:
mode:
authorKevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com>2018-12-11 17:56:32 -0500
committerRyan Dahl <ry@tinyclouds.org>2018-12-11 17:56:32 -0500
commitb94530332910c0b85553dc91fa1912bce308df3c (patch)
tree86034754d12b04aa8ee5afe541c4b98b78ca5ed0 /file_server_test.ts
parenta691d9257b89cc210de6371138508c76aa288aba (diff)
Serve directory for file server & Fix bufio flush bug (denoland/deno_std#15)
Original: https://github.com/denoland/deno_std/commit/b78f4e9fbd477b026f1a309c64f4f8f75cd4d5d6
Diffstat (limited to 'file_server_test.ts')
-rw-r--r--file_server_test.ts46
1 files changed, 46 insertions, 0 deletions
diff --git a/file_server_test.ts b/file_server_test.ts
new file mode 100644
index 000000000..a04ced7e5
--- /dev/null
+++ b/file_server_test.ts
@@ -0,0 +1,46 @@
+import { readFile } from "deno";
+
+import {
+ test,
+ assert,
+ assertEqual
+} from "https://deno.land/x/testing/testing.ts";
+
+// Promise to completeResolve when all tests completes
+let completeResolve;
+export const completePromise = new Promise(res => (completeResolve = res));
+let completedTestCount = 0;
+
+function maybeCompleteTests() {
+ completedTestCount++;
+ // Change this when adding more tests
+ if (completedTestCount === 3) {
+ completeResolve();
+ }
+}
+
+export function runTests(serverReadyPromise: Promise<any>) {
+ test(async function serveFile() {
+ await serverReadyPromise;
+ const res = await fetch("http://localhost:4500/.travis.yml");
+ const downloadedFile = await res.text();
+ const localFile = new TextDecoder().decode(await readFile("./.travis.yml"));
+ assertEqual(downloadedFile, localFile);
+ maybeCompleteTests();
+ });
+
+ test(async function serveDirectory() {
+ await serverReadyPromise;
+ const res = await fetch("http://localhost:4500/");
+ const page = await res.text();
+ assert(page.includes(".travis.yml"));
+ maybeCompleteTests();
+ });
+
+ test(async function serveFallback() {
+ await serverReadyPromise;
+ const res = await fetch("http://localhost:4500/badfile.txt");
+ assertEqual(res.status, 404);
+ maybeCompleteTests();
+ });
+}