@@ -9,41 +9,28 @@ jest.mock('../../cx-api', () => {
99 ...actual ,
1010 CloudAssemblyBuilder : jest . fn ( ) . mockImplementation ( ( ) => ( {
1111 addArtifact : jest . fn ( ) ,
12+ buildAssembly : jest . fn ( ) . mockReturnValue ( {
13+ tryGetArtifact : jest . fn ( ) . mockReturnValue ( 'aws-cdk-lib/feature-flag-report' ) ,
14+ } ) ,
1215 } ) ) ,
1316 } ;
1417} ) ;
1518
1619describe ( 'generate feature flag report' , ( ) => {
17- test ( 'populates the correct userValue based on the context' , ( ) => {
18- const app = new App ( {
19- context : {
20- '@aws-cdk/aws-ec2:bastionHostUseAmazonLinux2023ByDefault' : true ,
21- '@aws-cdk/core:aspectStabilization' : false ,
22- } ,
23- } ) ;
20+ test ( 'feature flag report can be retrieved from CloudAssembly using its artifact ID' , ( ) => {
21+ const app = new App ( ) ;
2422 const builder = new cxapi . CloudAssemblyBuilder ( '/tmp/test' ) ;
25- const spy = jest . spyOn ( builder , 'addArtifact' ) ;
2623
2724 generateFeatureFlagReport ( builder , app ) ;
2825
29- expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
30-
31- const [ artifactId , artifact ] = spy . mock . calls [ 0 ] ;
32-
33- expect ( artifact ) . toBeDefined ( ) ;
34- expect ( artifact ?. properties ) . toBeDefined ( ) ;
35-
36- const props = artifact . properties as FeatureFlagReportProperties ;
37- const flags = props . flags ;
38- expect ( flags ) . toBeDefined ( ) ;
39-
40- expect ( flags ?. [ '@aws-cdk/aws-ec2:bastionHostUseAmazonLinux2023ByDefault' ] ?. userValue ) . toEqual ( true ) ;
41- expect ( flags ?. [ '@aws-cdk/core:aspectStabilization' ] ?. userValue ) . toEqual ( false ) ;
26+ const cloudAssembly = builder . buildAssembly ( ) ;
27+ expect ( cloudAssembly . tryGetArtifact ( 'aws-cdk-lib/feature-flag-report' ) ) . toEqual ( 'aws-cdk-lib/feature-flag-report' ) ;
4228 } ) ;
43- test ( 'successfully creates an artifact stored in the CloudAssembly ' , ( ) => {
29+ test ( 'report contains context values that represent the feature flags ' , ( ) => {
4430 const app = new App ( {
4531 context : {
46- '@aws-cdk/aws-s3:grantWriteWithoutAcl' : true ,
32+ '@aws-cdk/aws-ec2:bastionHostUseAmazonLinux2023ByDefault' : true ,
33+ '@aws-cdk/core:aspectStabilization' : false ,
4734 } ,
4835 } ) ;
4936 const builder = new cxapi . CloudAssemblyBuilder ( '/tmp/test' ) ;
@@ -55,28 +42,34 @@ describe('generate feature flag report', () => {
5542
5643 const [ artifactId , artifact ] = spy . mock . calls [ 0 ] ;
5744
58- expect ( artifactId ) . toEqual ( 'feature flag report' ) ;
59- expect ( artifact ) . toMatchObject ( {
45+ expect ( artifact ) . toEqual ( expect . objectContaining ( {
6046 type : 'cdk:feature-flag-report' ,
61- properties : {
62- module : '@aws-cdk/core' ,
63- } ,
64- } ) ;
65-
66- const flags = ( artifact . properties as FeatureFlagReportProperties ) . flags ;
67- expect ( flags ) . toBeDefined ( ) ;
68- expect ( flags [ '@aws-cdk/aws-s3:grantWriteWithoutAcl' ] ) . toBeDefined ( ) ;
69- expect ( flags [ '@aws-cdk/aws-s3:grantWriteWithoutAcl' ] . userValue ) . toBe ( true ) ;
47+ properties : expect . objectContaining ( {
48+ module : 'aws-cdk-lib' ,
49+ flags : expect . objectContaining ( {
50+ '@aws-cdk/aws-ec2:bastionHostUseAmazonLinux2023ByDefault' : expect . objectContaining ( {
51+ userValue : true ,
52+ } ) ,
53+ '@aws-cdk/core:aspectStabilization' : expect . objectContaining ( {
54+ userValue : false ,
55+ } ) ,
56+ } ) ,
57+ } ) ,
58+ } ) ) ;
7059 } ) ;
71- test ( 'defaults userValue to false when not set in context' , ( ) => {
60+ test ( 'defaults userValue to undefined when not set in context' , ( ) => {
7261 const app = new App ( ) ;
7362 const builder = new cxapi . CloudAssemblyBuilder ( '/tmp/test' ) ;
7463 const spy = jest . spyOn ( builder , 'addArtifact' ) ;
7564
7665 generateFeatureFlagReport ( builder , app ) ;
7766
7867 const flags = ( spy . mock . calls [ 0 ] [ 1 ] . properties as FeatureFlagReportProperties ) . flags ;
79- expect ( flags [ '@aws-cdk/aws-ec2:bastionHostUseAmazonLinux2023ByDefault' ] . userValue ) . toBe ( false ) ;
68+ expect ( flags ) . toEqual ( expect . objectContaining ( {
69+ '@aws-cdk/aws-ec2:bastionHostUseAmazonLinux2023ByDefault' : expect . objectContaining ( {
70+ userValue : undefined ,
71+ } ) ,
72+ } ) ) ;
8073 } ) ;
8174} ) ;
8275
0 commit comments