-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: basic e2e integration test flow for migration tool #13946
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! leave some minor comments
void it('performs full migration codegen flow with Auth backend', async () => { | ||
await setupGen1Project(projRoot, 'CodegenTest'); | ||
const { gen1UserPoolId, gen1Region } = await assertGen1Setup(projRoot); | ||
await migrateCodegen(projRoot); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls rename migrateCodegen
to generateGen2Code
in the next PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall it's looking good. Please see comments.
@@ -0,0 +1,23 @@ | |||
import path from 'node:path'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we call this file migration_codegen_e2e.test.ts
.
We have tests related other "codegen" in the repo.
} catch (error) { | ||
console.error('Error fetching resource details:', error); | ||
throw error; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove all these catch-log-throw blocks, here and below.
As long as something catches this error at the top and prints it somewhere we can infer details from stack trace.
.runAsync(); | ||
} | ||
|
||
export async function setupGen1Project(projRoot: string, projectName: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export async function setupGen1Project(projRoot: string, projectName: string) { | |
export async function setupAndPushGen1Project(projRoot: string, projectName: string) { |
push is heavy long running operation. please be explicit in function name.
function removeNestedJsonKeys<T extends Record<string, unknown>>(obj: T, keysToRemove: string[]): T { | ||
const result = { ...obj }; | ||
keysToRemove.forEach((path) => { | ||
const parts = path.split('.'); | ||
let current: Record<string, unknown> = result; | ||
for (let i = 0; i < parts.length - 1; i++) { | ||
const part = parts[i]; | ||
if (current[part] === undefined || current[part] === null) { | ||
return; // Path doesn't exist, nothing to delete | ||
} | ||
current = current[part] as Record<string, unknown>; | ||
} | ||
const lastPart = parts[parts.length - 1]; | ||
if (current && lastPart in current) { | ||
delete current[lastPart]; | ||
} | ||
}); | ||
return result; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have lodash in the node_modules.
if we do, consider using https://lodash.com/docs/4.17.15#unset instead.
export async function migrateCodegen(projRoot: string) { | ||
await assert.doesNotReject(runCodegenCommand(projRoot), 'Codegen failed'); | ||
} | ||
|
||
export async function deployGen2Sandbox(projRoot: string) { | ||
await assert.doesNotReject(runGen2SandboxCommand(projRoot), 'Gen2 CDK deployment failed'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export async function migrateCodegen(projRoot: string) { | |
await assert.doesNotReject(runCodegenCommand(projRoot), 'Codegen failed'); | |
} | |
export async function deployGen2Sandbox(projRoot: string) { | |
await assert.doesNotReject(runGen2SandboxCommand(projRoot), 'Gen2 CDK deployment failed'); | |
} | |
export async function assertMigrateCodegen(projRoot: string) { | |
await assert.doesNotReject(runCodegenCommand(projRoot), 'Codegen failed'); | |
} | |
export async function assertDeploysGen2Sandbox(projRoot: string) { | |
await assert.doesNotReject(runGen2SandboxCommand(projRoot), 'Gen2 CDK deployment failed'); | |
} |
Or just get rid of these functions and have run..
and assertions inline in relevant tests. (I'd just inline this, these functions seem too small).
Description of changes
npx @aws-amplify/migrate to-gen-2 generate-code
npx ampx sandbox
yarn e2e-migration
from the rootDescription of how you validated changes
Checklist
yarn test
passesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.