How to test non-zero return codes?
See original GitHub issueI 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:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
Done. Merged in #5, released in v0.4.1 and documented in the README here: https://github.com/geelen/shellac#non-zero-exit-codes
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.