@@ -12,6 +12,7 @@ let consoleLogMock: jest.SpyInstance;
12
12
beforeEach ( ( ) => {
13
13
consoleErrorMock = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { return true ; } ) ;
14
14
consoleLogMock = jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { return true ; } ) ;
15
+ process . exitCode = undefined ;
15
16
} ) ;
16
17
17
18
afterEach ( ( ) => {
@@ -45,9 +46,9 @@ describe('validations', () => {
45
46
result : 'failure' ,
46
47
} ,
47
48
} ) ;
48
- expect ( ( ) => {
49
- app . synth ( ) ;
50
- } ) . toThrow ( / V a l i d a t i o n f a i l e d / ) ;
49
+
50
+ app . synth ( ) ;
51
+ expect ( process . exitCode ) . toEqual ( 1 ) ;
51
52
52
53
expect ( consoleErrorMock . mock . calls [ 0 ] [ 0 ] . split ( '\n' ) ) . toEqual ( expect . arrayContaining ( validationReport ( [ {
53
54
templatePath : '/path/to/Default.template.json' ,
@@ -88,9 +89,10 @@ describe('validations', () => {
88
89
result : 'success' ,
89
90
} ,
90
91
} ) ;
91
- expect ( ( ) => {
92
- app . synth ( ) ;
93
- } ) . not . toThrow ( / V a l i d a t i o n f a i l e d / ) ;
92
+
93
+ app . synth ( ) ;
94
+ expect ( process . exitCode ) . toBeUndefined ( ) ;
95
+
94
96
expect ( consoleLogMock . mock . calls ) . toEqual ( [
95
97
[
96
98
expect . stringMatching ( / P e r f o r m i n g P o l i c y V a l i d a t i o n s / ) ,
@@ -144,9 +146,9 @@ Policy Validation Report Summary
144
146
result : 'failure' ,
145
147
} ,
146
148
} ) ;
147
- expect ( ( ) => {
148
- app . synth ( ) ;
149
- } ) . toThrow ( / V a l i d a t i o n f a i l e d / ) ;
149
+
150
+ app . synth ( ) ;
151
+ expect ( process . exitCode ) . toEqual ( 1 ) ;
150
152
151
153
const report = consoleErrorMock . mock . calls [ 0 ] [ 0 ] ;
152
154
// Assuming the rest of the report's content is checked by another test
@@ -228,9 +230,9 @@ Policy Validation Report Summary
228
230
result : 'failure' ,
229
231
} ,
230
232
} ) ;
231
- expect ( ( ) => {
232
- app . synth ( ) ;
233
- } ) . toThrow ( / V a l i d a t i o n f a i l e d / ) ;
233
+
234
+ app . synth ( ) ;
235
+ expect ( process . exitCode ) . toEqual ( 1 ) ;
234
236
235
237
const report = consoleErrorMock . mock . calls [ 0 ] [ 0 ] . split ( '\n' ) ;
236
238
// Assuming the rest of the report's content is checked by another test
@@ -422,9 +424,8 @@ Policy Validation Report Summary
422
424
const stack = new core . Stack ( app ) ;
423
425
new LevelTwoConstruct ( stack , 'SomeResource' ) ;
424
426
new LevelTwoConstruct ( stack , 'AnotherResource' ) ;
425
- expect ( ( ) => {
426
- app . synth ( ) ;
427
- } ) . toThrow ( / V a l i d a t i o n f a i l e d / ) ;
427
+ app . synth ( ) ;
428
+ expect ( process . exitCode ) . toEqual ( 1 ) ;
428
429
429
430
const report = consoleErrorMock . mock . calls [ 0 ] [ 0 ] ;
430
431
// Assuming the rest of the report's content is checked by another test
@@ -462,9 +463,8 @@ Policy Validation Report Summary
462
463
result : 'failure' ,
463
464
} ,
464
465
} ) ;
465
- expect ( ( ) => {
466
- app . synth ( ) ;
467
- } ) . toThrow ( / V a l i d a t i o n f a i l e d / ) ;
466
+ app . synth ( ) ;
467
+ expect ( process . exitCode ) . toEqual ( 1 ) ;
468
468
469
469
const report = consoleErrorMock . mock . calls [ 0 ] [ 0 ] . split ( '\n' ) ;
470
470
expect ( report ) . toEqual ( expect . arrayContaining (
@@ -523,9 +523,7 @@ Policy Validation Report Summary
523
523
result : 'failure' ,
524
524
} ,
525
525
} ) ;
526
- expect ( ( ) => {
527
- app . synth ( ) ;
528
- } ) . toThrow ( / V a l i d a t i o n f a i l e d / ) ;
526
+ app . synth ( ) ;
529
527
530
528
const report = consoleErrorMock . mock . calls [ 0 ] [ 0 ] . split ( '\n' ) ;
531
529
expect ( report ) . toEqual ( expect . arrayContaining (
@@ -588,9 +586,8 @@ Policy Validation Report Summary
588
586
} ,
589
587
} ) ;
590
588
591
- expect ( ( ) => {
592
- app . synth ( ) ;
593
- } ) . toThrow ( / V a l i d a t i o n f a i l e d / ) ;
589
+ app . synth ( ) ;
590
+ expect ( process . exitCode ) . toEqual ( 1 ) ;
594
591
595
592
const report = consoleErrorMock . mock . calls [ 0 ] [ 0 ] ;
596
593
expect ( report ) . toContain ( 'error: Validation plugin \'broken-plugin\' failed: Something went wrong' ) ;
@@ -640,9 +637,8 @@ Policy Validation Report Summary
640
637
result : 'failure' ,
641
638
} ,
642
639
} ) ;
643
- expect ( ( ) => {
644
- app . synth ( ) ;
645
- } ) . toThrow ( / V a l i d a t i o n f a i l e d / ) ;
640
+ app . synth ( ) ;
641
+ expect ( process . exitCode ) . toEqual ( 1 ) ;
646
642
647
643
const report = fs . readFileSync ( path . join ( app . outdir , 'policy-validation-report.json' ) ) . toString ( 'utf-8' ) ;
648
644
expect ( JSON . parse ( report ) ) . toEqual ( expect . objectContaining ( {
@@ -785,7 +781,6 @@ const validationReport = (data: ValidationReportData[]) => {
785
781
expect . stringMatching ( new RegExp ( ' > test-location' ) ) ,
786
782
expect . stringMatching ( new RegExp ( ` Description: ${ d . description ?? 'test recommendation' } ` ) ) ,
787
783
...d . ruleMetadata ? [ expect . stringMatching ( ' Rule Metadata:' ) , ...Object . entries ( d . ruleMetadata ) . flatMap ( ( [ key , value ] ) => expect . stringMatching ( `${ key } : ${ value } ` ) ) ] : [ ] ,
788
- // new RegExp(''),
789
784
] ;
790
785
}
791
786
return [ ] ;
0 commit comments