Skip to content

Commit

Permalink
feat: add integ-runner and rosetta support (#17)
Browse files Browse the repository at this point in the history
This PR adds default support for integ-runner and rosetta for construct
libraries. I've been making these changes individually for some repos
(see https://github.com/cdklabs/cdk-stacksets), but we should be
controlling it centrally.

closes https://github.com/cdklabs/cdk-ops/issues/2438
  • Loading branch information
corymhall authored Feb 9, 2023
1 parent 0fd6038 commit 1afea3d
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/cdk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { awscdk, typescript } from 'projen';
import { Stability } from 'projen/lib/cdk';
import { IntegRunner } from './integ-runner';
import { Private } from './private';
import { Rosetta } from './rosetta';

export interface CdkConstructLibraryOptions extends awscdk.AwsCdkConstructLibraryOptions {
/**
Expand Down Expand Up @@ -52,6 +54,9 @@ export class CdkConstructLibrary extends awscdk.AwsCdkConstructLibrary {
});

this.private = options.private ?? true;
new Rosetta(this);
new IntegRunner(this);


if (this.private) {
new Private(this);
Expand Down
29 changes: 29 additions & 0 deletions src/integ-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Component, DependencyType } from 'projen';
import { TypeScriptProject } from 'projen/lib/typescript';

/**
* This component adds support for using `integ-runner` and `integ-tests`
* in a construct library.
*/
export class IntegRunner extends Component {
constructor(project: TypeScriptProject) {
super(project);

project.deps.addDependency('@aws-cdk/integ-runner@^2.45.0', DependencyType.DEVENV);
project.deps.addDependency('@aws-cdk/integ-tests-alpha@^2.45.0-alpha.0', DependencyType.DEVENV);

const integSnapshotTask = project.addTask('integ', {
description: 'Run integration snapshot tests',
receiveArgs: true,
exec: 'yarn integ-runner --language typescript',
});

project.addTask('integ:update', {
description: 'Run and update integration snapshot tests',
exec: 'yarn integ-runner --language typescript --update-on-failed',
receiveArgs: true,
});

project.testTask.spawn(integSnapshotTask);
}
}
41 changes: 41 additions & 0 deletions src/rosetta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Component, TextFile } from 'projen';
import { TypeScriptProject } from 'projen/lib/typescript';

/**
* The Rosetta component adds builtin rosetta support
* for a construct library. Since ConstructHub will run
* rosetta for real, this just adds a check to the build to
* ensure that rosetta will run successfully
*/
export class Rosetta extends Component {
constructor(project: TypeScriptProject) {
super(project);

const rosettaTask = project.addTask('rosetta:extract', {
description: 'Test rosetta extract',
exec: 'yarn --silent jsii-rosetta extract --strict',
});
project.postCompileTask.spawn(rosettaTask);
project.addGitIgnore('.jsii.tabl.json');

new TextFile(project, 'rosetta/default.ts-fixture', {
readonly: false,
lines: [
'// Fixture with packages imported, but nothing else',
"import { Construct } from 'constructs';",
'import {',
' Stack,',
"} from 'aws-cdk-lib';",
'',
'class Fixture extends Stack {',
' constructor(scope: Construct, id: string) {',
' super(scope, id);',
'',
' /// here',
' }',
'}',
],
marker: false,
});
}
}
66 changes: 66 additions & 0 deletions test/__snapshots__/cdk.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions test/__snapshots__/cdklabs.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1afea3d

Please sign in to comment.