@@ -10,7 +10,6 @@ const JSII_RUNTIME_SYMBOL = Symbol.for('jsii.rtti');
1010let app : App ;
1111let stack : Stack ;
1212let _cdkVersion : string | undefined = undefined ;
13- const modulePrefix = cdkMajorVersion ( ) === 1 ? '@aws-cdk/core' : 'aws-cdk-lib' ;
1413
1514// The runtime metadata this test relies on is only available if the most
1615// recent compile has happened using 'jsii', as the jsii compiler injects
@@ -40,24 +39,15 @@ describeTscSafe('constructInfoFromConstruct', () => {
4039 test ( 'returns fqn and version for core constructs' , ( ) => {
4140 const constructInfo = constructInfoFromConstruct ( stack ) ;
4241 expect ( constructInfo ) . toBeDefined ( ) ;
43- expect ( constructInfo ?. fqn ) . toEqual ( ` ${ modulePrefix } .Stack` ) ;
42+ expect ( constructInfo ?. fqn ) . toEqual ( '@aws-cdk/core .Stack' ) ;
4443 expect ( constructInfo ?. version ) . toEqual ( localCdkVersion ( ) ) ;
4544 } ) ;
4645
47- test ( 'returns base construct info if no more specific info is present' , ( ) => {
48- const simpleConstruct = new class extends Construct { } ( stack , 'Simple' ) ;
49- const constructInfo = constructInfoFromConstruct ( simpleConstruct ) ;
50- expect ( constructInfo ?. fqn ) . toEqual ( `${ modulePrefix } .Construct` ) ;
51- } ) ;
52-
53- test ( 'returns more specific subclass info if present' , ( ) => {
54- const construct = new class extends Construct {
55- // @ts -ignore
56- private static readonly [ JSII_RUNTIME_SYMBOL ] = { fqn : 'aws-cdk-lib.TestConstruct' , version : localCdkVersion ( ) }
57- } ( stack , 'TestConstruct' ) ;
46+ test ( 'returns jsii runtime info if present' , ( ) => {
47+ const construct = new TestConstruct ( stack , 'TestConstruct' ) ;
5848
5949 const constructInfo = constructInfoFromConstruct ( construct ) ;
60- expect ( constructInfo ?. fqn ) . toEqual ( 'aws-cdk-lib .TestConstruct' ) ;
50+ expect ( constructInfo ?. fqn ) . toEqual ( '@ aws-cdk/test .TestConstruct' ) ;
6151 } ) ;
6252
6353 test ( 'throws if the jsii runtime info is not as expected' , ( ) => {
@@ -89,56 +79,49 @@ describeTscSafe('constructInfoForStack', () => {
8979
9080 const stackInfo = constructInfos . find ( i => / S t a c k / . test ( i . fqn ) ) ;
9181 const jsiiInfo = constructInfos . find ( i => i . fqn === 'jsii-runtime.Runtime' ) ;
92- expect ( stackInfo ?. fqn ) . toEqual ( ` ${ modulePrefix } .Stack` ) ;
82+ expect ( stackInfo ?. fqn ) . toEqual ( '@aws-cdk/core .Stack' ) ;
9383 expect ( stackInfo ?. version ) . toEqual ( localCdkVersion ( ) ) ;
9484 expect ( jsiiInfo ?. version ) . toMatch ( / n o d e .j s / ) ;
9585 } ) ;
9686
9787 test ( 'returns info for constructs added to the stack' , ( ) => {
98- new class extends Construct { } ( stack , 'Simple ' ) ;
88+ new TestConstruct ( stack , 'TestConstruct ' ) ;
9989
10090 const constructInfos = constructInfoFromStack ( stack ) ;
10191
10292 expect ( constructInfos . length ) . toEqual ( 3 ) ;
103- expect ( constructInfos . map ( info => info . fqn ) ) . toContain ( ` ${ modulePrefix } .Construct` ) ;
93+ expect ( constructInfos . map ( info => info . fqn ) ) . toContain ( '@aws-cdk/test.TestConstruct' ) ;
10494 } ) ;
10595
10696 test ( 'returns unique info (no duplicates)' , ( ) => {
107- new class extends Construct { } ( stack , 'Simple1 ' ) ;
108- new class extends Construct { } ( stack , 'Simple2 ' ) ;
97+ new TestConstruct ( stack , 'TestConstruct1 ' ) ;
98+ new TestConstruct ( stack , 'TestConstruct2 ' ) ;
10999
110100 const constructInfos = constructInfoFromStack ( stack ) ;
111101
112102 expect ( constructInfos . length ) . toEqual ( 3 ) ;
113- expect ( constructInfos . map ( info => info . fqn ) ) . toContain ( ` ${ modulePrefix } .Construct` ) ;
103+ expect ( constructInfos . map ( info => info . fqn ) ) . toContain ( '@aws-cdk/test.TestConstruct' ) ;
114104 } ) ;
115105
116106 test ( 'returns info from nested constructs' , ( ) => {
117107 new class extends Construct {
118108 constructor ( scope : Construct , id : string ) {
119109 super ( scope , id ) ;
120- return new class extends Construct {
121- // @ts -ignore
122- private static readonly [ JSII_RUNTIME_SYMBOL ] = { fqn : '@aws-cdk/test.TestV1Construct' , version : localCdkVersion ( ) }
123- } ( this , 'TestConstruct' ) ;
110+ new TestConstruct ( this , 'TestConstruct' ) ;
124111 }
125112 } ( stack , 'Nested' ) ;
126113
127114 const constructInfos = constructInfoFromStack ( stack ) ;
128115
129- expect ( constructInfos . length ) . toEqual ( 4 ) ;
130- expect ( constructInfos . map ( info => info . fqn ) ) . toContain ( '@aws-cdk/test.TestV1Construct' ) ;
116+ expect ( constructInfos . map ( info => info . fqn ) ) . toContain ( '@aws-cdk/test.TestConstruct' ) ;
131117 } ) ;
132118
133119 test ( 'does not return info from nested stacks' , ( ) => {
134120 new class extends Construct {
135121 constructor ( scope : Construct , id : string ) {
136122 super ( scope , id ) ;
137123
138- new class extends Construct {
139- // @ts -ignore
140- private static readonly [ JSII_RUNTIME_SYMBOL ] = { fqn : '@aws-cdk/test.TestV1Construct' , version : localCdkVersion ( ) }
141- } ( this , 'TestConstruct' ) ;
124+ new TestConstruct ( this , 'TestConstruct' ) ;
142125
143126 new class extends Stack {
144127 // @ts -ignore
@@ -160,16 +143,16 @@ describeTscSafe('constructInfoForStack', () => {
160143 const constructInfos = constructInfoFromStack ( stack ) ;
161144
162145 const fqns = constructInfos . map ( info => info . fqn ) ;
163- expect ( fqns ) . toContain ( '@aws-cdk/test.TestV1Construct ' ) ;
146+ expect ( fqns ) . toContain ( '@aws-cdk/test.TestConstruct ' ) ;
164147 expect ( fqns ) . not . toContain ( '@aws-cdk/test.TestStackInsideStack' ) ;
165148 expect ( fqns ) . not . toContain ( '@aws-cdk/test.TestNestedStackInsideStack' ) ;
166149 expect ( fqns ) . not . toContain ( '@aws-cdk/test.TestStageInsideStack' ) ;
167150 } ) ;
168151} ) ;
169152
170- function cdkMajorVersion ( ) : number {
171- // eslint-disable-next-line @typescript-eslint/no-require-imports
172- return require ( '../../../../release.json' ) . majorVersion ;
153+ class TestConstruct extends Construct {
154+ // @ts -ignore
155+ private static readonly [ JSII_RUNTIME_SYMBOL ] = { fqn : '@aws-cdk/test.TestConstruct' , version : localCdkVersion ( ) }
173156}
174157
175158/**
0 commit comments