diff --git a/.changeset/breezy-spiders-sip.md b/.changeset/breezy-spiders-sip.md new file mode 100644 index 0000000000..a845151cc8 --- /dev/null +++ b/.changeset/breezy-spiders-sip.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/packages/integration-tests/src/test-project-setup/cdk/create_empty_cdk_project.ts b/packages/integration-tests/src/test-project-setup/cdk/create_empty_cdk_project.ts index 67d3b67758..72db39e0fe 100644 --- a/packages/integration-tests/src/test-project-setup/cdk/create_empty_cdk_project.ts +++ b/packages/integration-tests/src/test-project-setup/cdk/create_empty_cdk_project.ts @@ -24,5 +24,15 @@ export const createEmptyCdkProject = async ( await cdkCli(['init', 'app', '--language', 'typescript'], projectRoot).run(); + // Remove local node_modules after CDK init. + // This is to make sure that test project is using same version of + // CDK and constructs as the rest of the codebase. + // Otherwise, we might get errors about incompatible classes if + // dependencies on npm are ahead of our package-lock. + await fsp.rm(path.join(projectRoot, 'node_modules'), { + recursive: true, + force: true, + }); + return { projectName, projectRoot }; }; diff --git a/packages/integration-tests/src/test-project-setup/setup_deployed_backend_client.ts b/packages/integration-tests/src/test-project-setup/setup_deployed_backend_client.ts index 618ec72b26..66704f60cf 100644 --- a/packages/integration-tests/src/test-project-setup/setup_deployed_backend_client.ts +++ b/packages/integration-tests/src/test-project-setup/setup_deployed_backend_client.ts @@ -1,4 +1,10 @@ import { execa } from 'execa'; +import fsp from 'fs/promises'; +import { fileURLToPath } from 'node:url'; + +const packageLockPath = fileURLToPath( + new URL('../../../../package-lock.json', import.meta.url) +); /** * Configures package.json for testing the specified project directory with the version of deployed-backend-client on npm @@ -9,4 +15,14 @@ export const setupDeployedBackendClient = async ( await execa('npm', ['install', '@aws-amplify/deployed-backend-client'], { cwd: projectRootDirPath, }); + + // Install constructs version that is matching our package lock. + // Otherwise, the test might fail due to incompatible properties + // when two definitions are present. + const packageLock = JSON.parse(await fsp.readFile(packageLockPath, 'utf-8')); + const constructsVersion = + packageLock.packages['node_modules/constructs'].version; + await execa('npm', ['install', `constructs@${constructsVersion}`], { + cwd: projectRootDirPath, + }); };