diff --git a/package-lock.json b/package-lock.json index 0234104f83..907e82e9a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44,7 +44,7 @@ "rimraf": "^5.0.0", "tsx": "^3.12.6", "typedoc": "^0.25.3", - "typescript": "~5.2.0", + "typescript": "^5.3.2", "verdaccio": "^5.24.1" }, "engines": { @@ -19570,9 +19570,9 @@ } }, "node_modules/typescript": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", - "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.2.tgz", + "integrity": "sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ==", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/package.json b/package.json index 5718b0ff70..be61addacd 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ "rimraf": "^5.0.0", "tsx": "^3.12.6", "typedoc": "^0.25.3", - "typescript": "~5.2.0", + "typescript": "~5.3.2", "verdaccio": "^5.24.1" }, "workspaces": [ diff --git a/packages/integration-tests/src/define_backend_template_harness.ts b/packages/integration-tests/src/define_backend_template_harness.ts index b11fddad25..6c7bf753b8 100644 --- a/packages/integration-tests/src/define_backend_template_harness.ts +++ b/packages/integration-tests/src/define_backend_template_harness.ts @@ -9,7 +9,7 @@ import { Construct } from 'constructs'; /** * Asserts that the provided template has resources of 'resourceType' with the expected logical IDs */ -export const assertStableLogicalIds = ( +export const assertExpectedLogicalIds = ( template: Template, resourceType: string, expectedLogicalIds: string[] @@ -22,21 +22,33 @@ export const assertStableLogicalIds = ( }; /** - * Wrapper around `defineBackend` that returns CDK Template objects for each backend resource + * Synthesizes deterministic `defineBackend` CDK templates for each backend resource * * Supplies stable CDK context values to the synth process for deterministic synth output */ -export const defineBackendTemplateHarness: DefineBackendTemplateHarness = < +export const synthesizeBackendTemplates: SynthesizeBackendTemplates = < + T extends Record> +>( + constructFactories: T +) => { + try { + process.env.CDK_CONTEXT_JSON = JSON.stringify({ + [CDKContextKey.BACKEND_NAMESPACE]: 'testAppId', + [CDKContextKey.BACKEND_NAME]: 'testBranchName', + [CDKContextKey.DEPLOYMENT_TYPE]: 'branch', + secretLastUpdated: 123456789, + }); + return backendTemplatesCollector(constructFactories); + } finally { + delete process.env.CDK_CONTEXT_JSON; + } +}; + +const backendTemplatesCollector: SynthesizeBackendTemplates = < T extends Record> >( constructFactories: T ) => { - process.env.CDK_CONTEXT_JSON = JSON.stringify({ - [CDKContextKey.BACKEND_NAMESPACE]: 'testAppId', - [CDKContextKey.BACKEND_NAME]: 'testBranchName', - [CDKContextKey.DEPLOYMENT_TYPE]: 'branch', - secretLastUpdated: 123456789, - }); if (Object.keys(constructFactories).length === 0) { throw new Error('constructFactories must have at least one entry'); } @@ -55,7 +67,7 @@ export const defineBackendTemplateHarness: DefineBackendTemplateHarness = < return result as { [K in keyof T]: Template } & { root: Template }; }; -type DefineBackendTemplateHarness = < +type SynthesizeBackendTemplates = < T extends Record> >( constructFactories: T diff --git a/packages/integration-tests/src/test-in-memory/integration_tests.test.ts b/packages/integration-tests/src/test-in-memory/integration_tests.test.ts index 6817519a8a..5f34be654c 100644 --- a/packages/integration-tests/src/test-in-memory/integration_tests.test.ts +++ b/packages/integration-tests/src/test-in-memory/integration_tests.test.ts @@ -1,7 +1,7 @@ import { dataStorageAuthWithTriggers } from '../test-projects/data-storage-auth-with-triggers-ts/amplify/test_factories.js'; import { - assertStableLogicalIds, - defineBackendTemplateHarness, + assertExpectedLogicalIds, + synthesizeBackendTemplates, } from '../define_backend_template_harness.js'; import { it } from 'node:test'; import { dataWithoutAuth } from '../test-projects/standalone-data-auth-modes/amplify/test_factories.js'; @@ -15,60 +15,60 @@ import { dataWithoutAuthNoAuthMode } from '../test-projects/standalone-data-sand */ void it('data storage auth with triggers', () => { - const templates = defineBackendTemplateHarness(dataStorageAuthWithTriggers); + const templates = synthesizeBackendTemplates(dataStorageAuthWithTriggers); - assertStableLogicalIds(templates.root, 'AWS::CloudFormation::Stack', [ + assertExpectedLogicalIds(templates.root, 'AWS::CloudFormation::Stack', [ 'auth179371D7', 'data7552DF31', 'function1351588B', 'storage0EC3F24A', ]); - assertStableLogicalIds(templates.auth, 'AWS::Cognito::UserPool', [ + assertExpectedLogicalIds(templates.auth, 'AWS::Cognito::UserPool', [ 'amplifyAuthUserPool4BA7F805', ]); - assertStableLogicalIds(templates.data, 'AWS::AppSync::GraphQLApi', [ + assertExpectedLogicalIds(templates.data, 'AWS::AppSync::GraphQLApi', [ 'amplifyDataGraphQLAPI42A6FA33', ]); - assertStableLogicalIds(templates.data, 'AWS::CloudFormation::Stack', [ + assertExpectedLogicalIds(templates.data, 'AWS::CloudFormation::Stack', [ 'amplifyDataAmplifyTableManagerNestedStackAmplifyTableManagerNestedStackResource86290833', 'amplifyDataFunctionDirectiveStackNestedStackFunctionDirectiveStackNestedStackResource1246A302', 'amplifyDataTodoNestedStackTodoNestedStackResource551CEA56', ]); - assertStableLogicalIds(templates.storage, 'AWS::S3::Bucket', [ + assertExpectedLogicalIds(templates.storage, 'AWS::S3::Bucket', [ // eslint-disable-next-line spellcheck/spell-checker 'amplifyStorageamplifyStorageBucketC2F702CD', ]); }); void it('data without auth with lambda auth mode', () => { - const templates = defineBackendTemplateHarness(dataWithoutAuth); + const templates = synthesizeBackendTemplates(dataWithoutAuth); - assertStableLogicalIds(templates.root, 'AWS::CloudFormation::Stack', [ + assertExpectedLogicalIds(templates.root, 'AWS::CloudFormation::Stack', [ 'data7552DF31', 'function1351588B', ]); - assertStableLogicalIds(templates.data, 'AWS::AppSync::GraphQLApi', [ + assertExpectedLogicalIds(templates.data, 'AWS::AppSync::GraphQLApi', [ 'amplifyDataGraphQLAPI42A6FA33', ]); - assertStableLogicalIds(templates.data, 'AWS::CloudFormation::Stack', [ + assertExpectedLogicalIds(templates.data, 'AWS::CloudFormation::Stack', [ 'amplifyDataAmplifyTableManagerNestedStackAmplifyTableManagerNestedStackResource86290833', 'amplifyDataTodoNestedStackTodoNestedStackResource551CEA56', ]); }); void it('data without auth with default auth mode', () => { - const templates = defineBackendTemplateHarness(dataWithoutAuthNoAuthMode); + const templates = synthesizeBackendTemplates(dataWithoutAuthNoAuthMode); - assertStableLogicalIds(templates.root, 'AWS::CloudFormation::Stack', [ + assertExpectedLogicalIds(templates.root, 'AWS::CloudFormation::Stack', [ 'data7552DF31', ]); - assertStableLogicalIds(templates.data, 'AWS::AppSync::GraphQLApi', [ + assertExpectedLogicalIds(templates.data, 'AWS::AppSync::GraphQLApi', [ 'amplifyDataGraphQLAPI42A6FA33', ]); - assertStableLogicalIds(templates.data, 'AWS::CloudFormation::Stack', [ + assertExpectedLogicalIds(templates.data, 'AWS::CloudFormation::Stack', [ 'amplifyDataAmplifyTableManagerNestedStackAmplifyTableManagerNestedStackResource86290833', 'amplifyDataTodoNestedStackTodoNestedStackResource551CEA56', ]); diff --git a/packages/integration-tests/tsconfig.json b/packages/integration-tests/tsconfig.json index 1f51a22e20..3e171885a9 100644 --- a/packages/integration-tests/tsconfig.json +++ b/packages/integration-tests/tsconfig.json @@ -7,5 +7,5 @@ { "path": "../client-config" }, { "path": "../platform-core" } ], - "exclude": ["**/node_modules", "**/lib"] + "exclude": ["**/node_modules", "**/lib", "src/e2e-tests"] }