Skip to content

Commit

Permalink
feat: install AWS CDK CLI for integration snapshot tests (projen#1539)
Browse files Browse the repository at this point in the history
Currently when using a `AwsCdkConstructLibrary` it must be manually
added to the project.

---
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • Loading branch information
jogold authored Jan 18, 2022
1 parent 4b87871 commit 3a291b7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/awscdk/integration-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ export class IntegrationTest extends Component {

const app = `ts-node -P ${options.tsconfigPath} ${entry}`;

if (!project.deps.tryGetDependency("aws-cdk")) {
project.deps.addDependency(
`aws-cdk@^${options.cdkDeps.cdkMajorVersion}`,
DependencyType.BUILD
);
}

if (!project.deps.tryGetDependency("ts-node")) {
project.deps.addDependency("ts-node", DependencyType.BUILD);
}
Expand Down
44 changes: 44 additions & 0 deletions test/awscdk/integration-test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,50 @@ test("installs ts-node if needed", () => {
});
});

test("installs aws-cdk v1 if needed", () => {
const project = new TypeScriptProject({
name: "test",
defaultReleaseBranch: "main",
});

new IntegrationTest(project, {
entrypoint: "test/foo.integ.ts",
tsconfigPath: project.tsconfigDev.fileName,
cdkDeps: new AwsCdkDepsJs(project, {
cdkVersion: "1.0.0",
dependencyType: DependencyType.RUNTIME,
}),
});

expect(project.deps.getDependency("aws-cdk")).toStrictEqual({
name: "aws-cdk",
type: "build",
version: "^1",
});
});

test("installs aws-cdk v2 if needed", () => {
const project = new TypeScriptProject({
name: "test",
defaultReleaseBranch: "main",
});

new IntegrationTest(project, {
entrypoint: "test/foo.integ.ts",
tsconfigPath: project.tsconfigDev.fileName,
cdkDeps: new AwsCdkDepsJs(project, {
cdkVersion: "2.8.0",
dependencyType: DependencyType.RUNTIME,
}),
});

expect(project.deps.getDependency("aws-cdk")).toStrictEqual({
name: "aws-cdk",
type: "build",
version: "^2",
});
});

test("synthesizing cdk v2 integration tests", () => {
// GIVEN
const project = new awscdk.AwsCdkTypeScriptApp({
Expand Down

0 comments on commit 3a291b7

Please sign in to comment.