Skip to content

Commit

Permalink
test: set exit code to 0 to get invalid args tests to pass (#316)
Browse files Browse the repository at this point in the history
Currently the CI on the main branch is red because non-zero exit code has started to be considered as test failure since Deno 1.44.0. 

```
ERRORS 

parseArgsForLogSubcommand ... specify invalid format in since => ./src/subcommands/logs_test.ts:51:11
error: Error: Test case finished with exit code set to 1.
  await t.step("specify invalid format in since", () => {
  ^
    at exitSanitizer (ext:cli/40_test.js:113:15)
    at async Object.outerWrapped [as fn] (ext:cli/40_test.js:134:14)
    at async TestContext.step (ext:cli/40_test.js:492:22)
    at async file:///Users/runner/work/deployctl/deployctl/src/subcommands/logs_test.ts:51:3

parseArgsForLogSubcommand ... specify invalid format in until => ./src/subcommands/logs_test.ts:55:11
error: Error: Test case finished with exit code set to 1.
  await t.step("specify invalid format in until", () => {
  ^
    at exitSanitizer (ext:cli/40_test.js:113:15)
    at async Object.outerWrapped [as fn] (ext:cli/40_test.js:134:14)
    at async TestContext.step (ext:cli/40_test.js:492:22)
    at async file:///Users/runner/work/deployctl/deployctl/src/subcommands/logs_test.ts:55:3

 FAILURES 
```

This commit works around this issue by forcibly setting exit code to 0.
  • Loading branch information
magurotuna authored Jul 18, 2024
1 parent 0c4210b commit 6b1fefd
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/subcommands/logs_test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
import { parseArgsForLogSubcommand } from "./logs.ts";
import { assertEquals, assertThrows } from "jsr:@std/[email protected]";
import {
assertEquals,
assertNotEquals,
assertThrows,
} from "jsr:@std/[email protected]";
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"]);
Expand Down

0 comments on commit 6b1fefd

Please sign in to comment.