Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rix0rrr committed Sep 12, 2024
1 parent 537cb02 commit c16c7a8
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions packages/aws-cdk/test/util/stack-monitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,20 @@ describe('stack monitor, collecting errors from events', () => {
return {
StackEvents: [
addErrorToStackEvent(
event(100), {
event(102), {
logicalResourceId: 'nestedStackLogicalResourceId',
physicalResourceId: 'nestedStackPhysicalResourceId',
resourceType: 'AWS::CloudFormation::Stack',
resourceStatusReason: 'nested stack failed',
resourceStatus: 'UPDATE_FAILED',
},
),
addErrorToStackEvent(
event(100), {
logicalResourceId: 'nestedStackLogicalResourceId',
physicalResourceId: 'nestedStackPhysicalResourceId',
resourceType: 'AWS::CloudFormation::Stack',
resourceStatus: 'UPDATE_IN_PROGRESS',
},
),
],
Expand Down Expand Up @@ -253,18 +262,28 @@ async function testMonitorWithEventCalls(
let describeStackEvents = (jest.fn() as jest.Mock<AWS.CloudFormation.DescribeStackEventsOutput, [AWS.CloudFormation.DescribeStackEventsInput]>);

let finished = false;
let error: Error | undefined = undefined;

for (const invocation of beforeStopInvocations) {
const invocation_ = invocation; // Capture loop variable in local because of closure semantics
const isLast = invocation === beforeStopInvocations[beforeStopInvocations.length - 1];
describeStackEvents = describeStackEvents.mockImplementationOnce(request => {
const ret = invocation_(request);
if (isLast) {
try {
const ret = invocation_(request);
if (isLast) {
finished = true;
}
return ret;
} catch (e: any) {
finished = true;
error = e;
throw e;
}
return ret;
});
}
if (error) {
throw error;
}
for (const invocation of afterStopInvocations) {
describeStackEvents = describeStackEvents.mockImplementationOnce(invocation);
}
Expand Down

0 comments on commit c16c7a8

Please sign in to comment.