From 56ecfcc7ee11ec3699286e363bfb81bfb6587a73 Mon Sep 17 00:00:00 2001 From: Yuki Shindo Date: Thu, 23 Jun 2022 20:18:04 +0900 Subject: [PATCH] tests: add case for invalid inputs in fresh-init (#276) Co-authored-by: Luca Casonato --- tests/cli_test.ts | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tests/cli_test.ts b/tests/cli_test.ts index c91941cf..a8116372 100644 --- a/tests/cli_test.ts +++ b/tests/cli_test.ts @@ -1,6 +1,7 @@ import { assert, assertEquals, + assertStringIncludes, delay, puppeteer, TextLineStream, @@ -290,3 +291,61 @@ Deno.test({ sanitizeOps: false, sanitizeResources: false, }); + +Deno.test("fresh-init error(help)", async function (t) { + const includeText = "fresh-init"; + + await t.step( + "execute invalid init command (deno run -A init.ts)", + async () => { + const cliProcess = Deno.run({ + cmd: ["deno", "run", "-A", "init.ts"], + stderr: "piped", + }); + const { code } = await cliProcess.status(); + cliProcess.close(); + assertEquals(code, 1); + + const rawError = await cliProcess.stderrOutput(); + const errorString = new TextDecoder().decode(rawError); + + assertStringIncludes(errorString, includeText); + }, + ); + + await t.step( + "execute invalid init command (deno run -A init.ts -f)", + async () => { + const cliProcess = Deno.run({ + cmd: ["deno", "run", "-A", "init.ts", "-f"], + stderr: "piped", + }); + const { code } = await cliProcess.status(); + cliProcess.close(); + assertEquals(code, 1); + + const rawError = await cliProcess.stderrOutput(); + const errorString = new TextDecoder().decode(rawError); + + assertStringIncludes(errorString, includeText); + }, + ); + + await t.step( + "execute invalid init command (deno run -A init.ts --foo)", + async () => { + const cliProcess = Deno.run({ + cmd: ["deno", "run", "-A", "init.ts", "--foo"], + stderr: "piped", + }); + const { code } = await cliProcess.status(); + cliProcess.close(); + assertEquals(code, 1); + + const rawError = await cliProcess.stderrOutput(); + const errorString = new TextDecoder().decode(rawError); + + assertStringIncludes(errorString, includeText); + }, + ); +});