From 94bf551ead0ab5dc922cb61d13b3141896d5a8ae Mon Sep 17 00:00:00 2001 From: matheus Date: Wed, 3 Jun 2020 14:48:03 -0300 Subject: fix(std/http/file_server): args handling only if invoked directly (#5989) --- std/http/file_server_test.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'std/http/file_server_test.ts') diff --git a/std/http/file_server_test.ts b/std/http/file_server_test.ts index 97c07c250..dbbaf81ff 100644 --- a/std/http/file_server_test.ts +++ b/std/http/file_server_test.ts @@ -38,6 +38,24 @@ async function startFileServer({ assert(s !== null && s.includes("server listening")); } +async function startFileServerAsLibrary({}: FileServerCfg = {}): Promise { + fileServer = await Deno.run({ + cmd: [ + Deno.execPath(), + "run", + "--allow-read", + "--allow-net", + "http/testdata/file_server_as_library.ts", + ], + stdout: "piped", + stderr: "null", + }); + assert(fileServer.stdout != null); + const r = new TextProtoReader(new BufReader(fileServer.stdout)); + const s = await r.readLine(); + assert(s !== null && s.includes("Server running...")); +} + async function killFileServer(): Promise { fileServer.close(); // Process.close() kills the file server process. However this termination @@ -166,3 +184,13 @@ test("contentType", async () => { assertEquals(contentType, "text/html"); (response.body as Deno.File).close(); }); + +test("file_server running as library", async function (): Promise { + await startFileServerAsLibrary(); + try { + const res = await fetch("http://localhost:8000"); + assertEquals(res.status, 200); + } finally { + await killFileServer(); + } +}); -- cgit v1.2.3