11import test from 'ava'
2- import modernErrors from 'modern-errors'
2+ import ModernError from 'modern-errors'
33import modernErrorsCli from 'modern-errors-cli'
44import { each } from 'test-each'
55
66import { errorExit } from './helpers/main.js'
77
8- const globalOpts = { cli : { timeout : 0 } }
98const exitCode = 5
109const message = 'test'
1110
12- const BaseError = modernErrors ( [ modernErrorsCli ] , globalOpts )
13- const UnknownError = BaseError . subclass ( 'UnknownError' )
14- const OneError = BaseError . subclass ( 'OneError' )
15- const TwoError = BaseError . subclass ( 'TwoError' , { cli : { exitCode } } )
16- const ThreeError = BaseError . subclass ( 'ThreeError' )
17-
18- const error = new OneError ( message )
11+ const BaseError = ModernError . subclass ( 'BaseError' , {
12+ plugins : [ modernErrorsCli ] ,
13+ cli : { timeout : 0 } ,
14+ } )
15+ const error = new BaseError ( message )
1916
2017each (
2118 [ true , { timeout : 'true' } , { unknown : true } , { classes : { } } ] ,
@@ -30,16 +27,19 @@ test.serial('Call process.exit()', (t) => {
3027 t . true ( Number . isInteger ( errorExit ( error ) . exitCode ) )
3128} )
3229
33- test . serial ( 'Can pass "exitCode"' , ( t ) => {
30+ test . serial ( 'Can pass "exitCode" as instance option ' , ( t ) => {
3431 t . is ( errorExit ( error , { exitCode } ) . exitCode , exitCode )
3532} )
3633
37- test . serial ( '"exitCode" defaults to incrementing number' , ( t ) => {
38- t . is ( errorExit ( new UnknownError ( '' ) ) . exitCode , 1 )
39- t . is ( errorExit ( new OneError ( '' ) ) . exitCode , 2 )
40- t . is ( errorExit ( new TwoError ( '' ) ) . exitCode , exitCode )
41- // eslint-disable-next-line no-magic-numbers
42- t . is ( errorExit ( new ThreeError ( '' ) ) . exitCode , 4 )
34+ test . serial ( 'Can pass "exitCode" as class option' , ( t ) => {
35+ const ExitCodeError = BaseError . subclass ( 'ExitCodeError' , {
36+ cli : { exitCode } ,
37+ } )
38+ t . is ( errorExit ( new ExitCodeError ( '' ) ) . exitCode , exitCode )
39+ } )
40+
41+ test . serial ( '"exitCode" defaults to 1' , ( t ) => {
42+ t . is ( errorExit ( new BaseError ( '' ) ) . exitCode , 1 )
4343} )
4444
4545test . serial ( 'Can pass "stack"' , ( t ) => {
0 commit comments