Skip to content

many tests targeting annotations are brittle #19544

@kaizencc

Description

@kaizencc

What is the problem?

See:

expect(target.node.metadataEntry).toEqual([{
type: 'aws:cdk:warning',
data: 'cron: If you don\'t pass \'minute\', by default the event runs every minute. Pass \'minute: \'*\'\' if that\'s what you intend, or \'minute: 0\' to run once per hour instead.',
trace: undefined,
}]);

And many more places in the CDK. The problem is that they assert on a specific node.metadataentry, but if we ever add a different message to the node metadata, this test will fail.

This happens many times when we add warnings around the CDK, see #19464.

Reproduction Steps

see linked file.

What did you expect to happen?

These tests should be changed to:

Annotations.fromStack(stack).hasWarning('/Path/To/Node', 'warning message');

also:

Annotations.fromStack(stack).hasNoWarning('/Path/To/Node', 'warning message');

This will be more robust as it does not depend on the existence/non-existence of other messages on the node.

What actually happened?

Possible failing tests in the future.

CDK CLI Version

latest

Framework Version

No response

Node.js Version

latest

OS

Mac

Language

Typescript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.effort/smallSmall work item – less than a day of effortp1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions