From b3e189ee4f97a9d6c5b7a2164d644aa4c7fa4b79 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Tue, 9 Jun 2020 12:18:18 +0100 Subject: fix(cli/js/process): Strengthen socket types based on pipes (#4836) --- std/examples/chat/server_test.ts | 10 ++++++---- std/examples/tests/catj_test.ts | 14 ++++++++------ std/examples/tests/echo_server_test.ts | 4 ++-- std/http/file_server_test.ts | 2 +- std/http/racing_server_test.ts | 4 ++-- std/http/server_test.ts | 8 ++++---- 6 files changed, 23 insertions(+), 19 deletions(-) (limited to 'std') diff --git a/std/examples/chat/server_test.ts b/std/examples/chat/server_test.ts index 7375de47a..8e04b71d8 100644 --- a/std/examples/chat/server_test.ts +++ b/std/examples/chat/server_test.ts @@ -7,7 +7,9 @@ import { delay } from "../../async/delay.ts"; const { test } = Deno; -async function startServer(): Promise { +async function startServer(): Promise< + Deno.Process +> { const server = Deno.run({ // TODO(lucacasonato): remove unstable once possible cmd: [ @@ -27,7 +29,7 @@ async function startServer(): Promise { const s = await r.readLine(); assert(s !== null && s.includes("chat server starting")); } catch (err) { - server.stdout!.close(); + server.stdout.close(); server.close(); } @@ -46,7 +48,7 @@ test({ assert(html.includes("ws chat example"), "body is ok"); } finally { server.close(); - server.stdout!.close(); + server.stdout.close(); } await delay(10); }, @@ -66,7 +68,7 @@ test({ assertEquals((await it.next()).value, "[1]: Hello"); } finally { server.close(); - server.stdout!.close(); + server.stdout.close(); ws!.conn.close(); } }, diff --git a/std/examples/tests/catj_test.ts b/std/examples/tests/catj_test.ts index a859db0c1..58533ab60 100644 --- a/std/examples/tests/catj_test.ts +++ b/std/examples/tests/catj_test.ts @@ -17,7 +17,7 @@ Deno.test("[examples/catj] print an array", async () => { assertStrictEquals(actual, expected); } finally { - process.stdin!.close(); + process.stdin.close(); process.close(); } }); @@ -36,7 +36,7 @@ Deno.test("[examples/catj] print an object", async () => { assertStrictEquals(actual, expected); } finally { - process.stdin!.close(); + process.stdin.close(); process.close(); } }); @@ -54,7 +54,7 @@ Deno.test("[examples/catj] print multiple files", async () => { assertStrictEquals(actual, expected); } finally { - process.stdin!.close(); + process.stdin.close(); process.close(); } }); @@ -64,8 +64,8 @@ Deno.test("[examples/catj] read from stdin", async () => { const process = catj("-"); const input = `{ "foo": "bar" }`; try { - await process.stdin!.write(new TextEncoder().encode(input)); - process.stdin!.close(); + await process.stdin.write(new TextEncoder().encode(input)); + process.stdin.close(); const output = await process.output(); const actual = decoder.decode(output).trim(); @@ -75,7 +75,9 @@ Deno.test("[examples/catj] read from stdin", async () => { } }); -function catj(...files: string[]): Deno.Process { +function catj( + ...files: string[] +): Deno.Process { return Deno.run({ cmd: [Deno.execPath(), "run", "--allow-read", "catj.ts", ...files], cwd: "examples", diff --git a/std/examples/tests/echo_server_test.ts b/std/examples/tests/echo_server_test.ts index 475b0f73f..2cf52e466 100644 --- a/std/examples/tests/echo_server_test.ts +++ b/std/examples/tests/echo_server_test.ts @@ -13,7 +13,7 @@ Deno.test("[examples/echo_server]", async () => { let conn: Deno.Conn | undefined; try { - const processReader = new BufReader(process.stdout!); + const processReader = new BufReader(process.stdout); const message = await processReader.readLine(); assertNotEquals(message, null); @@ -38,7 +38,7 @@ Deno.test("[examples/echo_server]", async () => { assertStrictEquals(actualResponse, expectedResponse); } finally { conn?.close(); - process.stdout!.close(); + process.stdout.close(); process.close(); } }); diff --git a/std/http/file_server_test.ts b/std/http/file_server_test.ts index dbbaf81ff..ceea566fa 100644 --- a/std/http/file_server_test.ts +++ b/std/http/file_server_test.ts @@ -5,7 +5,7 @@ import { TextProtoReader } from "../textproto/mod.ts"; import { ServerRequest } from "./server.ts"; import { serveFile } from "./file_server.ts"; const { test } = Deno; -let fileServer: Deno.Process; +let fileServer: Deno.Process; type FileServerCfg = { target?: string; diff --git a/std/http/racing_server_test.ts b/std/http/racing_server_test.ts index 845e5a490..054dfc385 100644 --- a/std/http/racing_server_test.ts +++ b/std/http/racing_server_test.ts @@ -3,7 +3,7 @@ import { BufReader, BufWriter } from "../io/bufio.ts"; import { TextProtoReader } from "../textproto/mod.ts"; const { connect, run, test } = Deno; -let server: Deno.Process; +let server: Deno.Process; async function startServer(): Promise { server = run({ // TODO(lucacasonato): remove unstable when stabilized @@ -18,7 +18,7 @@ async function startServer(): Promise { } function killServer(): void { server.close(); - server.stdout?.close(); + server.stdout.close(); } const input = [ diff --git a/std/http/server_test.ts b/std/http/server_test.ts index d522b9a8f..2d911c450 100644 --- a/std/http/server_test.ts +++ b/std/http/server_test.ts @@ -372,7 +372,7 @@ test({ .catch((_): void => {}); // Ignores the error when closing the process. try { - const r = new TextProtoReader(new BufReader(p.stdout!)); + const r = new TextProtoReader(new BufReader(p.stdout)); const s = await r.readLine(); assert(s !== null && s.includes("server listening")); await delay(100); @@ -387,7 +387,7 @@ test({ // Stops the sever and allows `p.status()` promise to resolve Deno.kill(p.pid, Deno.Signal.SIGKILL); await statusPromise; - p.stdout!.close(); + p.stdout.close(); p.close(); } }, @@ -417,7 +417,7 @@ test({ .catch((_): void => {}); // Ignores the error when closing the process. try { - const r = new TextProtoReader(new BufReader(p.stdout!)); + const r = new TextProtoReader(new BufReader(p.stdout)); const s = await r.readLine(); assert( s !== null && s.includes("server listening"), @@ -444,7 +444,7 @@ test({ // Stops the sever and allows `p.status()` promise to resolve Deno.kill(p.pid, Deno.Signal.SIGKILL); await statusPromise; - p.stdout!.close(); + p.stdout.close(); p.close(); } }, -- cgit v1.2.3