@@ -91,12 +91,30 @@ describe('SLAS Lifecycle E2E Tests', function () {
9191 } ) ;
9292 }
9393
94- function expectFailure ( result : { exitCode ?: number ; stdout : string ; stderr : string } , stderrPatterns : RegExp [ ] ) : void {
94+ function expectFailure (
95+ result : { exitCode ?: number ; stdout : string ; stderr : string } ,
96+ options : { messagePatterns ?: RegExp [ ] ; status ?: number } = { } ,
97+ ) : void {
9598 const exitCode = result . exitCode ?? - 1 ;
9699 expect ( exitCode ) . to . not . equal ( 0 , `Expected command to fail but it succeeded: ${ result . stdout } ` ) ;
97- expect ( result . stderr ) . to . not . be . empty ;
98- for ( const pattern of stderrPatterns ) {
99- expect ( result . stderr ) . to . match ( pattern ) ;
100+
101+ const errorText = result . stderr || result . stdout ;
102+ expect ( errorText ) . to . not . be . empty ;
103+
104+ const parsed = JSON . parse ( errorText ) as {
105+ error ?: { message ?: string ; detail ?: string ; status ?: number ; code ?: string } ;
106+ } ;
107+ expect ( parsed . error , 'Expected JSON error object' ) . to . exist ;
108+
109+ if ( typeof options . status === 'number' ) {
110+ expect ( parsed . error ?. status , 'Expected error.status to match' ) . to . equal ( options . status ) ;
111+ }
112+
113+ if ( options . messagePatterns && options . messagePatterns . length > 0 ) {
114+ const msg = `${ parsed . error ?. message ?? '' } ${ parsed . error ?. detail ?? '' } ` ;
115+ for ( const pattern of options . messagePatterns ) {
116+ expect ( msg ) . to . match ( pattern ) ;
117+ }
100118 }
101119 }
102120
@@ -274,7 +292,7 @@ describe('SLAS Lifecycle E2E Tests', function () {
274292 '--json' ,
275293 ] ) ;
276294
277- expectFailure ( result , [ / n o t \s * f o u n d | 4 0 4 / i] ) ;
295+ expectFailure ( result , { messagePatterns : [ / f a i l e d \s + t o \s + g e t / i] } ) ;
278296 } ) ;
279297 } ) ;
280298
@@ -353,7 +371,7 @@ describe('SLAS Lifecycle E2E Tests', function () {
353371 '--json' ,
354372 ] ) ;
355373
356- expectFailure ( result , [ / n o t \s * f o u n d | 4 0 4 / i] ) ;
374+ expectFailure ( result , { messagePatterns : [ / f a i l e d \s + t o \s + g e t / i] } ) ;
357375 } ) ;
358376
359377 it ( 'should fail to update deleted client' , async function ( ) {
@@ -371,7 +389,7 @@ describe('SLAS Lifecycle E2E Tests', function () {
371389 '--json' ,
372390 ] ) ;
373391
374- expectFailure ( result , [ / n o t \s * f o u n d | 4 0 4 / i] ) ;
392+ expectFailure ( result , { messagePatterns : [ / f a i l e d \s + t o \s + f e t c h / i] } ) ;
375393 } ) ;
376394 } ) ;
377395} ) ;
0 commit comments