Skip to content

Commit

Permalink
Add tests to confirm exit code
Browse files Browse the repository at this point in the history
  • Loading branch information
cleve-fauna committed Apr 4, 2022
1 parent f72aec6 commit 5eab87e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/commands/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,12 @@ function performQuery(client, fqlQuery, outputFile, outputFormat) {
return writeFormattedOutput(outputFile, response, outputFormat)
})
.catch(function (error) {
console.error(
errorOut(
util.inspect(JSON.parse(error.faunaError.requestResult.responseRaw), {
depth: null,
compact: false,
})
)

process.exit(1)
})
}

Expand Down
14 changes: 14 additions & 0 deletions test/commands/eval.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ describe('eval', () => {
.it('runs eval on nested db', (ctx) => {
expect(JSON.parse(ctx.stdout).data[0].targetDb).to.equal('nested')
})

test
.stderr()
.command(withOpts(['eval', '[Add(1, 2), Abort("boom")]']))
.exit(1)
.it('Exits with non-zero code when the command fails')

test
.stderr()
.command(withOpts(['eval', '[Add(1, 2), Abort("boom")]']))
.catch((e) => {
expect(e.message).to.contain('transaction aborted')
})
.it('It pretty-prints an error message the command fails')
})

function mockQuery(api) {
Expand Down

0 comments on commit 5eab87e

Please sign in to comment.