Skip to content

Commit 09b05db

Browse files
committed
Expand test case for nested stack bundling required
1 parent 96f714e commit 09b05db

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

packages/aws-cdk-lib/core/lib/nested-stack.ts

-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ export class NestedStack extends Stack {
262262
}
263263

264264
public get bundlingRequired() {
265-
266265
return this._parentStack.bundlingRequired;
267266
}
268267
}

packages/aws-cdk-lib/core/test/nested-stack.test.ts

+25
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as path from 'path';
22
import { Construct } from 'constructs';
33
import { readFileSync } from 'fs-extra';
44
import { toCloudFormation } from './util';
5+
import * as cxapi from '../../cx-api';
56
import {
67
Stack, NestedStack, CfnStack, Resource, CfnResource, App, CfnOutput,
78
} from '../lib';
@@ -168,6 +169,30 @@ describe('nested-stack', () => {
168169
expect(() => toCloudFormation(stack2)).toThrow(
169170
/Cannot use resource 'Stack1\/MyNestedStack\/MyResource' in a cross-environment fashion/);
170171
});
172+
173+
test('requires bundling when root stack has exact match in BUNDLING_STACKS', () => {
174+
const app = new App();
175+
const stack = new Stack(app, 'Stack');
176+
stack.node.setContext(cxapi.BUNDLING_STACKS, ['Stack']);
177+
178+
const child = new NestedStack(stack, 'Child');
179+
const child_2 = new NestedStack(child, 'Child2');
180+
181+
expect(child.bundlingRequired).toBe(true);
182+
expect(child_2.bundlingRequired).toBe(true);
183+
});
184+
185+
test('not requires bundling when root stack has no match in BUNDLING_STACKS', () => {
186+
const app = new App();
187+
const stack = new Stack(app, 'Stack');
188+
stack.node.setContext(cxapi.BUNDLING_STACKS, ['Stack2']);
189+
190+
const child = new NestedStack(stack, 'Child');
191+
const child_2 = new NestedStack(child, 'Child2');
192+
193+
expect(child.bundlingRequired).toBe(false);
194+
expect(child_2.bundlingRequired).toBe(false);
195+
});
171196
});
172197

173198
class MyResource extends Resource {

0 commit comments

Comments
 (0)