diff --git a/.gitignore b/.gitignore index 58c2d574f1..7e66b0090f 100644 --- a/.gitignore +++ b/.gitignore @@ -44,4 +44,5 @@ packages/**/reports/junit/* test.out.log *.tsbuildinfo packages/amplify-graphiql-explorer/.eslintcache -!packages/amplify-graphql-model-transformer/src/__tests__/overrides/build/override.js \ No newline at end of file +!packages/amplify-graphql-model-transformer/src/__tests__/overrides/build/override.js +codebuild_specs/debug_workflow.yml diff --git a/codebuild_specs/cleanup_e2e_resources.yml b/codebuild_specs/cleanup_e2e_resources.yml index 3bdf3a0fd0..94a713fc82 100644 --- a/codebuild_specs/cleanup_e2e_resources.yml +++ b/codebuild_specs/cleanup_e2e_resources.yml @@ -9,3 +9,7 @@ phases: build: commands: - source ./shared-scripts.sh && _cleanupE2EResources +artifacts: + files: + - '**/*' + base-directory: $CODEBUILD_SRC_DIR/packages/amplify-e2e-tests/amplify-e2e-reports diff --git a/codebuild_specs/cleanup_workflow.yml b/codebuild_specs/cleanup_workflow.yml index 6674d74779..f466c28972 100644 --- a/codebuild_specs/cleanup_workflow.yml +++ b/codebuild_specs/cleanup_workflow.yml @@ -10,3 +10,7 @@ phases: commands: - yarn production-build - cd packages/amplify-e2e-tests && yarn clean-e2e-resources +artifacts: + files: + - '**/*' + base-directory: $CODEBUILD_SRC_DIR/packages/amplify-e2e-tests/amplify-e2e-reports diff --git a/codebuild_specs/e2e_workflow.yml b/codebuild_specs/e2e_workflow.yml index 34bb0cbb16..d9f05bc44a 100644 --- a/codebuild_specs/e2e_workflow.yml +++ b/codebuild_specs/e2e_workflow.yml @@ -116,64 +116,54 @@ batch: depend-on: - publish_to_local_registry - identifier: >- - index_with_stack_mappings_api_4_custom_policies_container_schema_iterative_rollback_1 + index_with_stack_mappings_api_4_custom_policies_container_schema_iterative_update_2 buildspec: codebuild_specs/run_e2e_tests.yml env: compute-type: BUILD_GENERAL1_MEDIUM variables: TEST_SUITE: >- - src/__tests__/graphql-v2/index-with-stack-mappings.test.ts|src/__tests__/api_4.test.ts|src/__tests__/custom_policies_container.test.ts|src/__tests__/schema-iterative-rollback-1.test.ts + src/__tests__/graphql-v2/index-with-stack-mappings.test.ts|src/__tests__/api_4.test.ts|src/__tests__/custom_policies_container.test.ts|src/__tests__/schema-iterative-update-2.test.ts CLI_REGION: ap-southeast-1 depend-on: - publish_to_local_registry - - identifier: >- - schema_iterative_update_2_api_connection_migration2_schema_iterative_rollback_2_api_5 - buildspec: codebuild_specs/run_e2e_tests.yml - env: - compute-type: BUILD_GENERAL1_MEDIUM - variables: - TEST_SUITE: >- - src/__tests__/schema-iterative-update-2.test.ts|src/__tests__/migration/api.connection.migration2.test.ts|src/__tests__/schema-iterative-rollback-2.test.ts|src/__tests__/api_5.test.ts - CLI_REGION: eu-central-1 - depend-on: - - publish_to_local_registry - - identifier: containers_api_secrets_schema_function_1_api_3_base_cdk + - identifier: api_connection_migration2_api_5_containers_api_secrets_schema_function_1 buildspec: codebuild_specs/run_e2e_tests.yml env: compute-type: BUILD_GENERAL1_MEDIUM variables: TEST_SUITE: >- - src/__tests__/containers-api-secrets.test.ts|src/__tests__/schema-function-1.test.ts|src/__tests__/api_3.test.ts|src/__tests__/cdk/base-cdk.test.ts + src/__tests__/migration/api.connection.migration2.test.ts|src/__tests__/api_5.test.ts|src/__tests__/containers-api-secrets.test.ts|src/__tests__/schema-function-1.test.ts CLI_REGION: us-east-1 depend-on: - publish_to_local_registry - - identifier: rds_import_vpc_rds_model_v2_rds_relational_directives_api_1 + - identifier: api_3_base_cdk_rds_import_vpc_rds_model_v2 buildspec: codebuild_specs/run_e2e_tests.yml env: compute-type: BUILD_GENERAL1_MEDIUM variables: TEST_SUITE: >- - src/__tests__/rds-import-vpc.test.ts|src/__tests__/rds-model-v2.test.ts|src/__tests__/rds-relational-directives.test.ts|src/__tests__/api_1.test.ts + src/__tests__/api_3.test.ts|src/__tests__/cdk/base-cdk.test.ts|src/__tests__/rds-import-vpc.test.ts|src/__tests__/rds-model-v2.test.ts CLI_REGION: ap-northeast-1 depend-on: - publish_to_local_registry - - identifier: resolvers_sync_query_datastore_api_6_api_lambda_auth + - identifier: rds_relational_directives_api_1_resolvers_sync_query_datastore buildspec: codebuild_specs/run_e2e_tests.yml env: compute-type: BUILD_GENERAL1_MEDIUM variables: TEST_SUITE: >- - src/__tests__/resolvers.test.ts|src/__tests__/graphql-v2/sync_query_datastore.test.ts|src/__tests__/api_6.test.ts|src/__tests__/graphql-v2/api_lambda_auth.test.ts - CLI_REGION: eu-central-1 + src/__tests__/rds-relational-directives.test.ts|src/__tests__/api_1.test.ts|src/__tests__/resolvers.test.ts|src/__tests__/graphql-v2/sync_query_datastore.test.ts + CLI_REGION: us-east-1 depend-on: - publish_to_local_registry - - identifier: api_9 + - identifier: api_6_api_lambda_auth_api_9 buildspec: codebuild_specs/run_e2e_tests.yml env: compute-type: BUILD_GENERAL1_MEDIUM variables: - TEST_SUITE: src/__tests__/api_9.test.ts - CLI_REGION: ap-northeast-1 + TEST_SUITE: >- + src/__tests__/api_6.test.ts|src/__tests__/graphql-v2/api_lambda_auth.test.ts|src/__tests__/api_9.test.ts + CLI_REGION: ap-southeast-2 depend-on: - publish_to_local_registry - identifier: function_migration @@ -296,13 +286,31 @@ batch: USE_PARENT_ACCOUNT: 1 depend-on: - publish_to_local_registry + - identifier: schema_iterative_rollback_1 + buildspec: codebuild_specs/run_e2e_tests.yml + env: + compute-type: BUILD_GENERAL1_SMALL + variables: + TEST_SUITE: src/__tests__/schema-iterative-rollback-1.test.ts + CLI_REGION: eu-central-1 + depend-on: + - publish_to_local_registry + - identifier: schema_iterative_rollback_2 + buildspec: codebuild_specs/run_e2e_tests.yml + env: + compute-type: BUILD_GENERAL1_SMALL + variables: + TEST_SUITE: src/__tests__/schema-iterative-rollback-2.test.ts + CLI_REGION: ap-southeast-1 + depend-on: + - publish_to_local_registry - identifier: schema_key buildspec: codebuild_specs/run_e2e_tests.yml env: compute-type: BUILD_GENERAL1_SMALL variables: TEST_SUITE: src/__tests__/schema-key.test.ts - CLI_REGION: ap-northeast-1 + CLI_REGION: ap-southeast-2 depend-on: - publish_to_local_registry - identifier: containers_api_1 @@ -320,7 +328,7 @@ batch: compute-type: BUILD_GENERAL1_SMALL variables: TEST_SUITE: src/__tests__/schema-auth-4.test.ts - CLI_REGION: us-east-1 + CLI_REGION: us-east-2 depend-on: - publish_to_local_registry - identifier: schema_auth_8 @@ -329,7 +337,7 @@ batch: compute-type: BUILD_GENERAL1_SMALL variables: TEST_SUITE: src/__tests__/schema-auth-8.test.ts - CLI_REGION: us-east-2 + CLI_REGION: us-west-2 depend-on: - publish_to_local_registry - identifier: api_key_migration2 @@ -338,7 +346,7 @@ batch: compute-type: BUILD_GENERAL1_SMALL variables: TEST_SUITE: src/__tests__/migration/api.key.migration2.test.ts - CLI_REGION: us-west-2 + CLI_REGION: eu-west-2 USE_PARENT_ACCOUNT: 1 depend-on: - publish_to_local_registry @@ -348,7 +356,7 @@ batch: compute-type: BUILD_GENERAL1_SMALL variables: TEST_SUITE: src/__tests__/schema-auth-11.test.ts - CLI_REGION: eu-west-2 + CLI_REGION: eu-central-1 depend-on: - publish_to_local_registry - identifier: api_key_migration1 @@ -357,7 +365,16 @@ batch: compute-type: BUILD_GENERAL1_SMALL variables: TEST_SUITE: src/__tests__/migration/api.key.migration1.test.ts - CLI_REGION: eu-central-1 + CLI_REGION: ap-southeast-1 + depend-on: + - publish_to_local_registry + - identifier: api_11 + buildspec: codebuild_specs/run_e2e_tests.yml + env: + compute-type: BUILD_GENERAL1_SMALL + variables: + TEST_SUITE: src/__tests__/api_11.test.ts + CLI_REGION: ap-southeast-2 depend-on: - publish_to_local_registry - identifier: schema_model @@ -366,7 +383,7 @@ batch: compute-type: BUILD_GENERAL1_SMALL variables: TEST_SUITE: src/__tests__/schema-model.test.ts - CLI_REGION: ap-southeast-1 + CLI_REGION: us-east-2 depend-on: - publish_to_local_registry - identifier: apigw @@ -375,7 +392,7 @@ batch: compute-type: BUILD_GENERAL1_SMALL variables: TEST_SUITE: src/__tests__/apigw.test.ts - CLI_REGION: ap-southeast-2 + CLI_REGION: us-west-2 depend-on: - publish_to_local_registry - identifier: containers_api_2 @@ -393,7 +410,7 @@ batch: compute-type: BUILD_GENERAL1_SMALL variables: TEST_SUITE: src/__tests__/schema-auth-14.test.ts - CLI_REGION: us-east-2 + CLI_REGION: eu-central-1 depend-on: - publish_to_local_registry - identifier: schema_auth_7 @@ -402,7 +419,7 @@ batch: compute-type: BUILD_GENERAL1_SMALL variables: TEST_SUITE: src/__tests__/schema-auth-7.test.ts - CLI_REGION: us-west-2 + CLI_REGION: ap-northeast-1 depend-on: - publish_to_local_registry - identifier: schema_auth_9 @@ -411,7 +428,7 @@ batch: compute-type: BUILD_GENERAL1_SMALL variables: TEST_SUITE: src/__tests__/schema-auth-9.test.ts - CLI_REGION: eu-west-2 + CLI_REGION: ap-southeast-1 depend-on: - publish_to_local_registry - identifier: schema_auth_5 @@ -420,7 +437,7 @@ batch: compute-type: BUILD_GENERAL1_SMALL variables: TEST_SUITE: src/__tests__/schema-auth-5.test.ts - CLI_REGION: ap-northeast-1 + CLI_REGION: us-east-1 depend-on: - publish_to_local_registry - identifier: searchable_datastore @@ -429,7 +446,7 @@ batch: compute-type: BUILD_GENERAL1_SMALL variables: TEST_SUITE: src/__tests__/graphql-v2/searchable-datastore.test.ts - CLI_REGION: ap-southeast-1 + CLI_REGION: us-east-2 USE_PARENT_ACCOUNT: 1 depend-on: - publish_to_local_registry @@ -439,7 +456,7 @@ batch: compute-type: BUILD_GENERAL1_SMALL variables: TEST_SUITE: src/__tests__/schema-iterative-update-4.test.ts - CLI_REGION: ap-southeast-2 + CLI_REGION: us-west-2 depend-on: - publish_to_local_registry - identifier: schema_searchable @@ -448,7 +465,7 @@ batch: compute-type: BUILD_GENERAL1_SMALL variables: TEST_SUITE: src/__tests__/schema-searchable.test.ts - CLI_REGION: us-east-1 + CLI_REGION: eu-west-2 USE_PARENT_ACCOUNT: 1 depend-on: - publish_to_local_registry @@ -458,7 +475,7 @@ batch: compute-type: BUILD_GENERAL1_SMALL variables: TEST_SUITE: src/__tests__/schema-auth-6.test.ts - CLI_REGION: us-east-2 + CLI_REGION: eu-central-1 depend-on: - publish_to_local_registry - identifier: schema_connection @@ -467,7 +484,7 @@ batch: compute-type: BUILD_GENERAL1_SMALL variables: TEST_SUITE: src/__tests__/schema-connection.test.ts - CLI_REGION: us-west-2 + CLI_REGION: ap-northeast-1 depend-on: - publish_to_local_registry - identifier: searchable_previous_deployment_had_node_to_node @@ -477,7 +494,7 @@ batch: variables: TEST_SUITE: >- src/__tests__/graphql-v2/searchable-node-to-node-encryption/searchable-previous-deployment-had-node-to-node.test.ts - CLI_REGION: eu-west-2 + CLI_REGION: ap-southeast-1 depend-on: - publish_to_local_registry - identifier: searchable_previous_deployment_no_node_to_node @@ -487,7 +504,7 @@ batch: variables: TEST_SUITE: >- src/__tests__/graphql-v2/searchable-node-to-node-encryption/searchable-previous-deployment-no-node-to-node.test.ts - CLI_REGION: eu-central-1 + CLI_REGION: ap-southeast-2 depend-on: - publish_to_local_registry - identifier: api_2 @@ -496,7 +513,7 @@ batch: compute-type: BUILD_GENERAL1_SMALL variables: TEST_SUITE: src/__tests__/api_2.test.ts - CLI_REGION: ap-southeast-1 + CLI_REGION: us-east-1 depend-on: - publish_to_local_registry - identifier: searchable_migration @@ -505,7 +522,7 @@ batch: compute-type: BUILD_GENERAL1_SMALL variables: TEST_SUITE: src/__tests__/transformer-migrations/searchable-migration.test.ts - CLI_REGION: ap-southeast-2 + CLI_REGION: us-east-2 USE_PARENT_ACCOUNT: 1 depend-on: - publish_to_local_registry diff --git a/codebuild_specs/graphql_e2e_tests.yml b/codebuild_specs/graphql_e2e_tests.yml index ce9214cbbc..43e1f7b873 100644 --- a/codebuild_specs/graphql_e2e_tests.yml +++ b/codebuild_specs/graphql_e2e_tests.yml @@ -11,6 +11,7 @@ env: phases: build: commands: + - codebuild-breakpoint - source ./shared-scripts.sh && _runGqlE2ETests post_build: commands: diff --git a/codebuild_specs/migration_tests_v10.yml b/codebuild_specs/migration_tests_v10.yml index 9ce87a4e6c..16fa08d03c 100644 --- a/codebuild_specs/migration_tests_v10.yml +++ b/codebuild_specs/migration_tests_v10.yml @@ -13,6 +13,7 @@ env: phases: build: commands: + - codebuild-breakpoint - source ./shared-scripts.sh && _runMigrationV10Test post_build: commands: @@ -21,5 +22,5 @@ phases: artifacts: files: - - $CODEBUILD_SRC_DIR/packages/amplify-migration-tests/amplify-migration-reports/* - discard-paths: yes + - '**/*' + base-directory: $CODEBUILD_SRC_DIR/packages/amplify-migration-tests/amplify-migration-reports diff --git a/codebuild_specs/migration_tests_v5.yml b/codebuild_specs/migration_tests_v5.yml index 5bfd9a27c3..80c90bee3c 100644 --- a/codebuild_specs/migration_tests_v5.yml +++ b/codebuild_specs/migration_tests_v5.yml @@ -13,6 +13,7 @@ env: phases: build: commands: + - codebuild-breakpoint - source ./shared-scripts.sh && _runMigrationV5Test post_build: commands: @@ -21,5 +22,5 @@ phases: artifacts: files: - - $CODEBUILD_SRC_DIR/packages/amplify-migration-tests/amplify-migration-reports/* - discard-paths: yes + - '**/*' + base-directory: $CODEBUILD_SRC_DIR/packages/amplify-migration-tests/amplify-migration-reports diff --git a/codebuild_specs/migration_tests_v6.yml b/codebuild_specs/migration_tests_v6.yml index e0afaa41c9..f56da76b5c 100644 --- a/codebuild_specs/migration_tests_v6.yml +++ b/codebuild_specs/migration_tests_v6.yml @@ -13,6 +13,7 @@ env: phases: build: commands: + - codebuild-breakpoint - source ./shared-scripts.sh && _runMigrationV6Test post_build: commands: @@ -21,5 +22,5 @@ phases: artifacts: files: - - $CODEBUILD_SRC_DIR/packages/amplify-migration-tests/amplify-migration-reports/* - discard-paths: yes + - '**/*' + base-directory: $CODEBUILD_SRC_DIR/packages/amplify-migration-tests/amplify-migration-reports diff --git a/codebuild_specs/run_e2e_tests.yml b/codebuild_specs/run_e2e_tests.yml index ad19cc435b..413ebbc0ba 100644 --- a/codebuild_specs/run_e2e_tests.yml +++ b/codebuild_specs/run_e2e_tests.yml @@ -7,13 +7,11 @@ env: CI: true CODEBUILD: true NODE_OPTIONS: --max-old-space-size=8096 - # mock values to test artifact scanning - ENV_VAR_WITH_SECRETS: 'MOCK_ENV_VAR_FOR_SCANNING_SECRETS' - MOCK_ENV_VAR_FOR_SCANNING_SECRETS: 'abc123xyz' phases: build: commands: - # you can provide a codebuild source version to use old cache and skip all other jobs :) + - codebuild-breakpoint + - source ./shared-scripts.sh && _setupE2ETestsLinux - source ./shared-scripts.sh && _runE2ETestsLinux post_build: commands: @@ -22,5 +20,5 @@ phases: artifacts: files: - - $CODEBUILD_SRC_DIR/packages/amplify-e2e-tests/amplify-e2e-reports/* - discard-paths: yes + - '**/*' + base-directory: $CODEBUILD_SRC_DIR/packages/amplify-e2e-tests/amplify-e2e-reports diff --git a/package.json b/package.json index 105b0fa900..5f2a5a80d7 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,6 @@ "view-test-artifacts": "yarn authenticate-e2e-profile && yarn ts-node --project ./scripts/tsconfig.json ./scripts/view-test-artifacts.ts", "cleanup-stale-resources": "source ./scripts/cloud-utils.sh && cleanupStaleResources", "depcheck": "eslint --no-eslintrc --config depcheck.config.js", - "generate-debug-e2e-spec": "./scripts/generate-debug-spec-for-failed-e2e-tests.sh", "cloud-e2e-debug": "source scripts/cloud-utils.sh && cloudE2EDebug", "authenticate-e2e-profile": "source scripts/cloud-utils.sh && authenticateWithE2EProfile" }, diff --git a/packages/amplify-category-api/CHANGELOG.md b/packages/amplify-category-api/CHANGELOG.md index a6ee0d20eb..eede24a958 100644 --- a/packages/amplify-category-api/CHANGELOG.md +++ b/packages/amplify-category-api/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [5.5.3](https://github.com/aws-amplify/amplify-category-api/compare/@aws-amplify/amplify-category-api@5.5.2...@aws-amplify/amplify-category-api@5.5.3) (2023-08-07) + +**Note:** Version bump only for package @aws-amplify/amplify-category-api + ## [5.5.2](https://github.com/aws-amplify/amplify-category-api/compare/@aws-amplify/amplify-category-api@5.5.1...@aws-amplify/amplify-category-api@5.5.2) (2023-07-31) ### Bug Fixes diff --git a/packages/amplify-category-api/package.json b/packages/amplify-category-api/package.json index 94a833d222..5bdc0515de 100644 --- a/packages/amplify-category-api/package.json +++ b/packages/amplify-category-api/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/amplify-category-api", - "version": "5.5.2", + "version": "5.5.3", "description": "Amplify CLI API Category Plugin", "repository": { "type": "git", diff --git a/packages/amplify-e2e-core/CHANGELOG.md b/packages/amplify-e2e-core/CHANGELOG.md index 6e51b4250e..0578f7b887 100644 --- a/packages/amplify-e2e-core/CHANGELOG.md +++ b/packages/amplify-e2e-core/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.2.1](https://github.com/aws-amplify/amplify-category-api/compare/amplify-category-api-e2e-core@4.2.0...amplify-category-api-e2e-core@4.2.1) (2023-08-07) + +**Note:** Version bump only for package amplify-category-api-e2e-core + # [4.2.0](https://github.com/aws-amplify/amplify-category-api/compare/amplify-category-api-e2e-core@4.1.10...amplify-category-api-e2e-core@4.2.0) (2023-07-21) ### Features diff --git a/packages/amplify-e2e-core/package.json b/packages/amplify-e2e-core/package.json index 40a6900e80..1dfef31838 100644 --- a/packages/amplify-e2e-core/package.json +++ b/packages/amplify-e2e-core/package.json @@ -1,6 +1,6 @@ { "name": "amplify-category-api-e2e-core", - "version": "4.2.0", + "version": "4.2.1", "description": "Core testing library", "repository": { "type": "git", diff --git a/packages/amplify-e2e-core/src/categories/auth.ts b/packages/amplify-e2e-core/src/categories/auth.ts index fe4bd45f53..fc058f5947 100644 --- a/packages/amplify-e2e-core/src/categories/auth.ts +++ b/packages/amplify-e2e-core/src/categories/auth.ts @@ -127,7 +127,7 @@ interface AddApiOptions { const defaultOptions: AddApiOptions = { apiName: '\r', - testingWithLatestCodebase: true, + testingWithLatestCodebase: false, transformerVersion: 2, }; diff --git a/packages/amplify-e2e-core/src/init/amplifyPush.ts b/packages/amplify-e2e-core/src/init/amplifyPush.ts index c2d9a85872..974ac1678b 100644 --- a/packages/amplify-e2e-core/src/init/amplifyPush.ts +++ b/packages/amplify-e2e-core/src/init/amplifyPush.ts @@ -141,12 +141,19 @@ export function cancelIterativeAmplifyPush( .wait(`Deploying iterative update ${idx.current} of ${idx.max} into`) .wait(/.*AWS::AppSync::GraphQLSchema.*UPDATE_IN_PROGRESS.*/) .sendCtrlC() - .run((err: Error) => { - if (err && !/Process exited with non zero exit code 130/.test(err.message)) { - reject(err); - } else { - resolve(); + .run((err: Error, signal) => { + if (err) { + if (process.env.CODEBUILD) { + // In codebuild the code 130 is not sent but with exit code 2 + // This is to catch the error in that scenario so that the test will proceed + if (!/Killed the process as no output receive/.test(err.message)) { + reject(err); + } + } else if (!/Process exited with non zero exit code 130/.test(err.message)) { + reject(err); + } } + resolve(); }); }); } diff --git a/packages/amplify-e2e-core/src/nexpect-reporter.js b/packages/amplify-e2e-core/src/nexpect-reporter.js index 748ebdc6f9..1b47d6a149 100644 --- a/packages/amplify-e2e-core/src/nexpect-reporter.js +++ b/packages/amplify-e2e-core/src/nexpect-reporter.js @@ -61,8 +61,10 @@ class AmplifyCLIExecutionReporter { onRunComplete(contexts, results) { const { publicPath = process.cwd(), filename = 'jest_html_reporters.html', logoImgPath } = this._options; + const runIdx = process.env['RUN_INDEX'] ?? '0'; const logoImg = logoImgPath ? imgToBase64(logoImgPath) : undefined; - fs.ensureDirSync(publicPath); + const reportPath = path.join(publicPath, runIdx); + fs.ensureDirSync(reportPath); const processedResults = results.testResults.map((result) => { // result is Array of TestResult: https://github.com/facebook/jest/blob/ac57282299c383320845fb9a026719de7ed3ee5e/packages/jest-test-result/src/types.ts#L90 @@ -89,7 +91,7 @@ class AmplifyCLIExecutionReporter { suffix = suffix.substring(0, 30); } const castFile = `${new Date().getTime()}_${index}_${suffix}.cast`; - const castFilePath = path.join(publicPath, castFile); + const castFilePath = path.join(reportPath, castFile); fs.writeFileSync(castFilePath, r.recording); const rCopy = { ...r }; delete rCopy.recording; @@ -114,7 +116,7 @@ class AmplifyCLIExecutionReporter { resultsWithRecordings._reporterOptions = { ...this._options, logoImg, customInfos: {} }; const data = JSON.stringify(resultsWithRecordings); - const filePath = path.resolve(publicPath, filename); + const filePath = path.resolve(reportPath, filename); // const filePathMock = path.resolve(publicPath, `devMock.json`); // fs.writeFileSync(filePathMock, data); const htmlTemplate = fs.readFileSync(localTemplatePath, 'utf-8'); diff --git a/packages/amplify-e2e-tests/CHANGELOG.md b/packages/amplify-e2e-tests/CHANGELOG.md index e4c1c95208..d34933110c 100644 --- a/packages/amplify-e2e-tests/CHANGELOG.md +++ b/packages/amplify-e2e-tests/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [3.13.1](https://github.com/aws-amplify/amplify-category-api/compare/amplify-category-api-e2e-tests@3.13.0...amplify-category-api-e2e-tests@3.13.1) (2023-08-07) + +**Note:** Version bump only for package amplify-category-api-e2e-tests + # [3.13.0](https://github.com/aws-amplify/amplify-category-api/compare/amplify-category-api-e2e-tests@3.12.10...amplify-category-api-e2e-tests@3.13.0) (2023-07-21) ### Features diff --git a/packages/amplify-e2e-tests/package.json b/packages/amplify-e2e-tests/package.json index 94c05688c3..52d5722b1c 100644 --- a/packages/amplify-e2e-tests/package.json +++ b/packages/amplify-e2e-tests/package.json @@ -1,6 +1,6 @@ { "name": "amplify-category-api-e2e-tests", - "version": "3.13.0", + "version": "3.13.1", "description": "E2e test suite", "repository": { "type": "git", @@ -26,7 +26,7 @@ "dependencies": { "@aws-amplify/amplify-app": "^5.0.4", "@aws-amplify/graphql-transformer-core": "1.4.0", - "amplify-category-api-e2e-core": "4.2.0", + "amplify-category-api-e2e-core": "4.2.1", "aws-amplify": "^4.2.8", "aws-appsync": "^4.1.1", "aws-sdk": "^2.1113.0", diff --git a/packages/amplify-e2e-tests/src/__tests__/api_11.test.ts b/packages/amplify-e2e-tests/src/__tests__/api_11.test.ts new file mode 100644 index 0000000000..42a35ecae3 --- /dev/null +++ b/packages/amplify-e2e-tests/src/__tests__/api_11.test.ts @@ -0,0 +1,78 @@ +/* eslint-disable */ +import { + addApiWithBlankSchemaAndConflictDetection, + amplifyPush, + createNewProjectDir, + deleteProject, + deleteProjectDir, + getAppSyncApi, + getProjectMeta, + getTransformConfig, + initJSProjectWithProfile, + updateApiSchema, + amplifyPushUpdate, + apiDisableDataStore, +} from 'amplify-category-api-e2e-core'; +import { existsSync } from 'fs'; +import { TRANSFORM_CURRENT_VERSION } from 'graphql-transformer-core'; +import _ from 'lodash'; +import * as path from 'path'; + +const providerName = 'awscloudformation'; + +// to deal with bug in cognito-identity-js +(global as any).fetch = require('node-fetch'); +// to deal with subscriptions in node env +(global as any).WebSocket = require('ws'); + +describe('amplify add api (GraphQL)', () => { + let projRoot: string; + beforeEach(async () => { + projRoot = await createNewProjectDir('graphql-api'); + }); + + afterEach(async () => { + const metaFilePath = path.join(projRoot, 'amplify', '#current-cloud-backend', 'amplify-meta.json'); + if (existsSync(metaFilePath)) { + await deleteProject(projRoot); + } + deleteProjectDir(projRoot); + }); + + it('init a project with conflict detection enabled and toggle disable', async () => { + const name = 'conflictdetection'; + await initJSProjectWithProfile(projRoot, { name }); + await addApiWithBlankSchemaAndConflictDetection(projRoot, { transformerVersion: 1 }); + await updateApiSchema(projRoot, name, 'simple_model.graphql'); + + await amplifyPush(projRoot); + + const meta = getProjectMeta(projRoot); + const { output } = meta.api[name]; + const { GraphQLAPIIdOutput, GraphQLAPIEndpointOutput, GraphQLAPIKeyOutput } = output; + const { graphqlApi } = await getAppSyncApi(GraphQLAPIIdOutput, meta.providers.awscloudformation.Region); + + expect(GraphQLAPIIdOutput).toBeDefined(); + expect(GraphQLAPIEndpointOutput).toBeDefined(); + expect(GraphQLAPIKeyOutput).toBeDefined(); + + expect(graphqlApi).toBeDefined(); + expect(graphqlApi.apiId).toEqual(GraphQLAPIIdOutput); + + const transformConfig = getTransformConfig(projRoot, name); + expect(transformConfig).toBeDefined(); + expect(transformConfig.Version).toBeDefined(); + expect(transformConfig.Version).toEqual(TRANSFORM_CURRENT_VERSION); + expect(transformConfig.ResolverConfig).toBeDefined(); + expect(transformConfig.ResolverConfig.project).toBeDefined(); + expect(transformConfig.ResolverConfig.project.ConflictDetection).toEqual('VERSION'); + expect(transformConfig.ResolverConfig.project.ConflictHandler).toEqual('AUTOMERGE'); + + // remove datastore feature + await apiDisableDataStore(projRoot, {}); + await amplifyPushUpdate(projRoot); + const disableDSConfig = getTransformConfig(projRoot, name); + expect(disableDSConfig).toBeDefined(); + expect(_.isEmpty(disableDSConfig.ResolverConfig)).toBe(true); + }); +}); diff --git a/packages/amplify-e2e-tests/src/__tests__/api_2.test.ts b/packages/amplify-e2e-tests/src/__tests__/api_2.test.ts index 8294c73589..6a5a7fabe8 100644 --- a/packages/amplify-e2e-tests/src/__tests__/api_2.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/api_2.test.ts @@ -2,8 +2,6 @@ import { addApiWithBlankSchemaAndConflictDetection, amplifyPush, - amplifyPushUpdate, - apiDisableDataStore, createNewProjectDir, deleteProject, deleteProjectDir, @@ -129,43 +127,6 @@ describe('amplify add api (GraphQL)', () => { expect(updateResultData.updateNote.note).toEqual(updateInput.input.note); }); - it('init a project with conflict detection enabled and toggle disable', async () => { - const name = 'conflictdetection'; - await initJSProjectWithProfile(projRoot, { name }); - await addApiWithBlankSchemaAndConflictDetection(projRoot, { transformerVersion: 1 }); - await updateApiSchema(projRoot, name, 'simple_model.graphql'); - - await amplifyPush(projRoot); - - const meta = getProjectMeta(projRoot); - const { output } = meta.api[name]; - const { GraphQLAPIIdOutput, GraphQLAPIEndpointOutput, GraphQLAPIKeyOutput } = output; - const { graphqlApi } = await getAppSyncApi(GraphQLAPIIdOutput, meta.providers.awscloudformation.Region); - - expect(GraphQLAPIIdOutput).toBeDefined(); - expect(GraphQLAPIEndpointOutput).toBeDefined(); - expect(GraphQLAPIKeyOutput).toBeDefined(); - - expect(graphqlApi).toBeDefined(); - expect(graphqlApi.apiId).toEqual(GraphQLAPIIdOutput); - - const transformConfig = getTransformConfig(projRoot, name); - expect(transformConfig).toBeDefined(); - expect(transformConfig.Version).toBeDefined(); - expect(transformConfig.Version).toEqual(TRANSFORM_CURRENT_VERSION); - expect(transformConfig.ResolverConfig).toBeDefined(); - expect(transformConfig.ResolverConfig.project).toBeDefined(); - expect(transformConfig.ResolverConfig.project.ConflictDetection).toEqual('VERSION'); - expect(transformConfig.ResolverConfig.project.ConflictHandler).toEqual('AUTOMERGE'); - - // remove datastore feature - await apiDisableDataStore(projRoot, {}); - await amplifyPushUpdate(projRoot); - const disableDSConfig = getTransformConfig(projRoot, name); - expect(disableDSConfig).toBeDefined(); - expect(_.isEmpty(disableDSConfig.ResolverConfig)).toBe(true); - }); - it('init a project with conflict detection enabled and admin UI enabled to generate datastore models in the cloud', async () => { const name = 'dsadminui'; await initJSProjectWithProfile(projRoot, { disableAmplifyAppCreation: false, name }); diff --git a/packages/amplify-e2e-tests/src/__tests__/auth_2.test.ts b/packages/amplify-e2e-tests/src/__tests__/auth_2.test.ts index dca8ca776e..e1e66dbbd4 100644 --- a/packages/amplify-e2e-tests/src/__tests__/auth_2.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/auth_2.test.ts @@ -18,11 +18,7 @@ const defaultsSettings = { name: 'authTest', }; -describe('placeholder', () => { - it('should execute a no-op test', () => {}); -}); - -describe.skip('amplify add auth...', () => { +describe('amplify add auth...', () => { let projRoot: string; beforeEach(async () => { projRoot = await createNewProjectDir('auth'); diff --git a/packages/amplify-e2e-tests/src/__tests__/schema-auth-10.test.ts b/packages/amplify-e2e-tests/src/__tests__/schema-auth-10.test.ts index 658d55114f..feeee088e4 100644 --- a/packages/amplify-e2e-tests/src/__tests__/schema-auth-10.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/schema-auth-10.test.ts @@ -5,7 +5,7 @@ describe('api directives @auth batch 8', () => { let projectDir: string; beforeEach(async () => { - projectDir = await createNewProjectDir('auth8'); + projectDir = await createNewProjectDir('auth10'); await initJSProjectWithProfile(projectDir, {}); }); diff --git a/packages/amplify-e2e-tests/src/__tests__/schema-auth-11.test.ts b/packages/amplify-e2e-tests/src/__tests__/schema-auth-11.test.ts index 84e4a9ee50..4bef9d9c97 100644 --- a/packages/amplify-e2e-tests/src/__tests__/schema-auth-11.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/schema-auth-11.test.ts @@ -5,7 +5,7 @@ describe('api directives @auth batch 3', () => { let projectDir: string; beforeEach(async () => { - projectDir = await createNewProjectDir('auth3'); + projectDir = await createNewProjectDir('auth11'); await initJSProjectWithProfile(projectDir, {}); }); diff --git a/packages/amplify-e2e-tests/src/__tests__/schema-auth-12.test.ts b/packages/amplify-e2e-tests/src/__tests__/schema-auth-12.test.ts index 6ad1885dbe..9c98b9a76c 100644 --- a/packages/amplify-e2e-tests/src/__tests__/schema-auth-12.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/schema-auth-12.test.ts @@ -5,7 +5,7 @@ describe('api directives @auth batch 2', () => { let projectDir: string; beforeEach(async () => { - projectDir = await createNewProjectDir('auth2'); + projectDir = await createNewProjectDir('auth12'); await initJSProjectWithProfile(projectDir, {}); }); diff --git a/packages/amplify-e2e-tests/src/__tests__/schema-auth-13.test.ts b/packages/amplify-e2e-tests/src/__tests__/schema-auth-13.test.ts index ba5c14508b..6fe75fcc27 100644 --- a/packages/amplify-e2e-tests/src/__tests__/schema-auth-13.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/schema-auth-13.test.ts @@ -5,7 +5,7 @@ describe('api directives @auth batch 1', () => { let projectDir: string; beforeEach(async () => { - projectDir = await createNewProjectDir('auth1'); + projectDir = await createNewProjectDir('auth13'); await initJSProjectWithProfile(projectDir, {}); }); diff --git a/packages/amplify-e2e-tests/src/__tests__/schema-auth-14.test.ts b/packages/amplify-e2e-tests/src/__tests__/schema-auth-14.test.ts index 8771988d01..05ee4d7c2f 100644 --- a/packages/amplify-e2e-tests/src/__tests__/schema-auth-14.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/schema-auth-14.test.ts @@ -18,7 +18,7 @@ describe('api directives @auth batch 14', () => { describe('javascript libraries', () => { beforeEach(async () => { - projectDir = await createNewProjectDir('auth1'); + projectDir = await createNewProjectDir('auth14'); await initJSProjectWithProfile(projectDir, {}); addFeatureFlag(projectDir, 'graphqlTransformer', 'useSubUsernameForDefaultIdentityClaim', true); }); diff --git a/packages/amplify-e2e-tests/src/__tests__/schema-auth-15.test.ts b/packages/amplify-e2e-tests/src/__tests__/schema-auth-15.test.ts index 2a5231fbb8..f8e40b43ee 100644 --- a/packages/amplify-e2e-tests/src/__tests__/schema-auth-15.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/schema-auth-15.test.ts @@ -18,7 +18,7 @@ describe('api directives @auth batch 15', () => { describe('ios libraries', () => { beforeEach(async () => { - projectDir = await createNewProjectDir('auth1'); + projectDir = await createNewProjectDir('auth15'); await initIosProjectWithProfile(projectDir, {}); addFeatureFlag(projectDir, 'graphqlTransformer', 'useSubUsernameForDefaultIdentityClaim', true); }); diff --git a/packages/amplify-e2e-tests/src/__tests__/schema-auth-8.test.ts b/packages/amplify-e2e-tests/src/__tests__/schema-auth-8.test.ts index 2a2825e6c7..b3b62b049b 100644 --- a/packages/amplify-e2e-tests/src/__tests__/schema-auth-8.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/schema-auth-8.test.ts @@ -5,7 +5,7 @@ describe('api directives @auth batch 7', () => { let projectDir: string; beforeEach(async () => { - projectDir = await createNewProjectDir('auth7'); + projectDir = await createNewProjectDir('auth8'); await initJSProjectWithProfile(projectDir, {}); }); diff --git a/packages/amplify-e2e-tests/src/__tests__/schema-auth-9.test.ts b/packages/amplify-e2e-tests/src/__tests__/schema-auth-9.test.ts index f461a3ec69..536c926879 100644 --- a/packages/amplify-e2e-tests/src/__tests__/schema-auth-9.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/schema-auth-9.test.ts @@ -5,7 +5,7 @@ describe('api directives @auth batch 8', () => { let projectDir: string; beforeEach(async () => { - projectDir = await createNewProjectDir('auth8'); + projectDir = await createNewProjectDir('auth9'); await initJSProjectWithProfile(projectDir, {}); }); diff --git a/packages/amplify-e2e-tests/src/cleanup-e2e-resources.ts b/packages/amplify-e2e-tests/src/cleanup-e2e-resources.ts index 469a2905b7..d17253c87c 100644 --- a/packages/amplify-e2e-tests/src/cleanup-e2e-resources.ts +++ b/packages/amplify-e2e-tests/src/cleanup-e2e-resources.ts @@ -20,7 +20,7 @@ const AWS_REGIONS_TO_RUN_TESTS = [ 'ap-southeast-2', ]; -const reportPath = path.normalize(path.join(__dirname, '..', 'amplify-e2e-reports', 'stale-resources.json')); +const reportPathDir = path.normalize(path.join(__dirname, '..', 'amplify-e2e-reports')); const MULTI_JOB_APP = ''; const ORPHAN = ''; @@ -532,7 +532,8 @@ const deleteCfnStack = async (account: AWSAccountInfo, accountIndex: number, sta } }; -const generateReport = (jobs: _.Dictionary): void => { +const generateReport = (jobs: _.Dictionary, accountIdx: number): void => { + const reportPath = path.join(reportPathDir, `stale-resources-${accountIdx}.json`); fs.ensureFileSync(reportPath); fs.writeFileSync(reportPath, JSON.stringify(jobs, null, 4)); }; @@ -676,7 +677,7 @@ const cleanupAccount = async (account: AWSAccountInfo, accountIndex: number, fil const allResources = await mergeResourcesByCCIJob(apps, stacks, buckets, orphanBuckets, orphanIamRoles); const staleResources = _.pickBy(allResources, filterPredicate); - generateReport(staleResources); + generateReport(staleResources, accountIndex); await deleteResources(account, accountIndex, staleResources); console.log(`${generateAccountInfo(account, accountIndex)} Cleanup done!`); }; diff --git a/packages/amplify-migration-tests/CHANGELOG.md b/packages/amplify-migration-tests/CHANGELOG.md index 9dca084e88..f8f2d30f1b 100644 --- a/packages/amplify-migration-tests/CHANGELOG.md +++ b/packages/amplify-migration-tests/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [5.0.32](https://github.com/aws-amplify/amplify-category-api/compare/amplify-category-api-migration-tests@5.0.31...amplify-category-api-migration-tests@5.0.32) (2023-08-07) + +**Note:** Version bump only for package amplify-category-api-migration-tests + ## [5.0.31](https://github.com/aws-amplify/amplify-category-api/compare/amplify-category-api-migration-tests@5.0.30...amplify-category-api-migration-tests@5.0.31) (2023-07-21) **Note:** Version bump only for package amplify-category-api-migration-tests diff --git a/packages/amplify-migration-tests/package.json b/packages/amplify-migration-tests/package.json index 347d8d9924..7e72c0971b 100644 --- a/packages/amplify-migration-tests/package.json +++ b/packages/amplify-migration-tests/package.json @@ -1,6 +1,6 @@ { "name": "amplify-category-api-migration-tests", - "version": "5.0.31", + "version": "5.0.32", "description": "Test suites for migration scenarios", "repository": { "type": "git", @@ -26,7 +26,7 @@ "dependencies": { "@aws-amplify/amplify-cli-core": "4.2.0-aws-cdk-lib-2-28.0", "@aws-cdk/cloudformation-diff": "~2.80.0", - "amplify-category-api-e2e-core": "4.2.0", + "amplify-category-api-e2e-core": "4.2.1", "aws-cdk-lib": "~2.80.0", "fs-extra": "^8.1.0", "graphql-transformer-core": "8.1.9", diff --git a/scripts/cloud-release.sh b/scripts/cloud-release.sh index 76fd4c8839..a39bdeb1b9 100644 --- a/scripts/cloud-release.sh +++ b/scripts/cloud-release.sh @@ -5,7 +5,6 @@ export RELEASE_PROFILE_NAME=AmplifyAPIPluginRelease export RELEASE_PROJECT_NAME=amplify-category-api-release-workflow function triggerRelease { - echo "Running release workflow from branch ${branch_name}" triggerProjectBatch $RELEASE_ACCOUNT_PROD $RELEASE_ROLE_NAME "${RELEASE_PROFILE_NAME}Prod" $RELEASE_PROJECT_NAME "release" } diff --git a/scripts/cloud-utils.sh b/scripts/cloud-utils.sh index 48b59d1899..a81e53b38a 100755 --- a/scripts/cloud-utils.sh +++ b/scripts/cloud-utils.sh @@ -44,9 +44,10 @@ function triggerProjectBatchWithDebugSession { echo AWS Account: $account_number echo Project: $project_name echo Target Branch: $target_branch + debug_spec=$(cat codebuild_specs/debug_workflow.yml) RESULT=$(aws codebuild start-build-batch --region=$REGION --profile="${profile_name}" --project-name $project_name --source-version=$target_branch \ --debug-session-enabled \ - --buildspec-override "codebuild_specs/debug_workflow.yml" \ + --buildspec-override "$debug_spec" \ --environment-variables-override name=BRANCH_NAME,value=$target_branch,type=PLAINTEXT \ --query 'buildBatch.id' --output text) echo "https://$REGION.console.aws.amazon.com/codesuite/codebuild/$account_number/projects/$project_name/batch/$RESULT?region=$REGION" @@ -87,6 +88,16 @@ function cloudE2E { } function cloudE2EDebug { + if [ $# -eq 0 ]; then + echo "Please provide the batch build id of codebuild" + exit 1 + fi + if [ "$1" == "--use-existing-debug-spec" ]; then + echo "Using existing debug spec" + else + echo "Generating debug spec for provided batch build id" + generatedDebugSpecForFailedTests $1 + fi echo Running Prod E2E Test Suite E2E_ROLE_NAME=CodebuildDeveloper E2E_PROFILE_NAME=AmplifyAPIE2EProd @@ -95,22 +106,37 @@ function cloudE2EDebug { triggerProjectBatchWithDebugSession $E2E_ACCOUNT_PROD $E2E_ROLE_NAME $E2E_PROFILE_NAME $E2E_PROJECT_NAME $TARGET_BRANCH } +function generatedDebugSpecForFailedTests { + # Get temporary access for the account + E2E_ROLE_NAME=CodebuildDeveloper + E2E_PROFILE_NAME=AmplifyAPIE2EProd + authenticate $E2E_ACCOUNT_PROD $E2E_ROLE_NAME "$E2E_PROFILE_NAME" + local batch_build_id=$1 + echo "Getting failed test suites" + failed_tests=$(aws codebuild batch-get-build-batches --profile="$E2E_PROFILE_NAME" --ids "$batch_build_id" --region us-east-1 --query 'buildBatches[0].buildGroups' | jq -c '.[] | select(.currentBuildSummary.buildStatus == "FAILED").identifier') + if [ -z "$failed_tests" ]; then + echo "No failed tests found in batch $1" + exit 0 + fi + echo $failed_tests | xargs yarn ts-node ./scripts/split-e2e-tests.ts --debug +} + function cleanupStaleResourcesBeta { - echo Running Beta E2E resource stale resource cleanup - CLEANUP_ROLE_NAME=CodebuildDeveloper - CLEANUP_PROFILE_NAME=AmplifyAPIE2EBeta - CLEANUP_PROJECT_NAME=amplify-category-api-cleanup-workflow - TARGET_BRANCH=$CURR_BRANCH - triggerProject $E2E_ACCOUNT_BETA $CLEANUP_ROLE_NAME $CLEANUP_PROFILE_NAME $CLEANUP_PROJECT_NAME $TARGET_BRANCH + echo Running Beta E2E resource stale resource cleanup + CLEANUP_ROLE_NAME=CodebuildDeveloper + CLEANUP_PROFILE_NAME=AmplifyAPIE2EBeta + CLEANUP_PROJECT_NAME=amplify-category-api-cleanup-workflow + TARGET_BRANCH=$CURR_BRANCH + triggerProject $E2E_ACCOUNT_BETA $CLEANUP_ROLE_NAME $CLEANUP_PROFILE_NAME $CLEANUP_PROJECT_NAME $TARGET_BRANCH } function cleanupStaleResources { - echo Running Prod E2E resource stale resource cleanup - CLEANUP_ROLE_NAME=CodebuildDeveloper - CLEANUP_PROFILE_NAME=AmplifyAPIE2EProd - CLEANUP_PROJECT_NAME=amplify-category-api-cleanup-workflow - TARGET_BRANCH=$CURR_BRANCH - triggerProject $E2E_ACCOUNT_PROD $CLEANUP_ROLE_NAME $CLEANUP_PROFILE_NAME $CLEANUP_PROJECT_NAME $TARGET_BRANCH + echo Running Prod E2E resource stale resource cleanup + CLEANUP_ROLE_NAME=CodebuildDeveloper + CLEANUP_PROFILE_NAME=AmplifyAPIE2EProd + CLEANUP_PROJECT_NAME=amplify-category-api-cleanup-workflow + TARGET_BRANCH=$CURR_BRANCH + triggerProject $E2E_ACCOUNT_PROD $CLEANUP_ROLE_NAME $CLEANUP_PROFILE_NAME $CLEANUP_PROJECT_NAME $TARGET_BRANCH } function authenticateWithE2EProfile { diff --git a/scripts/generate-debug-spec-for-failed-e2e-tests.sh b/scripts/generate-debug-spec-for-failed-e2e-tests.sh deleted file mode 100755 index 640e163824..0000000000 --- a/scripts/generate-debug-spec-for-failed-e2e-tests.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -source ./scripts/cloud-utils.sh - -function generatedDebugSpecForFailedTests { - # Check if an batch build name is provided - if [ $# -eq 0 ]; then - echo "Please provide the batch build id of codebuild" - exit 1 - fi - # Get temporary access for the account - E2E_ROLE_NAME=CodebuildDeveloper - E2E_PROFILE_NAME=AmplifyAPIE2EProd - authenticate $E2E_ACCOUNT_PROD $E2E_ROLE_NAME "$E2E_PROFILE_NAME" - local batch_build_id=$1 - echo "Getting failed test suites" - failed_tests=$(aws codebuild batch-get-build-batches --profile="$E2E_PROFILE_NAME" --ids "$batch_build_id" --region us-east-1 --query 'buildBatches[0].buildGroups' | jq -c '.[] | select(.currentBuildSummary.buildStatus == "FAILED").identifier') - if [ -z "$failed_tests" ]; then - echo "No failed tests found in batch $1" - exit 0 - fi - echo $failed_tests | xargs yarn ts-node ./scripts/split-e2e-tests.ts --debug - echo "" - echo "Next steps:" - echo "- add 'codebuild-breakpoint' to desired location in build specs or shared scripts" - echo "- git commit and push your changes" - echo "- run command 'yarn cloud-e2e-debug'" -} - -generatedDebugSpecForFailedTests "$@" - diff --git a/scripts/split-e2e-tests.ts b/scripts/split-e2e-tests.ts index d48c2e9818..02cc4e6fe2 100644 --- a/scripts/split-e2e-tests.ts +++ b/scripts/split-e2e-tests.ts @@ -40,6 +40,7 @@ const CODEBUILD_DEBUG_CONFIG_PATH = join(REPO_ROOT, 'codebuild_specs', 'debug_wo const RUN_SOLO = [ 'src/__tests__/apigw.test.ts', 'src/__tests__/api_2.test.ts', + 'src/__tests__/api_11.test.ts', 'src/__tests__/containers-api-1.test.ts', 'src/__tests__/containers-api-2.test.ts', 'src/__tests__/graphql-v2/searchable-datastore.test.ts', @@ -64,6 +65,8 @@ const RUN_SOLO = [ 'src/__tests__/schema-auth-13.test.ts', 'src/__tests__/schema-auth-14.test.ts', 'src/__tests__/schema-auth-15.test.ts', + 'src/__tests__/schema-iterative-rollback-1.test.ts', + 'src/__tests__/schema-iterative-rollback-2.test.ts', 'src/__tests__/schema-iterative-update-4.test.ts', 'src/__tests__/schema-iterative-update-5.test.ts', 'src/__tests__/schema-model.test.ts', diff --git a/scripts/view-test-artifacts.sh b/scripts/view-test-artifacts.sh index edcd3ae1d0..642a0d0e6c 100755 --- a/scripts/view-test-artifacts.sh +++ b/scripts/view-test-artifacts.sh @@ -2,34 +2,52 @@ source ./scripts/cloud-utils.sh +# Function to convert S3 ARN to S3 URI +function convertArnToUri { + local arn="$1" + + # Remove "arn:aws:s3:::" from the beginning of the ARN + local stripped_arn="${arn#arn:aws:s3:::}" + + # Extract the bucket name and object key + local bucket_name="${stripped_arn%%/*}" + local object_key="${stripped_arn#*/}" + + # Create the S3 URI + local s3_uri="s3://$bucket_name/$object_key" + + echo "$s3_uri" +} + function downloadS3Artifact { # Get temporary access for the account E2E_ROLE_NAME=CodebuildDeveloper E2E_PROFILE_NAME=AmplifyAPIE2EProd authenticate $E2E_ACCOUNT_PROD $E2E_ROLE_NAME "$E2E_PROFILE_NAME" - - local s3_object_uri=$1 - local destination_dir=$2 - + echo "Fetching artifact location from build" + s3_arn=$(aws codebuild batch-get-builds --profile="$E2E_PROFILE_NAME" --ids "$1" --region us-east-1 --query 'builds[0].artifacts.location') + # Have to remove double quote for arn + s3_object_uri=$(convertArnToUri ${s3_arn//\"/}) + echo $s3_object_uri echo "Downloading objects from S3 bucket..." - aws s3 cp "$s3_object_uri" "$destination_dir" --recursive --profile="$E2E_PROFILE_NAME" - echo "Download complete. Files are saved in: $destination_dir" + aws s3 cp $s3_object_uri $2 --recursive --profile="$E2E_PROFILE_NAME" + echo "Download complete. Files are saved in: $2" } function playTestArtifact { # Check if an S3 object URI is provided if [ $# -eq 0 ]; then - echo "Provide the S3 URI of the artifact: $0 " + echo "Provide the code build id: $0 " exit 1 fi - local s3_object_uri=$1 + local code_build_id=$1 local temp_dir=$(mktemp -d) # Create a temporary directory trap "cleanup $temp_dir" SIGINT SIGTERM # Register cleanup function to handle Ctrl+C echo "Starting test artifact playback..." - downloadS3Artifact "$s3_object_uri" "$temp_dir" + downloadS3Artifact "$code_build_id" "$temp_dir" local subfolders=("$temp_dir"/*/) diff --git a/scripts/view-test-artifacts.ts b/scripts/view-test-artifacts.ts index b1021910af..acfcd2c7e5 100644 --- a/scripts/view-test-artifacts.ts +++ b/scripts/view-test-artifacts.ts @@ -115,7 +115,8 @@ const downloadSingleTestArtifact = async (tempDir: string, artifact: Required { - const filePath = path.join(artifactDownloadPath, Key.split('/').pop()!); + const filePath = path.join(artifactDownloadPath, Key.split('/').slice(3).join('/')); + fs.ensureDirSync(path.dirname(filePath)); return new Promise((resolve, reject) => { const writer = fs.createWriteStream(filePath); s3.getObject({ Bucket, Key }).createReadStream().pipe(writer); diff --git a/shared-scripts.sh b/shared-scripts.sh index 0bc90b83b7..f847a577f0 100755 --- a/shared-scripts.sh +++ b/shared-scripts.sh @@ -195,15 +195,20 @@ function _loadTestAccountCredentials { export AWS_SECRET_ACCESS_KEY=$(echo $creds | jq -c -r ".Credentials.SecretAccessKey") export AWS_SESSION_TOKEN=$(echo $creds | jq -c -r ".Credentials.SessionToken") } -function _runE2ETestsLinux { - echo "RUN E2E Tests Linux" +function _setupE2ETestsLinux { + echo "Setup E2E Tests Linux" loadCacheFromBuildJob loadCache verdaccio-cache $CODEBUILD_SRC_DIR/../verdaccio-cache _installCLIFromLocalRegistry _loadTestAccountCredentials _setShell +} + +function _runE2ETestsLinux { + echo "RUN E2E Tests Linux" retry runE2eTest } + function _runGqlE2ETests { echo "RUN GraphQL E2E tests" loadCacheFromBuildJob @@ -269,7 +274,7 @@ function _cleanupE2EResources { echo "Running clean up script" build_batch_arn=$(aws codebuild batch-get-builds --ids $CODEBUILD_BUILD_ID | jq -r -c '.builds[0].buildBatchArn') echo "Cleanup resources for batch build $build_batch_arn" - yarn clean-e2e-resources --buildBatchArn $build_batch_arn + yarn clean-e2e-resources buildBatchArn $build_batch_arn } # The following functions are forked from circleci local publish helper @@ -307,22 +312,22 @@ function retry { MAX_ATTEMPTS=2 SLEEP_DURATION=5 FIRST_RUN=true - n=0 + RUN_INDEX=0 FAILED_TEST_REGEX_FILE="./amplify-e2e-reports/amplify-e2e-failed-test.txt" if [ -f $FAILED_TEST_REGEX_FILE ]; then rm -f $FAILED_TEST_REGEX_FILE fi - until [ $n -ge $MAX_ATTEMPTS ] + until [ $RUN_INDEX -ge $MAX_ATTEMPTS ] do echo "Attempting $@ with max retries $MAX_ATTEMPTS" setAwsAccountCredentials - "$@" && break - n=$[$n+1] + RUN_INDEX="$RUN_INDEX" "$@" && break + RUN_INDEX=$[$RUN_INDEX+1] FIRST_RUN=false - echo "Attempt $n completed." + echo "Attempt $RUN_INDEX completed." sleep $SLEEP_DURATION done - if [ $n -ge $MAX_ATTEMPTS ]; then + if [ $RUN_INDEX -ge $MAX_ATTEMPTS ]; then echo "failed: ${@}" >&2 exit 1 fi @@ -330,7 +335,7 @@ function retry { resetAwsAccountCredentials TEST_SUITE=${TEST_SUITE:-"TestSuiteNotSet"} aws cloudwatch put-metric-data --metric-name FlakyE2ETests --namespace amplify-category-api-e2e-tests --unit Count --value $n --dimensions testFile=$TEST_SUITE --profile amplify-integ-test-user || true - echo "Attempt $n succeeded." + echo "Attempt $RUN_INDEX succeeded." exit 0 # don't fail the step if putting the metric fails }