From eb9417f38cf294a86f453c019e43eba616e522b6 Mon Sep 17 00:00:00 2001 From: Jacky Leung Date: Wed, 31 Jul 2024 15:14:50 +1200 Subject: [PATCH] Expand test case for nested stack bundling required --- packages/aws-cdk-lib/core/lib/nested-stack.ts | 1 - .../core/test/nested-stack.test.ts | 25 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/core/lib/nested-stack.ts b/packages/aws-cdk-lib/core/lib/nested-stack.ts index 3f69ea31e9906..41d3cb209122b 100644 --- a/packages/aws-cdk-lib/core/lib/nested-stack.ts +++ b/packages/aws-cdk-lib/core/lib/nested-stack.ts @@ -262,7 +262,6 @@ export class NestedStack extends Stack { } public get bundlingRequired() { - return this._parentStack.bundlingRequired; } } diff --git a/packages/aws-cdk-lib/core/test/nested-stack.test.ts b/packages/aws-cdk-lib/core/test/nested-stack.test.ts index a9f3f4230b719..a770a06f31219 100644 --- a/packages/aws-cdk-lib/core/test/nested-stack.test.ts +++ b/packages/aws-cdk-lib/core/test/nested-stack.test.ts @@ -2,6 +2,7 @@ import * as path from 'path'; import { Construct } from 'constructs'; import { readFileSync } from 'fs-extra'; import { toCloudFormation } from './util'; +import * as cxapi from '../../cx-api'; import { Stack, NestedStack, CfnStack, Resource, CfnResource, App, CfnOutput, } from '../lib'; @@ -168,6 +169,30 @@ describe('nested-stack', () => { expect(() => toCloudFormation(stack2)).toThrow( /Cannot use resource 'Stack1\/MyNestedStack\/MyResource' in a cross-environment fashion/); }); + + test('requires bundling when root stack has exact match in BUNDLING_STACKS', () => { + const app = new App(); + const stack = new Stack(app, 'Stack'); + stack.node.setContext(cxapi.BUNDLING_STACKS, ['Stack']); + + const child = new NestedStack(stack, 'Child'); + const child_2 = new NestedStack(child, 'Child2'); + + expect(child.bundlingRequired).toBe(true); + expect(child_2.bundlingRequired).toBe(true); + }); + + test('not requires bundling when root stack has no match in BUNDLING_STACKS', () => { + const app = new App(); + const stack = new Stack(app, 'Stack'); + stack.node.setContext(cxapi.BUNDLING_STACKS, ['Stack2']); + + const child = new NestedStack(stack, 'Child'); + const child_2 = new NestedStack(child, 'Child2'); + + expect(child.bundlingRequired).toBe(false); + expect(child_2.bundlingRequired).toBe(false); + }); }); class MyResource extends Resource {