@@ -54,9 +54,15 @@ describe('non-nested stacks', () => {
54
54
// Default implementations
55
55
cloudFormation . readCurrentTemplateWithNestedStacks . mockImplementation ( ( stackArtifact : CloudFormationStackArtifact ) => {
56
56
if ( stackArtifact . stackName === 'D' ) {
57
- return Promise . resolve ( { resource : 'D' } ) ;
57
+ return Promise . resolve ( {
58
+ deployedTemplate : { resource : 'D' } ,
59
+ nestedStackCount : 0 ,
60
+ } ) ;
58
61
}
59
- return Promise . resolve ( { } ) ;
62
+ return Promise . resolve ( {
63
+ deployedTemplate : { } ,
64
+ nestedStackCount : 0 ,
65
+ } ) ;
60
66
} ) ;
61
67
cloudFormation . deployStack . mockImplementation ( ( options ) => Promise . resolve ( {
62
68
noOp : true ,
@@ -85,6 +91,43 @@ describe('non-nested stacks', () => {
85
91
expect ( exitCode ) . toBe ( 0 ) ;
86
92
} ) ;
87
93
94
+ test ( 'diff number of stack diffs, not resource diffs' , async ( ) => {
95
+ // GIVEN
96
+ cloudExecutable = new MockCloudExecutable ( {
97
+ stacks : [ {
98
+ stackName : 'A' ,
99
+ template : { resourceA : 'A' , resourceB : 'B' } ,
100
+ } ,
101
+ {
102
+ stackName : 'B' ,
103
+ template : { resourceC : 'C' } ,
104
+ } ] ,
105
+ } ) ;
106
+
107
+ toolkit = new CdkToolkit ( {
108
+ cloudExecutable,
109
+ deployments : cloudFormation ,
110
+ configuration : cloudExecutable . configuration ,
111
+ sdkProvider : cloudExecutable . sdkProvider ,
112
+ } ) ;
113
+
114
+ const buffer = new StringWritable ( ) ;
115
+
116
+ // WHEN
117
+ const exitCode = await toolkit . diff ( {
118
+ stackNames : [ 'A' , 'B' ] ,
119
+ stream : buffer ,
120
+ } ) ;
121
+
122
+ // THEN
123
+ const plainTextOutput = buffer . data . replace ( / \x1B \[ [ 0 - ? ] * [ - / ] * [ @ - ~ ] / g, '' ) ;
124
+ expect ( plainTextOutput ) . toContain ( 'Stack A' ) ;
125
+ expect ( plainTextOutput ) . toContain ( 'Stack B' ) ;
126
+
127
+ expect ( buffer . data . trim ( ) ) . toContain ( '✨ Number of stacks with differences: 2' ) ;
128
+ expect ( exitCode ) . toBe ( 0 ) ;
129
+ } ) ;
130
+
88
131
test ( 'exits with 1 with diffs and fail set to true' , async ( ) => {
89
132
// GIVEN
90
133
const buffer = new StringWritable ( ) ;
@@ -161,7 +204,7 @@ describe('nested stacks', () => {
161
204
cloudExecutable = new MockCloudExecutable ( {
162
205
stacks : [ {
163
206
stackName : 'Parent' ,
164
- template : { } ,
207
+ template : { } ,
165
208
} ] ,
166
209
} ) ;
167
210
@@ -209,41 +252,47 @@ describe('nested stacks', () => {
209
252
} ,
210
253
} ;
211
254
return Promise . resolve ( {
212
- Resources : {
213
- AdditionChild : {
214
- Type : 'AWS::CloudFormation::Stack' ,
215
- Resources : {
216
- SomeResource : {
217
- Type : 'AWS::Something' ,
255
+ deployedTemplate : {
256
+ Resources : {
257
+ AdditionChild : {
258
+ Type : 'AWS::CloudFormation::Stack' ,
259
+ Resources : {
260
+ SomeResource : {
261
+ Type : 'AWS::Something' ,
262
+ } ,
218
263
} ,
219
264
} ,
220
- } ,
221
- DeletionChild : {
222
- Type : 'AWS::CloudFormation::Stack' ,
223
- Resources : {
224
- SomeResource : {
225
- Type : 'AWS::Something' ,
226
- Properties : {
227
- Prop : 'value-to-be-removed' ,
265
+ DeletionChild : {
266
+ Type : 'AWS::CloudFormation::Stack' ,
267
+ Resources : {
268
+ SomeResource : {
269
+ Type : 'AWS::Something' ,
270
+ Properties : {
271
+ Prop : 'value-to-be-removed' ,
272
+ } ,
228
273
} ,
229
274
} ,
230
275
} ,
231
- } ,
232
- ChangedChild : {
233
- Type : 'AWS::CloudFormation::Stack' ,
234
- Resources : {
235
- SomeResource : {
236
- Type : 'AWS::Something' ,
237
- Properties : {
238
- Prop : 'old-value' ,
276
+ ChangedChild : {
277
+ Type : 'AWS::CloudFormation::Stack' ,
278
+ Resources : {
279
+ SomeResource : {
280
+ Type : 'AWS::Something' ,
281
+ Properties : {
282
+ Prop : 'old-value' ,
283
+ } ,
239
284
} ,
240
285
} ,
241
286
} ,
242
287
} ,
243
288
} ,
289
+ nestedStackCount : 3 ,
244
290
} ) ;
245
291
}
246
- return Promise . resolve ( { } ) ;
292
+ return Promise . resolve ( {
293
+ deployedTemplate : { } ,
294
+ nestedStackCount : 0 ,
295
+ } ) ;
247
296
} ) ;
248
297
} ) ;
249
298
@@ -279,7 +328,7 @@ Resources
279
328
└─ [+] new-value
280
329
281
330
282
- ✨ Number of stacks with differences: 3 ` ) ;
331
+ ✨ Number of stacks with differences: 4 ` ) ;
283
332
284
333
expect ( exitCode ) . toBe ( 0 ) ;
285
334
} ) ;
0 commit comments