Skip to content

Commit

Permalink
chore: add Amplify integration tests (#31921)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
rix0rrr authored Oct 29, 2024
1 parent d108a80 commit a279b98
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export class RepoPackageSource implements IPackageSource {
return releaseJson.majorVersion;
}

public requestedCliVersion(): string {
return '*';
}

public requestedFrameworkVersion(): string {
return '*';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export interface IPackageSource {

initializeDotnetPackages(targetDir: string): Promise<void>;

/**
* CLI version
*/
requestedCliVersion(): string;

/**
* Framework version if it's different than the CLI version
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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' });
}

0 comments on commit a279b98

Please sign in to comment.