@@ -42,6 +42,14 @@ const mockFlagsData: FeatureFlag[] = [
4242 userValue : 'true' ,
4343 explanation : 'Flag that matches recommendation' ,
4444 } ,
45+ {
46+ module : 'different-module' ,
47+ name : '@aws-cdk/core:anotherMatchingFlag' ,
48+ recommendedValue : 'true' ,
49+ userValue : 'true' ,
50+ explanation : 'Flag that matches recommendation' ,
51+ unconfiguredBehavesLike : { v2 : 'true' } ,
52+ } ,
4553] ;
4654
4755function createMockToolkit ( ) : jest . Mocked < Toolkit > {
@@ -121,8 +129,8 @@ describe('displayFlags', () => {
121129 await displayFlags ( params ) ;
122130
123131 const plainTextOutput = output ( ) ;
124- expect ( plainTextOutput ) . toContain ( '@aws-cdk/core:testFlag' ) ;
125- expect ( plainTextOutput ) . toContain ( '@aws-cdk/s3:anotherFlag' ) ;
132+ expect ( plainTextOutput ) . toContain ( ' @aws-cdk/core:testFlag' ) ;
133+ expect ( plainTextOutput ) . toContain ( ' @aws-cdk/s3:anotherFlag' ) ;
126134 } ) ;
127135
128136 test ( 'handles null user values correctly' , async ( ) => {
@@ -181,6 +189,19 @@ describe('displayFlags', () => {
181189 expect ( plainTextOutput ) . toContain ( 'different-module' ) ;
182190 } ) ;
183191
192+ test ( 'does not display flag when unconfigured behavior is the same as recommended behavior' , async ( ) => {
193+ const params = {
194+ flagData : mockFlagsData ,
195+ toolkit : mockToolkit ,
196+ ioHelper,
197+ all : true ,
198+ } ;
199+ await displayFlags ( params ) ;
200+
201+ const plainTextOutput = output ( ) ;
202+ expect ( plainTextOutput ) . not . toContain ( ' @aws-cdk/core:anotherMatchingFlag' ) ;
203+ } ) ;
204+
184205 test ( 'displays single flag details when only one substring match is found' , async ( ) => {
185206 const params = {
186207 flagData : mockFlagsData ,
@@ -221,9 +242,10 @@ describe('displayFlags', () => {
221242 await displayFlags ( params ) ;
222243
223244 const plainTextOutput = output ( ) ;
224- expect ( plainTextOutput ) . toContain ( '@aws-cdk/core:testFlag' ) ;
225- expect ( plainTextOutput ) . toContain ( '@aws-cdk/s3:anotherFlag' ) ;
226- expect ( plainTextOutput ) . toContain ( '@aws-cdk/core:matchingFlag' ) ;
245+ expect ( plainTextOutput ) . toContain ( ' @aws-cdk/core:testFlag' ) ;
246+ expect ( plainTextOutput ) . toContain ( ' @aws-cdk/s3:anotherFlag' ) ;
247+ expect ( plainTextOutput ) . toContain ( ' @aws-cdk/core:matchingFlag' ) ;
248+ expect ( plainTextOutput ) . not . toContain ( ' @aws-cdk/core:anothermatchingFlag' ) ;
227249 } ) ;
228250
229251 test ( 'returns all matching flags if user enters multiple substrings' , async ( ) => {
@@ -236,9 +258,10 @@ describe('displayFlags', () => {
236258 await displayFlags ( params ) ;
237259
238260 const plainTextOutput = output ( ) ;
239- expect ( plainTextOutput ) . toContain ( '@aws-cdk/core:testFlag' ) ;
240- expect ( plainTextOutput ) . toContain ( '@aws-cdk/core:matchingFlag' ) ;
241- expect ( plainTextOutput ) . not . toContain ( '@aws-cdk/s3:anotherFlag' ) ;
261+ expect ( plainTextOutput ) . toContain ( ' @aws-cdk/core:testFlag' ) ;
262+ expect ( plainTextOutput ) . toContain ( ' @aws-cdk/core:matchingFlag' ) ;
263+ expect ( plainTextOutput ) . not . toContain ( ' @aws-cdk/s3:anotherFlag' ) ;
264+ expect ( plainTextOutput ) . not . toContain ( ' @aws-cdk/core:anothermatchingFlag' ) ;
242265 } ) ;
243266} ) ;
244267
@@ -264,8 +287,8 @@ describe('handleFlags', () => {
264287 await handleFlags ( mockFlagsData , ioHelper , options , mockToolkit ) ;
265288
266289 const plainTextOutput = output ( ) ;
267- expect ( plainTextOutput ) . toContain ( '@aws-cdk/core:testFlag' ) ;
268- expect ( plainTextOutput ) . toContain ( '@aws-cdk/s3:anotherFlag' ) ;
290+ expect ( plainTextOutput ) . toContain ( ' @aws-cdk/core:testFlag' ) ;
291+ expect ( plainTextOutput ) . toContain ( ' @aws-cdk/s3:anotherFlag' ) ;
269292 } ) ;
270293
271294 test ( 'displays only differing flags when no specific options are provided' , async ( ) => {
@@ -275,9 +298,9 @@ describe('handleFlags', () => {
275298 await handleFlags ( mockFlagsData , ioHelper , options , mockToolkit ) ;
276299
277300 const plainTextOutput = output ( ) ;
278- expect ( plainTextOutput ) . toContain ( '@aws-cdk/core:testFlag' ) ;
279- expect ( plainTextOutput ) . toContain ( '@aws-cdk/s3:anotherFlag' ) ;
280- expect ( plainTextOutput ) . not . toContain ( '@aws-cdk/core:matchingFlag' ) ;
301+ expect ( plainTextOutput ) . toContain ( ' @aws-cdk/core:testFlag' ) ;
302+ expect ( plainTextOutput ) . toContain ( ' @aws-cdk/s3:anotherFlag' ) ;
303+ expect ( plainTextOutput ) . not . toContain ( ' @aws-cdk/core:matchingFlag' ) ;
281304 } ) ;
282305
283306 test ( 'handles flag not found for specific flag query' , async ( ) => {
@@ -560,6 +583,65 @@ describe('modifyValues', () => {
560583 } ) ;
561584} ) ;
562585
586+ describe ( 'checkDefaultBehavior' , ( ) => {
587+ test ( 'calls setMultipleFlags when unconfiguredBehavesLike is present' , async ( ) => {
588+ const flagsWithUnconfiguredBehavior : FeatureFlag [ ] = [
589+ {
590+ module : 'aws-cdk-lib' ,
591+ name : '@aws-cdk/core:testFlag' ,
592+ recommendedValue : 'true' ,
593+ userValue : undefined ,
594+ explanation : 'Test flag' ,
595+ unconfiguredBehavesLike : { v2 : 'true' } ,
596+ } ,
597+ ] ;
598+
599+ const cdkJsonPath = await createCdkJsonFile ( { } ) ;
600+ setupMockToolkitForPrototyping ( mockToolkit ) ;
601+
602+ const requestResponseSpy = jest . spyOn ( ioHelper , 'requestResponse' ) ;
603+ requestResponseSpy . mockResolvedValue ( true ) ;
604+
605+ const options : FlagsOptions = {
606+ set : true ,
607+ all : true ,
608+ default : true ,
609+ } ;
610+
611+ await handleFlags ( flagsWithUnconfiguredBehavior , ioHelper , options , mockToolkit ) ;
612+
613+ expect ( mockToolkit . fromCdkApp ) . toHaveBeenCalled ( ) ;
614+ expect ( mockToolkit . synth ) . toHaveBeenCalled ( ) ;
615+
616+ await cleanupCdkJsonFile ( cdkJsonPath ) ;
617+ requestResponseSpy . mockRestore ( ) ;
618+ } ) ;
619+
620+ test ( 'shows error when unconfiguredBehavesLike is not present' , async ( ) => {
621+ const flagsWithoutUnconfiguredBehavior : FeatureFlag [ ] = [
622+ {
623+ module : 'aws-cdk-lib' ,
624+ name : '@aws-cdk/core:testFlag' ,
625+ recommendedValue : 'true' ,
626+ userValue : undefined ,
627+ explanation : 'Test flag' ,
628+ } ,
629+ ] ;
630+
631+ const options : FlagsOptions = {
632+ set : true ,
633+ all : true ,
634+ default : true ,
635+ } ;
636+
637+ await handleFlags ( flagsWithoutUnconfiguredBehavior , ioHelper , options , mockToolkit ) ;
638+
639+ const plainTextOutput = output ( ) ;
640+ expect ( plainTextOutput ) . toContain ( 'The --default options are not compatible with the AWS CDK library used by your application.' ) ;
641+ expect ( mockToolkit . fromCdkApp ) . not . toHaveBeenCalled ( ) ;
642+ } ) ;
643+ } ) ;
644+
563645describe ( 'interactive prompts lead to the correct function calls' , ( ) => {
564646 beforeEach ( ( ) => {
565647 setupMockToolkitForPrototyping ( mockToolkit ) ;
@@ -642,11 +724,30 @@ describe('interactive prompts lead to the correct function calls', () => {
642724 const requestResponseSpy = jest . spyOn ( ioHelper , 'requestResponse' ) ;
643725 requestResponseSpy . mockResolvedValue ( true ) ;
644726
727+ const flagsWithUnconfiguredBehavior : FeatureFlag [ ] = [
728+ {
729+ module : 'aws-cdk-lib' ,
730+ name : '@aws-cdk/core:testFlag' ,
731+ recommendedValue : 'true' ,
732+ userValue : 'false' ,
733+ explanation : 'Test flag for unit tests' ,
734+ unconfiguredBehavesLike : { v2 : 'true' } ,
735+ } ,
736+ {
737+ module : 'aws-cdk-lib' ,
738+ name : '@aws-cdk/s3:anotherFlag' ,
739+ recommendedValue : 'false' ,
740+ userValue : undefined ,
741+ explanation : 'Another test flag' ,
742+ unconfiguredBehavesLike : { v2 : 'false' } ,
743+ } ,
744+ ] ;
745+
645746 const options : FlagsOptions = {
646747 interactive : true ,
647748 } ;
648749
649- await handleFlags ( mockFlagsData , ioHelper , options , mockToolkit ) ;
750+ await handleFlags ( flagsWithUnconfiguredBehavior , ioHelper , options , mockToolkit ) ;
650751
651752 expect ( mockToolkit . fromCdkApp ) . toHaveBeenCalledTimes ( 2 ) ;
652753 expect ( mockToolkit . synth ) . toHaveBeenCalledTimes ( 2 ) ;
0 commit comments