From d63c2761f0503719710fa189006afd42932163a6 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Wed, 5 May 2021 16:45:08 +0200 Subject: [PATCH] fix: `assert` matches more than the template on multiple CDK copies (#14544) The `assert` library sometimes fails to get the template out of a `CloudFormationStackArtifact` if there are multiple copies of the CDK in the dependency tree. Fix by replacing an `instanceof` with a duck-type check. Fixes #14468. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/assert-internal/lib/synth-utils.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/assert-internal/lib/synth-utils.ts b/packages/@aws-cdk/assert-internal/lib/synth-utils.ts index bb8d9a437afd9..d8dc73aff881a 100644 --- a/packages/@aws-cdk/assert-internal/lib/synth-utils.ts +++ b/packages/@aws-cdk/assert-internal/lib/synth-utils.ts @@ -18,7 +18,7 @@ export class SynthUtils { */ public static toCloudFormation(stack: core.Stack, options: core.SynthesisOptions = { }): any { const synth = this._synthesizeWithNested(stack, options); - if (synth instanceof cxapi.CloudFormationStackArtifact) { + if (isStackArtifact(synth)) { return synth.template; } else { return synth; @@ -85,3 +85,7 @@ export interface SubsetOptions { */ resourceTypes?: string[]; } + +function isStackArtifact(x: object): x is cxapi.CloudFormationStackArtifact { + return 'template' in x; +} \ No newline at end of file