From a279b989f6750b004da84e5b6bcbe60ec32a5415 Mon Sep 17 00:00:00 2001 From: Rico Hermans Date: Tue, 29 Oct 2024 10:41:44 +0100 Subject: [PATCH] chore: add Amplify integration tests (#31921) Test integration with the Amplify client, that uses CDK under the hood. Creates a new project, deploys it, and then deletes it again. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../lib/package-sources/release-source.ts | 4 +++ .../lib/package-sources/repo-source.ts | 4 +++ .../cli-integ/lib/package-sources/source.ts | 5 ++++ .../tool-integrations/amplify.integtest.ts | 27 +++++++++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/amplify.integtest.ts diff --git a/packages/@aws-cdk-testing/cli-integ/lib/package-sources/release-source.ts b/packages/@aws-cdk-testing/cli-integ/lib/package-sources/release-source.ts index 544e9ef5dabf7..10b227678ef26 100644 --- a/packages/@aws-cdk-testing/cli-integ/lib/package-sources/release-source.ts +++ b/packages/@aws-cdk-testing/cli-integ/lib/package-sources/release-source.ts @@ -60,6 +60,10 @@ export class ReleasePackageSource implements IPackageSource { return this.version.split('.')[0] as string; } + public requestedCliVersion() { + return this.version; + } + public requestedFrameworkVersion() { return process.env.FRAMEWORK_VERSION!; } diff --git a/packages/@aws-cdk-testing/cli-integ/lib/package-sources/repo-source.ts b/packages/@aws-cdk-testing/cli-integ/lib/package-sources/repo-source.ts index 7a5f08ec71b98..e6d3714aa4b64 100644 --- a/packages/@aws-cdk-testing/cli-integ/lib/package-sources/repo-source.ts +++ b/packages/@aws-cdk-testing/cli-integ/lib/package-sources/repo-source.ts @@ -49,6 +49,10 @@ export class RepoPackageSource implements IPackageSource { return releaseJson.majorVersion; } + public requestedCliVersion(): string { + return '*'; + } + public requestedFrameworkVersion(): string { return '*'; } diff --git a/packages/@aws-cdk-testing/cli-integ/lib/package-sources/source.ts b/packages/@aws-cdk-testing/cli-integ/lib/package-sources/source.ts index 21e970701db94..88d0c4051d39a 100644 --- a/packages/@aws-cdk-testing/cli-integ/lib/package-sources/source.ts +++ b/packages/@aws-cdk-testing/cli-integ/lib/package-sources/source.ts @@ -14,6 +14,11 @@ export interface IPackageSource { initializeDotnetPackages(targetDir: string): Promise; + /** + * CLI version + */ + requestedCliVersion(): string; + /** * Framework version if it's different than the CLI version * diff --git a/packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/amplify.integtest.ts b/packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/amplify.integtest.ts new file mode 100644 index 0000000000000..50be902ef31d2 --- /dev/null +++ b/packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/amplify.integtest.ts @@ -0,0 +1,27 @@ +import { promises as fs } from 'fs'; +import * as path from 'path'; +import { integTest, withTemporaryDirectory, ShellHelper, withPackages, TemporaryDirectoryContext } from '../../lib'; + +const TIMEOUT = 1800_000; + +integTest('amplify integration', withTemporaryDirectory(withPackages(async (context) => { + const shell = ShellHelper.fromContext(context); + + await shell.shell(['npm', 'create', '-y', 'amplify@latest']); + await shell.shell(['npx', 'ampx', 'configure', 'telemetry', 'disable']); + + // This will create 'package.json' implicating a certain version of the CDK + await updateCdkDependency(context, context.packages.requestedCliVersion(), context.packages.requestedFrameworkVersion()); + await shell.shell(['npm', 'install']); + + await shell.shell(['npx', 'ampx', 'sandbox', '--once']); + await shell.shell(['npx', 'ampx', 'sandbox', 'delete', '--yes']); +})), TIMEOUT); + +async function updateCdkDependency(context: TemporaryDirectoryContext, cliVersion: string, libVersion: string) { + const filename = path.join(context.integTestDir, 'package.json'); + const pj = JSON.parse(await fs.readFile(filename, { encoding: 'utf-8' })); + pj.devDependencies['aws-cdk'] = cliVersion; + pj.devDependencies['aws-cdk-lib'] = libVersion; + await fs.writeFile(filename, JSON.stringify(pj, undefined, 2), { encoding: 'utf-8' }); +}