Skip to content

Commit

Permalink
test: fixing e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardfoyle committed Apr 23, 2021
1 parent 814b1ae commit d890f86
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ export function saveEnvResourceParameters(context: $TSContext, category: string,
stateManager.setTeamProviderInfo(undefined, teamProviderInfo);
// write hostedUIProviderCreds to deploymentSecrets
const deploymentSecrets = stateManager.getDeploymentSecrets();
const rootStackId = getRootStackId();
let rootStackId;
try {
rootStackId = getRootStackId();
} catch (err) {
return;
}
if (hostedUIProviderCreds) {
stateManager.setDeploymentSecrets(
mergeDeploymentSecrets({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export function getRootStackId(): string {
const teamProviderInfo = stateManager.getTeamProviderInfo();
const { envName } = stateManager.getLocalEnvInfo();
const envTeamProviderInfo = teamProviderInfo[envName];
if (envTeamProviderInfo && envTeamProviderInfo.awscloudformation) {
const stackId = envTeamProviderInfo.awscloudformation.StackId;
const stackId = envTeamProviderInfo?.awscloudformation?.StackId;
if (typeof stackId === 'string') {
return stackId.split('/')[2];
}
throw new Error('Root stack Id not found');
Expand Down
3 changes: 3 additions & 0 deletions packages/amplify-e2e-core/src/init/deleteProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { nspawn as spawn, retry, getCLIPath, describeCloudFormationStack, getPro

export const deleteProject = async (cwd: string, profileConfig?: any): Promise<void> => {
const { StackName: stackName, Region: region } = getProjectMeta(cwd).providers.awscloudformation;
if (!stackName || !region) {
return;
}
await retry(
() => describeCloudFormationStack(stackName, region, profileConfig),
stack => stack.StackStatus.endsWith('_COMPLETE'),
Expand Down
40 changes: 25 additions & 15 deletions packages/amplify-e2e-tests/src/__tests__/defer-init-push.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,55 @@ describe('defer root stack push', () => {
await deleteProject(projRoot);
deleteProjectDir(projRoot);
});
it('does not create a root stack until running amplify push', async () => {
await initJSProjectWithProfile(projRoot, { name: 'deferInitPush' });

it('does not create a root stack on interactive init', async () => {
await initJSProjectWithProfile(projRoot, { name: 'deferInitPush', envName: 'dev' });
const tpi_before = getTeamProviderInfo(projRoot);
expect(tpi_before?.dev?.awscloudformation?.DeploymentBucket).toBeUndefined();
expect(tpi_before?.dev?.awscloudformation?.DeploymentBucketName).toBeUndefined();
await addFunction(projRoot, { functionTemplate: 'Hello World' }, 'nodejs');
await amplifyPushAuth(projRoot);
const tpi_after = getTeamProviderInfo(projRoot);
expect(tpi_after?.dev?.awscloudformation?.DeploymentBucket).toBeDefined();
expect(tpi_after?.dev?.awscloudformation?.DeploymentBucketName).toBeDefined();
});

it('does not create a root stack on interactive env add', async () => {
await initJSProjectWithProfile(projRoot, { name: 'deferInitPush', envName: 'dev' });
const tpi_dev = getTeamProviderInfo(projRoot);
expect(tpi_dev?.dev?.awscloudformation?.DeploymentBucketName).toBeUndefined();
await addEnvironment(projRoot, { envName: 'test' });
const tpi_test = getTeamProviderInfo(projRoot);
expect(tpi_test?.test?.awscloudformation?.DeploymentBucketName).toBeUndefined();
});

it('creates a root stack when doing headless init', async () => {
it('creates a root stack on headless init', async () => {
await amplifyInitYes(projRoot);
const tpi_after = getTeamProviderInfo(projRoot);
expect(tpi_after?.dev?.awscloudformation?.DeploymentBucket).toBeDefined();
expect(tpi_after?.dev?.awscloudformation?.DeploymentBucketName).toBeDefined();
});

it('creates a root stack when doing headless env add', async () => {
await initJSProjectWithProfile(projRoot, { name: 'deferInitPush' });
it('creates a root stack on headless env add', async () => {
await initJSProjectWithProfile(projRoot, { name: 'deferInitPush', envName: 'dev' });
const tpi_dev = getTeamProviderInfo(projRoot);
expect(tpi_dev?.dev?.awscloudformation?.DeploymentBucket).toBeUndefined();
expect(tpi_dev?.dev?.awscloudformation?.DeploymentBucketName).toBeUndefined();
await addEnvironmentYes(projRoot, { envName: 'test' });
const tpi_test = getTeamProviderInfo(projRoot);
expect(tpi_test?.test?.awscloudformation?.DeploymentBucket).toBeDefined();
expect(tpi_test?.test?.awscloudformation?.DeploymentBucketName).toBeDefined();
});

it('can checkout unpushed environment', async () => {
await initJSProjectWithProfile(projRoot, { name: 'deferInitPush' });
await initJSProjectWithProfile(projRoot, { name: 'deferInitPush', envName: 'dev' });
const tpi_dev = getTeamProviderInfo(projRoot);
expect(tpi_dev?.dev?.awscloudformation?.DeploymentBucket).toBeUndefined();
expect(tpi_dev?.dev?.awscloudformation?.DeploymentBucketName).toBeUndefined();
await addEnvironment(projRoot, { envName: 'test' });
const tpi_test = getTeamProviderInfo(projRoot);
expect(tpi_test?.test?.awscloudformation?.DeploymentBucket).toBeUndefined();
expect(tpi_test?.test?.awscloudformation?.DeploymentBucketName).toBeUndefined();
await checkoutEnvironment(projRoot, { envName: 'dev' });
const localEnvInfo = getLocalEnvInfo(projRoot);
expect(localEnvInfo?.envName).toEqual('dev');
});

it('can remove a non-pushed env', async () => {
await initJSProjectWithProfile(projRoot, { name: 'deferInitPush' });
it('can remove unpushed environment', async () => {
await initJSProjectWithProfile(projRoot, { name: 'deferInitPush', envName: 'dev' });
await addEnvironment(projRoot, { envName: 'test' });
await checkoutEnvironment(projRoot, { envName: 'dev' });
const tpi_before = getTeamProviderInfo(projRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ function normalizeStackName(stackName) {
const doInitializeInCloud = (context: $TSContext): boolean => {
const hasCommandLineArgs = !_.isEmpty(context?.input?.options);
const isHeadlessInit = context?.input?.command === 'init' && hasCommandLineArgs;
const isHeadlessEnvAdd = context?.input?.command === 'env' && context?.input?.subcommand === 'add' && hasCommandLineArgs;
const isHeadlessEnvAdd = context?.input?.command === 'env' && context?.input?.subCommands?.[0] === 'add' && hasCommandLineArgs;
const isPush = context?.input?.command === 'push';
return !context.exeInfo || (context.exeInfo.isNewEnv && isHeadlessInit) || (context.exeInfo.isNewEnv && isHeadlessEnvAdd) || isPush;
};

0 comments on commit d890f86

Please sign in to comment.