Skip to content

Commit

Permalink
test: add yaml output crash test
Browse files Browse the repository at this point in the history
  • Loading branch information
stefreak committed Aug 31, 2023
1 parent 8a5d227 commit ebd71a5
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion core/test/unit/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ describe("cli", () => {
expect(JSON.parse(consoleOutput!)).to.eql({ result: { some: "output" }, success: true })
})

it("should output YAML if --output=json", async () => {
it("should output YAML if --output=yaml", async () => {
class TestCommand extends Command {
name = "test-command"
help = "halp!"
Expand Down Expand Up @@ -985,6 +985,41 @@ describe("cli", () => {
const lastLine = outputLines[outputLines.length - 2] // the last line is empty due to trailing newline
expect(lastLine).to.eql("See .garden/error.log for detailed error message")
})

it("Handles crash on the command level with --output=yaml correctly", async () => {
class TestCommand extends Command {
name = "test-command"
help = "halp!"
override noProject = true

override printHeader() {}

async action({}): Promise<CommandResult> {
const err = new Error("Some unexpected error that leads to a crash")
// the stack makes this hard to compare below
err.stack = "stack"
throw err
}
}

const cmd = new TestCommand()
cli.addCommand(cmd)

const { code, consoleOutput } = await cli.run({ args: ["test-command", "-o", "yaml"], exitOnError: false })

expect(code).to.equal(1)
const resultData = load(consoleOutput!) as any
expect(resultData).to.eql({
success: false,
errors: [
{
type: "crash",
message: "Some unexpected error that leads to a crash",
stack: "stack",
}
]
})
})
})
})

Expand Down

0 comments on commit ebd71a5

Please sign in to comment.