Skip to content

Commit

Permalink
test: fix e2e failures
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardfoyle committed Sep 24, 2021
1 parent 7d6a130 commit 186efe2
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 17 deletions.
25 changes: 21 additions & 4 deletions packages/amplify-e2e-core/src/init/amplifyPush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,18 @@ export function amplifyPushWithoutCodegen(cwd: string, testingWithLatestCodebase
});
}

export function amplifyPushUpdate(cwd: string, waitForText?: RegExp, testingWithLatestCodebase: boolean = false): Promise<void> {
export function amplifyPushUpdate(
cwd: string,
waitForText?: RegExp,
testingWithLatestCodebase: boolean = false,
allowDestructiveUpdates: boolean = false,
): Promise<void> {
const args = ['push'];
if (allowDestructiveUpdates) {
args.push('--allow-destructuve-graphql-schema-updates');
}
return new Promise((resolve, reject) => {
spawn(getCLIPath(testingWithLatestCodebase), ['push'], { cwd, stripColors: true, noOutputTimeout: pushTimeoutMS })
spawn(getCLIPath(testingWithLatestCodebase), args, { cwd, stripColors: true, noOutputTimeout: pushTimeoutMS })
.wait('Are you sure you want to continue?')
.sendConfirmYes()
.wait(waitForText || /.*/)
Expand Down Expand Up @@ -130,7 +139,15 @@ export function amplifyPushAuth(cwd: string, testingWithLatestCodebase: boolean
});
}

export function amplifyPushUpdateForDependentModel(cwd: string, testingWithLatestCodebase: boolean = false): Promise<void> {
export function amplifyPushUpdateForDependentModel(
cwd: string,
testingWithLatestCodebase: boolean = false,
allowDestructiveUpdates: boolean = false,
): Promise<void> {
const args = ['push'];
if (allowDestructiveUpdates) {
args.push('--allow-destructuve-graphql-schema-updates');
}
return new Promise((resolve, reject) => {
spawn(getCLIPath(testingWithLatestCodebase), ['push'], { cwd, stripColors: true, noOutputTimeout: pushTimeoutMS })
.wait('Are you sure you want to continue?')
Expand Down Expand Up @@ -251,7 +268,7 @@ export function amplifyPushWithNoChanges(cwd: string, testingWithLatestCodebase:
return new Promise((resolve, reject) => {
spawn(getCLIPath(testingWithLatestCodebase), ['push'], { cwd, stripColors: true, noOutputTimeout: pushTimeoutMS })
.wait('No changes detected')
.run((err: Error) => err ? reject(err) : resolve());
.run((err: Error) => (err ? reject(err) : resolve()));
});
}

Expand Down
16 changes: 13 additions & 3 deletions packages/amplify-e2e-core/src/utils/headless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export const addHeadlessApi = async (cwd: string, request: AddApiRequest) => {
await executeHeadlessCommand(cwd, 'api', 'add', request);
};

export const updateHeadlessApi = async (cwd: string, request: UpdateApiRequest) => {
await executeHeadlessCommand(cwd, 'api', 'update', request);
export const updateHeadlessApi = async (cwd: string, request: UpdateApiRequest, allowDestructiveUpdates?: boolean) => {
await executeHeadlessCommand(cwd, 'api', 'update', request, allowDestructiveUpdates);
};

export const removeHeadlessApi = async (cwd: string, apiName: string) => {
Expand All @@ -33,7 +33,17 @@ export const headlessAuthImport = async (cwd: string, request: ImportAuthRequest
const headlessRemoveResource = async (cwd: string, category: string, resourceName: string) => {
await execa(getCLIPath(), ['remove', category, resourceName, '--yes'], { cwd });
};
const executeHeadlessCommand = async (cwd: string, category: string, operation: string, request: AnyHeadlessRequest) => {
const executeHeadlessCommand = async (
cwd: string,
category: string,
operation: string,
request: AnyHeadlessRequest,
allowDestructiveUpdates: boolean = false,
) => {
const args = [operation, category, '--headless'];
if (allowDestructiveUpdates) {
args.push('--allow-destructuve-graphql-schema-updates');
}
await execa(getCLIPath(), [operation, category, '--headless'], { input: JSON.stringify(request), cwd });
};

Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-e2e-tests/src/__tests__/api_1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ describe('amplify add api (GraphQL)', () => {
);
await amplifyPush(projRoot);
updateApiSchema(projRoot, projectName, nextSchema);
await amplifyPushUpdateForDependentModel(projRoot);
await amplifyPushUpdateForDependentModel(projRoot, undefined, true);
const meta = getProjectMeta(projRoot);
const region = meta.providers.awscloudformation.Region;
const { output } = meta.api.blogapp;
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-e2e-tests/src/__tests__/api_3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ describe('amplify add api (GraphQL)', () => {
await initJSProjectWithProfile(projRoot, {});
await addHeadlessApi(projRoot, addApiRequest);
await amplifyPush(projRoot);
await updateHeadlessApi(projRoot, updateApiRequest);
await amplifyPushUpdate(projRoot);
await updateHeadlessApi(projRoot, updateApiRequest, true);
await amplifyPushUpdate(projRoot, undefined, undefined, true);

// verify
const meta = getProjectMeta(projRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ describe('Schema iterative update - rename @key', () => {

const finalSchema = path.join('iterative-push', 'change-model-name', 'final-schema.graphql');
await updateApiSchema(projectDir, apiName, finalSchema);
await amplifyPushUpdate(projectDir);
await amplifyPushUpdate(projectDir, undefined, undefined, true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const prependDeploymentStepsToDisconnectFunctionsFromReplacedModelTables
): Promise<DeploymentStep[]> => {
const amplifyMeta = stateManager.getMeta();
const rootStackId = amplifyMeta?.providers?.awscloudformation?.StackId;
const allFunctionNames = Object.keys(amplifyMeta?.function);
const allFunctionNames = Object.keys(amplifyMeta?.function || {});
functionsDependentOnReplacedModelTables = await getDependentFunctions(
modelsBeingReplaced,
allFunctionNames,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ export async function run(context: $TSContext, resourceDefinition: $TSObject, re
}

let deploymentSteps: DeploymentStep[] = [];
let functionsDependentOnReplacedModelTables: string[] = [];

// location where the intermediate deployment steps are stored
let stateFolder: { local?: string; cloud?: string } = {};
Expand Down
8 changes: 5 additions & 3 deletions packages/graphql-auth-transformer/src/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ export class ResourceFactory {
expirationDays = apiKeyConfig.apiKeyExpirationDays;
}
// add delay expiration time is valid upon resource creation
let expirationDateInSeconds = 60 /* s */ * 60 /* m */ * 24 /* h */ * expirationDays; /* d */
// Add a 2 minute time delay if set to 1 day: https://github.com/aws-amplify/amplify-cli/issues/4460
if (expirationDays === 1) expirationDateInSeconds += 60 * 2;
let expirationDateInSeconds = 60 * 60 * 24 * expirationDays; // sec * min * day * days
// Add a 30 minute time delay if set to 1 day: https://github.com/aws-amplify/amplify-cli/issues/4460
// initially this was 2 minutes but with iterative deployments it is possible for deployments to take much longer than that
// if an iterative deployment takes longer than that, and API key expiration is set to 1 day, deployments may still fail
if (expirationDays === 1) expirationDateInSeconds += 60 * 30;
const nowEpochTime = Math.floor(Date.now() / 1000);
return new AppSync.ApiKey({
ApiId: Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
Expand Down
4 changes: 3 additions & 1 deletion packages/graphql-transformer-core/src/util/sanity-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,9 @@ export const cantRemoveTableAfterCreation = (_: Diff, currentBuild: DiffableProj
.map(([name]) => name);
const currentModels = getNestedStackLogicalIds(currentBuild);
const nextModels = getNestedStackLogicalIds(nextBuild);
const removedModels = currentModels.filter(currModel => !nextModels.includes(currModel));
const removedModels = currentModels
.filter(currModel => !nextModels.includes(currModel))
.filter(stackLogicalId => stackLogicalId !== 'ConnectionStack');
if (removedModels.length > 0) {
throw new DestructiveMigrationError(
'Removing a model from the GraphQL schema will also remove the underlying DynamoDB table.',
Expand Down

0 comments on commit 186efe2

Please sign in to comment.