Skip to content

Commit 96ba475

Browse files
committed
fix(integ-tests): add integ tests for the toolkit library
Signed-off-by: github-actions <github-actions@github.com>
1 parent 1082e00 commit 96ba475

File tree

18 files changed

+258
-20
lines changed

18 files changed

+258
-20
lines changed

.github/workflows/integ.yml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projenrc.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,7 @@ const cliInteg = configureProject(
15691569
],
15701570
devDeps: [
15711571
yarnCling,
1572+
toolkitLib,
15721573
'@types/semver@^7',
15731574
'@types/yargs@^16',
15741575
'@types/fs-extra@^9',
@@ -1604,6 +1605,8 @@ const cliInteg = configureProject(
16041605
);
16051606
cliInteg.eslint?.addIgnorePattern('resources/**/*.ts');
16061607

1608+
cliInteg.deps.addDependency('@aws-cdk/toolkit-lib', pj.DependencyType.OPTIONAL);
1609+
16071610
const compiledDirs = ['tests', 'test', 'lib'];
16081611
for (const compiledDir of compiledDirs) {
16091612
cliInteg.gitignore.addPatterns(`${compiledDir}/**/*.js`);

packages/@aws-cdk-testing/cli-integ/.projen/deps.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/cli-integ/.projen/tasks.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/cli-integ/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ inject these dependencies into tests. Users can specify component versions, but
4545
Test Authors are responsible for taking these parameters and using it to set up
4646
the right environment for the tests.
4747

48-
| Component | Command-line argument | Default | Treatment by runner | Treatment in test |
49-
|-----------------------|--------------------------------------|-------------|----------------------------|-------------------------------------------|
50-
| CDK Construct Library | `--framework-version=VERSION` | Latest | Nothing | `npm install` into temporary project dir. |
51-
| CDK CLI | `--cli-version=VERSION` | Auto source | `npm install` into tempdir | Add to `$PATH`. |
48+
| Component | Command-line argument | Default | Treatment by runner | Treatment in test |
49+
|-----------------------|--------------------------------------|-------------|----------------------------|-----------------------------------------------|
50+
| CDK Construct Library | `--framework-version=VERSION` | Latest | Nothing | `npm install` into temporary project dir. |
51+
| CDK CLI | `--cli-version=VERSION` | Auto source | `npm install` into tempdir | Add to `$PATH`. |
5252
| | `--cli-source=ROOT` or `auto` | Auto source | | Add `<ROOT>/packages/aws-cdk/bin` to `$PATH`. |
53+
| Toolkit Library | `--toolkit-lib-version=VERSION` | Devdep | Install into its own deps | Nothing
5354

5455
### Running a test suite
5556

packages/@aws-cdk-testing/cli-integ/lib/cli/run-suite.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ async function main() {
3434
alias: 'f',
3535
type: 'string',
3636
})
37+
.options('toolkit-lib-version', {
38+
describe: 'Toolkit lib version to use',
39+
alias: 'l',
40+
type: 'string',
41+
})
3742
.option('use-source', {
3843
descripton: 'Use TypeScript packages from the given source repository (or "auto")',
3944
type: 'string',
@@ -153,6 +158,8 @@ async function main() {
153158
library,
154159
});
155160

161+
const jestConfig = path.resolve(__dirname, '..', '..', 'resources', 'integ.jest.config.js');
162+
156163
await jest.run([
157164
'--randomize',
158165
...args.runInBand ? ['-i'] : [],
@@ -161,7 +168,7 @@ async function main() {
161168
...args.maxWorkers ? [`--maxWorkers=${args.maxWorkers}`] : [],
162169
...passWithNoTests ? ['--passWithNoTests'] : [],
163170
...args['test-file'] ? [args['test-file']] : [],
164-
], path.resolve(__dirname, '..', '..', 'resources', 'integ.jest.config.js'));
171+
], jestConfig);
165172
} finally {
166173
for (const disp of disposables) {
167174
await disp.dispose();

packages/@aws-cdk-testing/cli-integ/lib/npm.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ export async function npmMostRecentMatching(packageName: string, range: string)
2424
return output[output.length - 1];
2525
}
2626

27+
export async function npmQueryInstalledVersion(packageName: string, dir: string) {
28+
const reportStr = await shell(['node', require.resolve('npm'), 'list', '--json', '--depth', '0', packageName], {
29+
cwd: dir,
30+
show: 'error',
31+
});
32+
const report = JSON.parse(reportStr);
33+
return report.dependencies[packageName].version;
34+
}
35+
2736
/**
2837
* Use NPM preinstalled on the machine to look up a list of TypeScript versions
2938
*/

packages/@aws-cdk-testing/cli-integ/lib/package-sources/cli-npm-source.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as os from 'os';
22
import * as path from 'path';
33
import * as fs from 'fs-extra';
44
import type { IRunnerSource, ITestCliSource, IPreparedRunnerSource } from './source';
5+
import { npmQueryInstalledVersion } from '../npm';
56
import { addToShellPath, rimraf, shell } from '../shell';
67

78
export class RunnerCliNpmSource implements IRunnerSource<ITestCliSource> {
@@ -18,13 +19,7 @@ export class RunnerCliNpmSource implements IRunnerSource<ITestCliSource> {
1819
await shell(['node', require.resolve('npm'), 'install', `aws-cdk@${this.range}`], {
1920
cwd: tempDir,
2021
});
21-
22-
const reportStr = await shell(['node', require.resolve('npm'), 'list', '--json', '--depth', '0', 'aws-cdk'], {
23-
cwd: tempDir,
24-
show: 'error',
25-
});
26-
const report = JSON.parse(reportStr);
27-
const installedVersion = report.dependencies['aws-cdk'].version;
22+
const installedVersion = await npmQueryInstalledVersion('aws-cdk', tempDir);
2823

2924
return {
3025
version: installedVersion,

packages/@aws-cdk-testing/cli-integ/lib/package-sources/cli-repo-source.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,25 @@ import { addToShellPath } from '../shell';
1010
*/
1111
export class RunnerCliRepoSource implements IRunnerSource<ITestCliSource> {
1212
public readonly sourceDescription: string;
13-
private readonly cliPath: string;
13+
private readonly cliBinPath: string;
1414

1515
constructor(private readonly repoRoot: string) {
16-
this.cliPath = path.join(this.repoRoot, 'packages', 'aws-cdk', 'bin');
17-
this.sourceDescription = this.cliPath;
16+
this.cliBinPath = path.join(this.repoRoot, 'packages', 'aws-cdk', 'bin');
17+
this.sourceDescription = this.cliBinPath;
1818
}
1919

2020
public async runnerPrepare(): Promise<IPreparedRunnerSource<ITestCliSource>> {
2121
if (!await fs.pathExists(path.join(this.repoRoot, 'package.json')) || !await fs.pathExists(path.join(this.repoRoot, 'yarn.lock'))) {
2222
throw new Error(`${this.repoRoot}: does not look like the repository root`);
2323
}
2424

25+
const pj = JSON.parse(await fs.readFile(path.join(this.cliBinPath, '..', 'package.json'), 'utf-8'));
26+
2527
return {
26-
version: '*',
28+
version: pj.version,
2729
dispose: () => Promise.resolve(),
2830
serialize: () => {
29-
return [TestCliRepoSource, [this.cliPath]];
31+
return [TestCliRepoSource, [this.cliBinPath]];
3032
},
3133
};
3234
}

packages/@aws-cdk-testing/cli-integ/lib/package-sources/find-root.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { findUp } from '../files';
55
* Find the root directory of the repo from the current directory
66
*/
77
export async function autoFindRoot() {
8-
const found = findUp('release.json');
8+
const found = findUp('yarn.lock');
99
if (!found) {
10-
throw new Error(`Could not determine repository root: 'release.json' not found from ${process.cwd()}`);
10+
throw new Error(`Could not determine repository root: 'yarn.lock' not found from ${process.cwd()}`);
1111
}
1212
return path.dirname(found);
1313
}

0 commit comments

Comments
 (0)