File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,8 +34,17 @@ export const testHook: TestHook = (
3434 const engine = new Engine ( )
3535 await engine . load ( opts . root || module . parent ! . parent ! . filename )
3636 const run = ( ) => engine . runHook ( event , hookOpts )
37- if ( typeof opts . exit === 'number' ) await expect ( run ( ) ) . to . be . rejectedWith ( `EEXIT: ${ opts . exit } ` )
38- else await run ( )
37+ if ( typeof opts . exit === 'number' ) {
38+ try {
39+ await run ( )
40+ throw new Error ( `Expected hook to exit with code ${ opts . exit } but it ran without exiting` )
41+ } catch ( err ) {
42+ if ( ! err [ 'cli-ux' ] || typeof err [ 'cli-ux' ] . exit !== 'number' ) throw err
43+ if ( err [ 'cli-ux' ] . exit !== opts . exit ) {
44+ throw new Error ( `Expected hook to exit with ${ opts . exit } but exited with ${ err [ 'cli-ux' ] . exit } ` )
45+ }
46+ }
47+ } else await run ( )
3948 if ( typeof opts . stdout === 'string' ) expect ( output . stdout ) . to . equal ( opts . stdout )
4049 if ( typeof opts . stderr === 'string' ) expect ( output . stderr ) . to . equal ( opts . stderr )
4150 if ( ! fn ) return
You can’t perform that action at this time.
0 commit comments