diff options
| author | Ryan Dahl <ry@tinyclouds.org> | 2018-12-18 18:25:49 -0500 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2018-12-18 18:27:05 -0500 |
| commit | 968d50842512a007dc9c2e4ae31b1970fdc6e6a2 (patch) | |
| tree | 240d8b019a6694b6722ea4cfc3576e3f5b1b4bd0 /net/file_server_test.ts | |
| parent | 6e077e71fa27dbb993a49cda211c5385a76ca6aa (diff) | |
Rename project to deno_std
Move typescript files to net/
Original: https://github.com/denoland/deno_std/commit/99e276eb89fbe0003bfa8d9e7b907ff3ef19ee47
Diffstat (limited to 'net/file_server_test.ts')
| -rw-r--r-- | net/file_server_test.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/net/file_server_test.ts b/net/file_server_test.ts new file mode 100644 index 000000000..a04ced7e5 --- /dev/null +++ b/net/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(); + }); +} |
