Skip to content

Commit 5d9af0f

Browse files
authored
chore(CLI-integ-tests): cli integ tests cannot use local CDK framework (#31131)
### Reason for this change The cli integration tests cannot use your local version of `aws-cdk-lib`. This can be verified by making your `Stack` construct throw an error upon creation, and watching no CLI integration tests fail, even with `-a`. ### Description of changes Fixed the CLI integration test framework to correctly link the local packages, like it [used to](#23590). ### Description of how you validated changes Manual testing. This isn't something we can add automated tests for. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent b754353 commit 5d9af0f

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,14 @@ const YARN_MONOREPO_CACHE: Record<string, any> = {};
7575
*
7676
* Cached in YARN_MONOREPO_CACHE.
7777
*/
78-
async function findYarnPackages(root: string): Promise<Record<string, string>> {
78+
export async function findYarnPackages(root: string): Promise<Record<string, string>> {
7979
if (!(root in YARN_MONOREPO_CACHE)) {
80-
const output: YarnWorkspacesOutput = JSON.parse(await shell(['yarn', 'workspaces', '--silent', 'info'], {
80+
const outputDataString: string = JSON.parse(await shell(['yarn', 'workspaces', '--json', 'info'], {
8181
captureStderr: false,
8282
cwd: root,
8383
show: 'error',
84-
}));
84+
})).data;
85+
const output: YarnWorkspacesOutput = JSON.parse(outputDataString);
8586

8687
const ret: Record<string, string> = {};
8788
for (const [k, v] of Object.entries(output)) {
@@ -96,7 +97,7 @@ async function findYarnPackages(root: string): Promise<Record<string, string>> {
9697
* Find the root directory of the repo from the current directory
9798
*/
9899
export async function autoFindRoot() {
99-
const found = await findUp('release.json');
100+
const found = findUp('release.json');
100101
if (!found) {
101102
throw new Error(`Could not determine repository root: 'release.json' not found from ${process.cwd()}`);
102103
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as os from 'os';
44
import * as path from 'path';
55
import { outputFromStack, AwsClients } from './aws';
66
import { TestContext } from './integ-test';
7+
import { findYarnPackages } from './package-sources/repo-source';
78
import { IPackageSource } from './package-sources/source';
89
import { packageSourceInSubprocess } from './package-sources/subprocess';
910
import { RESOURCES_DIR } from './resources';
@@ -612,6 +613,17 @@ function defined<A>(x: A): x is NonNullable<A> {
612613
* for Node's dependency lookup mechanism).
613614
*/
614615
export async function installNpmPackages(fixture: TestFixture, packages: Record<string, string>) {
616+
if (process.env.REPO_ROOT) {
617+
const monoRepo = await findYarnPackages(process.env.REPO_ROOT);
618+
619+
// Replace the install target with the physical location of this package
620+
for (const key of Object.keys(packages)) {
621+
if (key in monoRepo) {
622+
packages[key] = monoRepo[key];
623+
}
624+
}
625+
}
626+
615627
fs.writeFileSync(path.join(fixture.integTestDir, 'package.json'), JSON.stringify({
616628
name: 'cdk-integ-tests',
617629
private: true,

0 commit comments

Comments
 (0)