question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to test non-zero return codes?

See original GitHub issue

I was surprised to see shellac throw an error when the command exits non-zero. I was expecting exit-code to be part of the normal object returned, because I don’t think its shellac’s business to decide what semantics apply to my exit codes.

To boil it down lets say I have these two tests:

  it(`should exit 1`, async () => {
    await expect(shellac.default`
      $ echo foo >&2; false
    `).rejects.toEqual(expect.objectContaining({ retCode: 1 }))
  })

  it(`should write to stderr`, async () => {
    await expect(shellac.default`
      $ echo foo >&2; false
    `).rejects.toEqual(expect.objectContaining({ stderr: "foo" }))
  })

The first test works fine. Yes I was surprised to see its a rejection, but it’s simple to test the return code. The 2nd test fails though because as far as I can tell there’s no stderr in the rejection object.

Does shellac offer a way to test stderr is handled correctly in this case? Maybe I’ve missed something…?

Other than that it’s been nice to use the library! 👍 💪

(FWIW this is the actual code I’m using shellac for: https://github.com/gaggle/svgs-to-pdf/blob/main/test/svgs-to-pdf.spec.js)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
geelencommented, Feb 1, 2021

Done. Merged in #5, released in v0.4.1 and documented in the README here: https://github.com/geelen/shellac#non-zero-exit-codes

0reactions
gagglecommented, Feb 1, 2021

I opted for the return-checking only because it’s what I’m used to. I think I felt it was a bit more arrange/act/assert-ish, if that makes sense? But I don’t actually mind and I’ve been considering changing to the inline so, yeah, maybe this is when I do it. I do agree your example reads a bit cleaner, so I’ll at least give it a shot next I’m in the project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I test for a non-zero exit status of a command in Bash?
What is the correct way to check for a non-zero exit status of a command in an if statement? bash · shell ·...
Read more >
Return a non-zero exit code, when testsuite has failing tests #21
Currently, a testsuite with failing tests returns an exit code of 0. Proposed exit codes: 0 - all OK: analysis, simulation, ...
Read more >
make test failures more obvious for non-zero exit status
1. run a unit test that fails w/ non-zero exit status, e.g. log.Fatal() ... RUN TestFoo Process finished with exit code 1. C...
Read more >
Non-Zero return code: Ansible fails due to non-zero value
Ansible will fail if the exit status of a task is any non-zero value. Here's how we can resolve Non-Zero return code: Ansible....
Read more >
Non-zero exit status for clean exit
If two fail it returns 2, etc. This goes up to 250, which means "250 or more test failures". It uses exit codes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found