Skip to content

Commit

Permalink
Expand test case for nested stack bundling required
Browse files Browse the repository at this point in the history
  • Loading branch information
jk2l committed Jul 31, 2024
1 parent 329f1da commit eb9417f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 0 additions & 1 deletion packages/aws-cdk-lib/core/lib/nested-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ export class NestedStack extends Stack {
}

public get bundlingRequired() {

return this._parentStack.bundlingRequired;
}
}
Expand Down
25 changes: 25 additions & 0 deletions packages/aws-cdk-lib/core/test/nested-stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit eb9417f

Please sign in to comment.