Skip to content
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

fix(amplify-provider-awscloudformation): fix hosting output #6041

Merged
merged 1 commit into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 27 additions & 2 deletions packages/amplify-e2e-core/src/categories/hosting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ export function addDEVHosting(cwd: string) {

export function addPRODHosting(cwd: string) {
return new Promise((resolve, reject) => {
// Cloudfront distrubution takes a long time. Bumping up the timeout
spawn(getCLIPath(), ['add', 'hosting'], { cwd, stripColors: true, noOutputTimeout: 30 * 60 * 1000 })
spawn(getCLIPath(), ['add', 'hosting'], { cwd, stripColors: true })
.wait('Select the plugin module to execute')
.send(KEY_DOWN_ARROW)
.sendCarriageReturn()
Expand All @@ -49,6 +48,32 @@ export function addPRODHosting(cwd: string) {
});
}

export function removePRODCloudFront(cwd: string) {
return new Promise((resolve, reject) => {
spawn(getCLIPath(), ['update', 'hosting'], { cwd, stripColors: true })
.wait('Specify the section to configure')
.send(KEY_DOWN_ARROW)
.sendCarriageReturn()
.wait('Remove CloudFront from hosting')
.send('y')
.sendCarriageReturn()
.wait('index doc for the website')
.sendCarriageReturn()
.wait('error doc for the website')
.sendCarriageReturn()
.wait('Specify the section to configure')
.send(KEY_DOWN_ARROW)
.sendCarriageReturn()
.run((err: Error) => {
if (!err) {
resolve();
} else {
reject(err);
}
});
});
}

export function amplifyPushWithUpdate(cwd: string) {
return new Promise((resolve, reject) => {
spawn(getCLIPath(), ['push'], { cwd, stripColors: true })
Expand Down
18 changes: 16 additions & 2 deletions packages/amplify-e2e-tests/src/__tests__/hostingPROD.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CloudFront } from 'aws-sdk';
import { amplifyPublishWithoutUpdate, createReactTestProject, resetBuildCommand } from 'amplify-e2e-core';

import { initJSProjectWithProfile, deleteProject, deleteS3Bucket } from 'amplify-e2e-core';
import { addPRODHosting, removeHosting, amplifyPushWithoutCodegen } from 'amplify-e2e-core';
import { addPRODHosting, removePRODCloudFront, removeHosting, amplifyPushWithoutCodegen } from 'amplify-e2e-core';
import { deleteProjectDir, getProjectMeta } from 'amplify-e2e-core';
import * as fs from 'fs-extra';
import * as path from 'path';
Expand Down Expand Up @@ -35,7 +35,7 @@ describe('amplify add hosting', () => {
expect(fs.existsSync(path.join(projRoot, 'amplify', 'backend', 'hosting', 'S3AndCloudFront'))).toBe(true);
const projectMeta = getProjectMeta(projRoot);
expect(projectMeta.hosting).toBeDefined();
expect(projectMeta.hosting.S3AndCloudFront).toBeDefined(); //CloudFrontDistributionID
expect(projectMeta.hosting.S3AndCloudFront).toBeDefined();
expect(projectMeta.hosting.S3AndCloudFront.output.CloudFrontDistributionID).toBeDefined();

const cloudFrontDistribution = await getCloudFrontDistribution(projectMeta.hosting.S3AndCloudFront.output.CloudFrontDistributionID);
Expand Down Expand Up @@ -64,6 +64,20 @@ describe('amplify add hosting', () => {
expect(error.message).toEqual('Process exited with non zero exit code 1');
resetBuildCommand(projRoot, currentBuildCommand);
});

it('correctly updates hosting meta output after CloudFront is removed', async () => {
await removePRODCloudFront(projRoot);
await amplifyPushWithoutCodegen(projRoot);
expect(fs.existsSync(path.join(projRoot, 'amplify', 'backend', 'hosting', 'S3AndCloudFront'))).toBe(true);
const projectMeta = getProjectMeta(projRoot);
expect(projectMeta.hosting).toBeDefined();
expect(projectMeta.hosting.S3AndCloudFront).toBeDefined();
expect(projectMeta.hosting.S3AndCloudFront.output.CloudFrontSecureURL).not.toBeDefined();
expect(projectMeta.hosting.S3AndCloudFront.output.CloudFrontOriginAccessIdentity).not.toBeDefined();
expect(projectMeta.hosting.S3AndCloudFront.output.CloudFrontDistributionID).not.toBeDefined();
expect(projectMeta.hosting.S3AndCloudFront.output.CloudFrontDomainName).not.toBeDefined();
expect(projectMeta.hosting.S3AndCloudFront.output.WebsiteURL).toBeDefined();
});
});

async function getCloudFrontDistribution(cloudFrontDistributionID: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ class CloudFormation {
}
}

if (resourceObject.service === 'S3AndCloudFront' && resourceObject.output) {
updatedMeta[category][resource].output = formattedOutputs;
}

stateManager.setMeta(undefined, updatedMeta);
}
}
Expand Down