Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
Add test to ensure pretty printable properties are preserved
Browse files Browse the repository at this point in the history
  • Loading branch information
chadian committed Jun 17, 2020
1 parent 28e75b7 commit db79e25
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,56 @@ describe('error', () => {
expect(error.suggestion).to.equal('rm -rf node_modules')
})
.it('attached pretty print properties from options to an existing error object')

fancy
.do(() => {
const e: any = new Error('An existing error object error!')
e.code = 'ORIG_ERR'
e.ref = 'ORIG_REF'
e.suggestion = 'ORIG_SUGGESTION'
error(e, {code: 'ERR', ref: 'https://oclif.com/error', suggestion: 'rm -rf node_modules'})
})
.catch((error: PrettyPrintableError) => {
expect(error.code).to.equal('ORIG_ERR')
expect(error.ref).to.equal('ORIG_REF')
expect(error.suggestion).to.equal('ORIG_SUGGESTION')
})
.it('preserves original pretty printable properties and is not overwritten by options')

describe('exitable errors', () => {
fancy
.do(() => {
error(new Error('An existing error object error!'))
})
.catch((error: any) => {
const defaultErrorCode = 2
expect(error.oclif.exit).to.equal(defaultErrorCode)
})
.it('adds oclif exit code to errors by default')
})

describe('exitable errors', () => {
fancy
.do(() => {
error(new Error('An existing error object error!'), {exit: 9001})
})
.catch((error: any) => {
expect(error.oclif.exit).to.equal(9001)
})
.it('applies the exit property on options to the error object')
})

fancy
.do(() => {
const e: any = new Error('An existing error object error!')
e.oclif = {
code: 'ORIG_EXIT_CODE',
}

error(e)
})
.catch((error: any) => {
expect(error.oclif.code).to.equal('ORIG_EXIT_CODE')
})
.it('preserves original oclif exitable error properties and is not overwritten by options')
})

0 comments on commit db79e25

Please sign in to comment.