diff --git a/src/subcommands/logs_test.ts b/src/subcommands/logs_test.ts index 4f64d7a7..6bf2ffa3 100644 --- a/src/subcommands/logs_test.ts +++ b/src/subcommands/logs_test.ts @@ -1,13 +1,33 @@ import { parseArgsForLogSubcommand } from "./logs.ts"; -import { assertEquals, assertThrows } from "jsr:@std/assert@0.217"; +import { + assertEquals, + assertNotEquals, + assertThrows, +} from "jsr:@std/assert@0.217"; import { parseArgs } from "../args.ts"; Deno.test("parseArgsForLogSubcommand", async (t) => { - const parseHelper = (args: string[]) => - // NOTE: We omit `logs` subcommand from the arguments passed to `parseArgs()` - // in order to match the actual behavior; the first positional argument is - // removed using `args._.shift()` in `deployctl.ts`. - parseArgsForLogSubcommand(parseArgs(args)); + const parseHelper = (args: string[]) => { + // For this test, the subcommand name should not be included in `args`. + assertNotEquals(args.at(0), "logs"); + + try { + return parseArgsForLogSubcommand(parseArgs(args)); + } catch (e) { + // Since Deno v1.44.0, when `Deno.exitCode` was introduced, test cases + // with non-zero exit code has been treated as failure, causing some tests + // to fail unexpectedly (not sure if this behavior change is intended). + // To avoid this, we set `Deno.exitCode` to 0 before giving control back + // to each test case. + // https://github.com/denoland/deno/pull/23609 + // deno-lint-ignore no-explicit-any + if ((Deno as any).exitCode !== undefined) { + // deno-lint-ignore no-explicit-any + (Deno as any).exitCode = 0; + } + throw e; + } + }; await t.step("specify help", () => { const got = parseHelper(["--help"]);