diff --git a/packages/amplify-migration-e2e/src/__tests__/migration_codegen_e2e.test.ts b/packages/amplify-migration-e2e/src/__tests__/migration_codegen_e2e.test.ts index 48e2ee0277..bebae7abe7 100644 --- a/packages/amplify-migration-e2e/src/__tests__/migration_codegen_e2e.test.ts +++ b/packages/amplify-migration-e2e/src/__tests__/migration_codegen_e2e.test.ts @@ -1,6 +1,6 @@ import path from 'node:path'; import assert from 'node:assert'; -import { createNewProjectDir, npmInstall } from '@aws-amplify/amplify-e2e-core'; +import { createNewProjectDir, generateRandomShortId, npmInstall } from '@aws-amplify/amplify-e2e-core'; import { createGen2Renderer } from '@aws-amplify/amplify-gen2-codegen'; import { copyFunctionFile } from '../function_utils'; import { copyGen1Schema } from '../api_utils'; @@ -46,7 +46,7 @@ void describe('Codegen E2E tests', () => { beforeEach(async () => { const baseDir = process.env.INIT_CWD ?? process.cwd(); projRoot = await createNewProjectDir('codegen_e2e_flow_test', path.join(baseDir, '..', '..')); - projName = `test${Math.floor(Math.random() * 1000000)}`; + projName = `test${generateRandomShortId()}`; }); afterEach(async () => { @@ -60,10 +60,7 @@ void describe('Codegen E2E tests', () => { await runCodegenCommand(projRoot); await copyFunctionFile(projRoot, 'function', gen1FunctionName); await copyGen1Schema(projRoot, projName); - - // TODO: replace below line with correct package version await updatePackageDependency(projRoot, '@aws-amplify/backend'); - await npmInstall(projRoot); const gen2StackName = await runGen2SandboxCommand(projRoot); await assertAuthResource(projRoot, gen1UserPoolId, gen1ClientIds, gen1IdentityPoolId, gen1Region); @@ -80,10 +77,7 @@ void describe('Codegen E2E tests', () => { await runCodegenCommand(projRoot); await copyFunctionFile(projRoot, 'auth', gen1FunctionName); await removeErrorThrowsFromAuthResourceFile(projRoot); - - // TODO: replace below line with correct package version await updatePackageDependency(projRoot, '@aws-amplify/backend'); - await npmInstall(projRoot); await toggleSandboxSecrets(projRoot, 'set'); const gen2StackName = await runGen2SandboxCommand(projRoot); @@ -98,10 +92,7 @@ void describe('Codegen E2E tests', () => { projRoot, ); await runCodegenCommand(projRoot); - - // TODO: replace below line with correct package version await updatePackageDependency(projRoot, '@aws-amplify/backend'); - await npmInstall(projRoot); await runGen2SandboxCommand(projRoot); await assertAuthResource(projRoot, gen1UserPoolId, gen1ClientIds, gen1IdentityPoolId, gen1Region); diff --git a/packages/amplify-migration-e2e/src/__tests__/migration_templategen_e2e.test.ts b/packages/amplify-migration-e2e/src/__tests__/migration_templategen_e2e.test.ts index 6a9c91eed7..e1b521ed4e 100644 --- a/packages/amplify-migration-e2e/src/__tests__/migration_templategen_e2e.test.ts +++ b/packages/amplify-migration-e2e/src/__tests__/migration_templategen_e2e.test.ts @@ -1,6 +1,6 @@ import path from 'node:path'; import assert from 'node:assert'; -import { createNewProjectDir, npmInstall, deleteS3Bucket } from '@aws-amplify/amplify-e2e-core'; +import { createNewProjectDir, npmInstall, deleteS3Bucket, generateRandomShortId } from '@aws-amplify/amplify-e2e-core'; import { assertDefaultGen1Setup } from '../assertions'; import { setupAndPushDefaultGen1Project, runCodegenCommand, runGen2SandboxCommand, cleanupProjects } from '..'; import { copyFunctionFile } from '../function_utils'; @@ -18,8 +18,8 @@ void describe('Templategen E2E tests', () => { beforeEach(async () => { const baseDir = process.env.INIT_CWD ?? process.cwd(); projRoot = await createNewProjectDir('templategen_e2e_flow_test', path.join(baseDir, '..', '..')); - projName = `test${Math.floor(Math.random() * 1000000)}`; - bucketName = `testbucket${Math.floor(Math.random() * 1000000)}`; + projName = `test${generateRandomShortId()}`; + bucketName = `testbucket${generateRandomShortId()}`; }); afterEach(async () => { @@ -35,10 +35,7 @@ void describe('Templategen E2E tests', () => { await runCodegenCommand(projRoot); await copyFunctionFile(projRoot, 'function', gen1FunctionName); await copyGen1Schema(projRoot, projName); - - // TODO: replace below line with correct package version await updatePackageDependency(projRoot, '@aws-amplify/backend'); - await npmInstall(projRoot); const gen2StackName = await runGen2SandboxCommand(projRoot); assert(gen2StackName); diff --git a/packages/amplify-migration-e2e/src/envVariables.ts b/packages/amplify-migration-e2e/src/envVariables.ts index 64680b1314..f31d295dfa 100644 --- a/packages/amplify-migration-e2e/src/envVariables.ts +++ b/packages/amplify-migration-e2e/src/envVariables.ts @@ -1,9 +1,8 @@ -type EnvVariableAction = 'SET' | 'DELETE'; - -export function toggleEnvVariable(name: string, option: EnvVariableAction, value?: string) { - if (option === 'SET') { +export const envVariable = { + set: (name: string, value: string): void => { process.env[name] = value; - } else if (option === 'DELETE') { + }, + delete: (name: string): void => { delete process.env[name]; - } -} + }, +}; diff --git a/packages/amplify-migration-e2e/src/gen1ResourceDetailsFetcher.ts b/packages/amplify-migration-e2e/src/gen1ResourceDetailsFetcher.ts index 4909918333..bd6e49cd40 100644 --- a/packages/amplify-migration-e2e/src/gen1ResourceDetailsFetcher.ts +++ b/packages/amplify-migration-e2e/src/gen1ResourceDetailsFetcher.ts @@ -11,8 +11,7 @@ async function getGen1AuthResourceDetails(projRoot: string) { const { gen1UserPoolId } = await assertUserPool(gen1Meta, gen1Region); const { gen1IdentityPoolId } = await assertIdentityPool(gen1Meta, gen1Region); const { gen1ClientIds } = await assertUserPoolClients(gen1Meta, gen1Region); - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const [gen1ClientIdWeb, gen1ClientId] = gen1ClientIds; + const gen1ClientIdWeb = gen1ClientIds[0]; const gen1ResourceIds = [gen1UserPoolId, gen1IdentityPoolId, gen1ClientIdWeb]; const gen1ResourceDetails = await Promise.all([ diff --git a/packages/amplify-migration-e2e/src/templategen.ts b/packages/amplify-migration-e2e/src/templategen.ts index 751bbc9626..664e226c34 100644 --- a/packages/amplify-migration-e2e/src/templategen.ts +++ b/packages/amplify-migration-e2e/src/templategen.ts @@ -5,7 +5,7 @@ import * as fs from 'fs-extra'; import { getNpxPath, retry, RetrySettings } from '@aws-amplify/amplify-e2e-core'; import { runGen2SandboxCommand } from './sandbox'; import { getCommandsFromReadme } from './migrationReadmeParser'; -import { toggleEnvVariable } from './envVariables'; +import { envVariable } from './envVariables'; import { getGen1ResourceDetails } from './gen1ResourceDetailsFetcher'; import { getGen2ResourceDetails } from './gen2ResourceDetailsFetcher'; @@ -89,11 +89,11 @@ async function executeStep2(cwd: string, commands: string[]) { } async function executeStep3(cwd: string, commands: string[], bucketName: string) { - toggleEnvVariable('BUCKET_NAME', 'SET', bucketName); + envVariable.set('BUCKET_NAME', bucketName); await executeCommand(commands[1], cwd); await executeCommand(commands[2], cwd); const stackRefactorId = await executeCreateStackRefactorCallCommand(commands[3], cwd); - toggleEnvVariable('STACK_REFACTOR_ID', 'SET', stackRefactorId); + envVariable.set('STACK_REFACTOR_ID', stackRefactorId); await retry( () => assertRefactorStepCompletion(commands[5]), (status) => status.includes(STATUS_COMPLETE) && !status.includes(STATUS_IN_PROGRESS), @@ -107,6 +107,8 @@ async function executeStep3(cwd: string, commands: string[], bucketName: string) RETRY_CONFIG, (status) => status.includes(STATUS_FAILED), ); + envVariable.delete('BUCKET_NAME'); + envVariable.delete('STACK_REFACTOR_ID'); } async function assertStepCompletion(command: string) { @@ -134,9 +136,6 @@ export async function stackRefactor(projRoot: string, category: RefactorCategory await runGen2SandboxCommand(projRoot); - toggleEnvVariable('BUCKET_NAME', 'DELETE'); - toggleEnvVariable('STACK_REFACTOR_ID', 'DELETE'); - const { gen2ResourceIds, gen2ResourceDetails } = await getGen2ResourceDetails(projRoot, category); assert.deepEqual(gen1ResourceIds, gen2ResourceIds); assert.deepEqual(gen1ResourceDetails, gen2ResourceDetails);