@@ -53,12 +53,12 @@ describe('Messages', () => {
5353 describe ( 'findError' , ( ) => {
5454 test ( 'match' , ( ) => {
5555 const result = annotations . findError ( '*' , Match . anyValue ( ) ) ;
56- expect ( Object . keys ( result ) . length ) . toEqual ( 2 ) ;
56+ expect ( result . length ) . toEqual ( 2 ) ;
5757 } ) ;
5858
5959 test ( 'no match' , ( ) => {
6060 const result = annotations . findError ( '*' , 'no message looks like this' ) ;
61- expect ( Object . keys ( result ) . length ) . toEqual ( 0 ) ;
61+ expect ( result . length ) . toEqual ( 0 ) ;
6262 } ) ;
6363 } ) ;
6464
@@ -75,12 +75,12 @@ describe('Messages', () => {
7575 describe ( 'findWarning' , ( ) => {
7676 test ( 'match' , ( ) => {
7777 const result = annotations . findWarning ( '*' , Match . anyValue ( ) ) ;
78- expect ( Object . keys ( result ) . length ) . toEqual ( 1 ) ;
78+ expect ( result . length ) . toEqual ( 1 ) ;
7979 } ) ;
8080
8181 test ( 'no match' , ( ) => {
8282 const result = annotations . findWarning ( '*' , 'no message looks like this' ) ;
83- expect ( Object . keys ( result ) . length ) . toEqual ( 0 ) ;
83+ expect ( result . length ) . toEqual ( 0 ) ;
8484 } ) ;
8585 } ) ;
8686
@@ -97,19 +97,19 @@ describe('Messages', () => {
9797 describe ( 'findInfo' , ( ) => {
9898 test ( 'match' , ( ) => {
9999 const result = annotations . findInfo ( '/Default/Qux' , 'this is an info' ) ;
100- expect ( Object . keys ( result ) . length ) . toEqual ( 1 ) ;
100+ expect ( result . length ) . toEqual ( 1 ) ;
101101 } ) ;
102102
103103 test ( 'no match' , ( ) => {
104104 const result = annotations . findInfo ( '*' , 'no message looks like this' ) ;
105- expect ( Object . keys ( result ) . length ) . toEqual ( 0 ) ;
105+ expect ( result . length ) . toEqual ( 0 ) ;
106106 } ) ;
107107 } ) ;
108108
109109 describe ( 'with matchers' , ( ) => {
110110 test ( 'anyValue' , ( ) => {
111111 const result = annotations . findError ( '*' , Match . anyValue ( ) ) ;
112- expect ( Object . keys ( result ) . length ) . toEqual ( 2 ) ;
112+ expect ( result . length ) . toEqual ( 2 ) ;
113113 } ) ;
114114
115115 test ( 'not' , ( ) => {
@@ -123,6 +123,45 @@ describe('Messages', () => {
123123 } ) ;
124124} ) ;
125125
126+ describe ( 'Multiple Messages on the Resource' , ( ) => {
127+ let stack : Stack ;
128+ let annotations : _Annotations ;
129+ beforeAll ( ( ) => {
130+ stack = new Stack ( ) ;
131+ new CfnResource ( stack , 'Foo' , {
132+ type : 'Foo::Bar' ,
133+ properties : {
134+ Fred : 'Thud' ,
135+ } ,
136+ } ) ;
137+
138+ const bar = new CfnResource ( stack , 'Bar' , {
139+ type : 'Foo::Bar' ,
140+ properties : {
141+ Baz : 'Qux' ,
142+ } ,
143+ } ) ;
144+ bar . node . setContext ( 'disable-stack-trace' , false ) ;
145+
146+ Aspects . of ( stack ) . add ( new MultipleAspectsPerNode ( ) ) ;
147+ annotations = _Annotations . fromStack ( stack ) ;
148+ } ) ;
149+
150+ test ( 'succeeds on hasXxx APIs' , ( ) => {
151+ annotations . hasError ( '/Default/Foo' , 'error: this is an error' ) ;
152+ annotations . hasError ( '/Default/Foo' , 'error: unsupported type Foo::Bar' ) ;
153+ annotations . hasWarning ( '/Default/Foo' , 'warning: Foo::Bar is deprecated' ) ;
154+ } ) ;
155+
156+ test ( 'succeeds on findXxx APIs' , ( ) => {
157+ const result1 = annotations . findError ( '*' , Match . stringLikeRegexp ( 'error:.*' ) ) ;
158+ expect ( result1 . length ) . toEqual ( 4 ) ;
159+ const result2 = annotations . findError ( '/Default/Bar' , Match . stringLikeRegexp ( 'error:.*' ) ) ;
160+ expect ( result2 . length ) . toEqual ( 2 ) ;
161+ const result3 = annotations . findWarning ( '/Default/Bar' , 'warning: Foo::Bar is deprecated' ) ;
162+ expect ( result3 [ 0 ] . entry . data ) . toEqual ( 'warning: Foo::Bar is deprecated' ) ;
163+ } ) ;
164+ } ) ;
126165class MyAspect implements IAspect {
127166 public visit ( node : IConstruct ) : void {
128167 if ( node instanceof CfnResource ) {
@@ -147,4 +186,22 @@ class MyAspect implements IAspect {
147186 protected info ( node : IConstruct , message : string ) : void {
148187 Annotations . of ( node ) . addInfo ( message ) ;
149188 }
189+ }
190+
191+ class MultipleAspectsPerNode implements IAspect {
192+ public visit ( node : IConstruct ) : void {
193+ if ( node instanceof CfnResource ) {
194+ this . error ( node , 'error: this is an error' ) ;
195+ this . error ( node , `error: unsupported type ${ node . cfnResourceType } ` ) ;
196+ this . warn ( node , `warning: ${ node . cfnResourceType } is deprecated` ) ;
197+ }
198+ }
199+
200+ protected warn ( node : IConstruct , message : string ) : void {
201+ Annotations . of ( node ) . addWarning ( message ) ;
202+ }
203+
204+ protected error ( node : IConstruct , message : string ) : void {
205+ Annotations . of ( node ) . addError ( message ) ;
206+ }
150207}
0 commit comments