diff --git a/packages/@aws-cdk-testing/cli-integ/lib/with-aws.ts b/packages/@aws-cdk-testing/cli-integ/lib/with-aws.ts index a9ebe5a2ba968..8f9ca8d51a612 100644 --- a/packages/@aws-cdk-testing/cli-integ/lib/with-aws.ts +++ b/packages/@aws-cdk-testing/cli-integ/lib/with-aws.ts @@ -10,11 +10,11 @@ export type AwsContext = { readonly aws: AwsClients }; * * Allocate the next region from the REGION pool and dispose it afterwards. */ -export function withAws( - block: (context: TestContext & AwsContext & DisableBootstrapContext) => Promise, +export function withAws( + block: (context: A & AwsContext & DisableBootstrapContext) => Promise, disableBootstrap: boolean = false, -): (context: TestContext) => Promise { - return (context: TestContext) => regionPool().using(async (region) => { +): (context: A) => Promise { + return (context: A) => regionPool().using(async (region) => { const aws = await AwsClients.forRegion(region, context.output); await sanityCheck(aws); 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 index 50be902ef31d2..8c926e010ef76 100644 --- 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 @@ -1,10 +1,11 @@ import { promises as fs } from 'fs'; import * as path from 'path'; -import { integTest, withTemporaryDirectory, ShellHelper, withPackages, TemporaryDirectoryContext } from '../../lib'; +import { withToolContext } from './with-tool-context'; +import { integTest, ShellHelper, TemporaryDirectoryContext } from '../../lib'; const TIMEOUT = 1800_000; -integTest('amplify integration', withTemporaryDirectory(withPackages(async (context) => { +integTest('amplify integration', withToolContext(async (context) => { const shell = ShellHelper.fromContext(context); await shell.shell(['npm', 'create', '-y', 'amplify@latest']); @@ -14,9 +15,24 @@ integTest('amplify integration', withTemporaryDirectory(withPackages(async (cont 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); + await shell.shell(['npx', 'ampx', 'sandbox', '--once'], { + modEnv: { + AWS_REGION: context.aws.region, + }, + }); + try { + + // Future code goes here, putting the try/finally here already so it doesn't + // get forgotten. + + } finally { + await shell.shell(['npx', 'ampx', 'sandbox', 'delete', '--yes'], { + modEnv: { + AWS_REGION: context.aws.region, + }, + }); + } +}), TIMEOUT); async function updateCdkDependency(context: TemporaryDirectoryContext, cliVersion: string, libVersion: string) { const filename = path.join(context.integTestDir, 'package.json'); diff --git a/packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/with-tool-context.ts b/packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/with-tool-context.ts new file mode 100644 index 0000000000000..91a9bf3c688a7 --- /dev/null +++ b/packages/@aws-cdk-testing/cli-integ/tests/tool-integrations/with-tool-context.ts @@ -0,0 +1,14 @@ +import { TestContext } from '../../lib/integ-test'; +import { AwsContext, withAws } from '../../lib/with-aws'; +import { DisableBootstrapContext } from '../../lib/with-cdk-app'; +import { PackageContext, withPackages } from '../../lib/with-packages'; +import { TemporaryDirectoryContext, withTemporaryDirectory } from '../../lib/with-temporary-directory'; + +/** + * The default prerequisites for tests running tool integrations + */ +export function withToolContext( + block: (context: A & TemporaryDirectoryContext & PackageContext & AwsContext & DisableBootstrapContext + ) => Promise) { + return withAws(withTemporaryDirectory(withPackages(block))); +}