Skip to content

Commit

Permalink
chore: print more information in Aspects proptest (#32543)
Browse files Browse the repository at this point in the history
We weren't printing which Aspects were there at the start of the tree, vs which Aspects were added during the Aspect run.

Print that info.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr authored Dec 17, 2024
1 parent 506d210 commit 537cabf
Showing 1 changed file with 27 additions and 2 deletions.
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

0 comments on commit 537cabf

Please sign in to comment.