Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: print more information in Aspects proptest #32543

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions packages/aws-cdk-lib/core/test/aspect.prop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,12 @@ function arbConstructTreeFactory(): fc.Arbitrary<ConstructFactory> {
*/
class PrettyApp {
private readonly initialTree: Set<string>;
private readonly initialAspects: Map<string, Set<string>>;

constructor(public readonly cdkApp: App, public readonly executionState: ExecutionState) {
this.initialTree = new Set(cdkApp.node.findAll().map(c => c.node.path));
const constructs = cdkApp.node.findAll();
this.initialTree = new Set(constructs.map(c => c.node.path));
this.initialAspects = new Map(constructs.map(c => [c.node.path, new Set(renderAspects(c))]));
}

/**
Expand Down Expand Up @@ -402,7 +405,14 @@ class PrettyApp {
}

function recurse(construct: Construct) {
const aspects = Aspects.of(construct).applied.map(a => `${a.aspect}@${a.priority}`);
const aspects = renderAspects(construct);

for (let i = 0; i < aspects.length; i++) {
if (!(self.initialAspects.get(construct.node.path) ?? new Set()).has(aspects[i])) {
aspects[i] += ' (added)';
}
}

line([
'+-',
...self.initialTree.has(construct.node.path) ? [] : ['(added)'],
Expand All @@ -419,6 +429,21 @@ class PrettyApp {
}
}

function renderAspects(c: Construct) {
return unique(Aspects.of(c).applied.map(a => `${a.aspect}@${a.priority}`));
}

function unique(xs: string[]): string[] {
const seen = new Set<string>();
const ret: string[] = [];
for (const x of xs) {
if (seen.has(x)) { continue; }
ret.push(x);
seen.add(x);
}
return ret;
}

interface AspectVisit {
construct: IConstruct;
aspect: TracingAspect;
Expand Down
Loading