Skip to content

Commit

Permalink
Fix cdk tests when new dependencies are shipped to npm. (aws-amplify#…
Browse files Browse the repository at this point in the history
…2107)

* Fix cdk tests when new dependencies are shipped to npm.

* try this

* try this

* try this

* try this
  • Loading branch information
sobolk authored Oct 14, 2024
1 parent b35f01d commit 39ea5a0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .changeset/breezy-spiders-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
});
};

0 comments on commit 39ea5a0

Please sign in to comment.