Skip to content

Commit

Permalink
fix: #429 - Editor hanging bug (#2086)
Browse files Browse the repository at this point in the history
  • Loading branch information
attilah authored and kaustavghosh06 committed Aug 22, 2019
1 parent 814722a commit 6767445
Show file tree
Hide file tree
Showing 25 changed files with 130 additions and 115 deletions.
4 changes: 2 additions & 2 deletions packages/amplify-category-analytics/lib/pinpoint-helper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const opn = require('opn');
const open = require('open');
const constants = require('./constants');

function console(context) {
Expand All @@ -11,7 +11,7 @@ function console(context) {
const { Id, Region } = pinpointApp;
const consoleUrl =
`https://${Region}.console.aws.amazon.com/pinpoint/home/?region=${Region}#/apps/${Id}/analytics/overview`;
opn(consoleUrl, { wait: false });
open(consoleUrl, { wait: false });
} else {
context.print.error('Neither analytics nor notifications is enabled in the cloud.');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-category-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"amplify-category-auth": "1.11.0",
"fs-extra": "^8.1.0",
"inquirer": "^6.5.1",
"opn": "^5.3.0",
"open": "^6.4.0",
"uuid": "^3.3.2"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-category-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"inquirer": "^6.5.1",
"merge-graphql-schemas": "^1.7.0",
"moment": "^2.24.0",
"opn": "^5.3.0",
"open": "^6.4.0",
"ora": "^3.4.0",
"uuid": "^3.3.2"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const inquirer = require('inquirer');
const fs = require('fs-extra');
const path = require('path');
const opn = require('opn');
const open = require('open');

const category = 'api';
const serviceName = 'AppSync';
Expand Down Expand Up @@ -30,7 +30,7 @@ function openConsole(context) {

const consoleUrl =
`https://console.aws.amazon.com/appsync/home?region=${Region}#/${GraphQLAPIIdOutput}/v1/queries`;
opn(consoleUrl, { wait: false });
open(consoleUrl, { wait: false });
} else {
context.print.error('AppSync API is not pushed in the cloud.');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-category-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"inquirer": "^6.5.1",
"lodash": "^4.17.15",
"mime-types": "^2.1.24",
"opn": "^5.3.0",
"open": "^6.4.0",
"ora": "^3.4.0",
"promise-sequential": "^1.1.1",
"uuid": "^3.3.2"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const inquirer = require('inquirer');
const opn = require('opn');
const open = require('open');
const _ = require('lodash');
const {
existsSync,
Expand Down Expand Up @@ -532,15 +532,15 @@ function getCognitoOutput(amplifyMeta) {
async function openUserPoolConsole(context, region, userPoolId) {
const userPoolConsoleUrl =
`https://${region}.console.aws.amazon.com/cognito/users/?region=${region}#/pool/${userPoolId}/details`;
await opn(userPoolConsoleUrl, { wait: false });
await open(userPoolConsoleUrl, { wait: false });
context.print.info('User Pool console:');
context.print.success(userPoolConsoleUrl);
}

async function openIdentityPoolConsole(context, region, identityPoolId) {
const identityPoolConsoleUrl =
`https://${region}.console.aws.amazon.com/cognito/pool/?region=${region}&id=${identityPoolId}`;
await opn(identityPoolConsoleUrl, { wait: false });
await open(identityPoolConsoleUrl, { wait: false });
context.print.info('Identity Pool console:');
context.print.success(identityPoolConsoleUrl);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
jest.mock('fs-extra');
jest.mock('opn');
jest.mock('open');

jest.mock('../../../lib/S3AndCloudFront/configuration-manager');
jest.mock('../../../lib/S3AndCloudFront/configuration-manager');
jest.mock('../../../lib/S3AndCloudFront/helpers/file-uploader');
jest.mock('../../../lib/S3AndCloudFront/helpers/cloudfront-manager');

const fs = require('fs-extra');
const path = require('path');
const opn = require('opn');
const open = require('open');
const inquirer = require('inquirer');
const mockirer = require('mockirer');

Expand Down Expand Up @@ -74,17 +74,17 @@ describe('s3IndexModule', () => {
}
const mockAnswers = {
environment: DEV
};
};
let mockContext = {
amplify: {
pathManager: {
getBackendDirPath: jest.fn(()=>{
return 'mockBackendDirPath';
return 'mockBackendDirPath';
})
},
},
updateamplifyMetaAfterResourceAdd: jest.fn(),
getProjectMeta: jest.fn(()=>{
return mockAmplifyMeta;
return mockAmplifyMeta;
}),
readJsonFile: jest.fn(path => JSON.parse(fs.readFileSync(path))),
},
Expand All @@ -105,64 +105,64 @@ describe('s3IndexModule', () => {
parameters: {
options: {}
}
};
};
beforeAll(() => {
mockirer(inquirer, mockAnswers);
fs.ensureDirSync = jest.fn();
mockirer(inquirer, mockAnswers);
fs.ensureDirSync = jest.fn();
fs.existsSync = jest.fn(()=>{return true;})
fs.writeFileSync = jest.fn();
fs.writeFileSync = jest.fn();
fs.readFileSync = jest.fn((filePath)=>{
let result;
filePath = path.normalize(filePath);
let result;
filePath = path.normalize(filePath);
if(filePath.indexOf(templateFileName) > -1){
if(filePath === INTERNAL_TEMPLATE_FILE_PATH){
result = JSON.stringify(internalTemplateContents);
result = JSON.stringify(internalTemplateContents);
}else{
result = JSON.stringify(mockTemplate);
result = JSON.stringify(mockTemplate);
}
}else if(filePath.indexOf(parametersFileName)>-1){
if(filePath === INTERNAL_PARAMETERS_FILE_PATH){
result = JSON.stringify(internalParametersContents);
}else{
result = JSON.stringify(mockParameters);
result = JSON.stringify(mockParameters);
}
}
return result;
});
return result;
});
fileUPloader.run = jest.fn(()=>{return Promise.resolve(); });
cloudFrontManager.invalidateCloudFront = jest.fn(()=>{return Promise.resolve(); });

});
});

beforeEach(() => {
fs.ensureDirSync.mockClear();
fs.writeFileSync.mockClear();
fs.ensureDirSync.mockClear();
fs.writeFileSync.mockClear();
});

test('enable', async () => {
await s3IndexModule.enable(mockContext);
expect(configManager.init).toBeCalled();
await s3IndexModule.enable(mockContext);
expect(configManager.init).toBeCalled();
expect(mockContext.amplify.updateamplifyMetaAfterResourceAdd).toBeCalled();
});

test('configure', async () => {
await s3IndexModule.configure(mockContext);
expect(configManager.configure).toBeCalled();
await s3IndexModule.configure(mockContext);
expect(configManager.configure).toBeCalled();
});

test('publish', async () => {
await s3IndexModule.publish(mockContext, {distributionDirPath: 'dist'});
expect(fileUPloader.run).toBeCalled();
expect(cloudFrontManager.invalidateCloudFront).toBeCalled();
expect(opn).toBeCalled();
await s3IndexModule.publish(mockContext, {distributionDirPath: 'dist'});
expect(fileUPloader.run).toBeCalled();
expect(cloudFrontManager.invalidateCloudFront).toBeCalled();
expect(open).toBeCalled();
});

test('console', async () => {
await s3IndexModule.console(mockContext);
expect(opn).toBeCalled();
await s3IndexModule.console(mockContext);
expect(open).toBeCalled();
});

test('migrate', async () => {
await s3IndexModule.migrate(mockContext);
await s3IndexModule.migrate(mockContext);
});
})
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs-extra');
const inquirer = require('inquirer');
const path = require('path');
const opn = require('opn');
const open = require('open');
const chalk = require('chalk');
const configManager = require('./configuration-manager');
const fileUPloader = require('./helpers/file-uploader');
Expand Down Expand Up @@ -130,7 +130,7 @@ function publish(context, args) {
const { WebsiteURL } = context.exeInfo.serviceMeta.output;
context.print.info('Your app is published successfully.');
context.print.info(chalk.green(WebsiteURL));
opn(WebsiteURL, { wait: false });
open(WebsiteURL, { wait: false });
}
})
.catch((e) => {
Expand All @@ -145,7 +145,7 @@ function console(context) {
const consoleUrl =
`https://s3.console.aws.amazon.com/s3/buckets/${bucket}/?region=${region}&tab=overview`;
context.print.info(chalk.green(consoleUrl));
opn(consoleUrl, { wait: false });
open(consoleUrl, { wait: false });
}

async function migrate(context) {
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-category-hosting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"mime-types": "^2.1.24",
"minimatch": "^3.0.4",
"moment": "^2.24.0",
"opn": "^5.3.0",
"open": "^6.4.0",
"ora": "^3.4.0",
"promise-sequential": "^1.1.1"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const opn = require('opn');
const open = require('open');
const ora = require('ora');
const inquirer = require('inquirer');

Expand Down Expand Up @@ -221,7 +221,7 @@ function console(context) {
const { Id, Region } = pinpointApp;
const consoleUrl =
`https://${Region}.console.aws.amazon.com/pinpoint/home/?region=${Region}#/apps/${Id}/settings`;
opn(consoleUrl, { wait: false });
open(consoleUrl, { wait: false });
} else {
context.print.error('Neither notifications nor analytics is enabled in the cloud.');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-category-notifications/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"amplify-category-auth": "1.11.0",
"fs-extra": "^8.1.0",
"inquirer": "^6.5.1",
"opn": "^5.3.0",
"open": "^6.4.0",
"ora": "^3.4.0",
"promise-sequential": "^1.1.1",
"uuid": "^3.3.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-category-predictions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"fuzzy": "^0.1.3",
"inquirer": "^6.5.1",
"lodash": "^4.17.15",
"opn": "^5.3.0",
"open": "^6.4.0",
"uuid": "^3.3.2"
},
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import opn from 'opn';
import open from 'open';

const path = require('path');
const chalk = require('chalk');
Expand Down Expand Up @@ -62,7 +62,7 @@ async function console(context, resourceObj, amplifyMeta) {
async function openEndpointDetails(context, region, endpointName) {
const endpointConsoleUrl =
`https://${region}.console.aws.amazon.com/sagemaker/home?region=${region}#/endpoints/${endpointName}`;
await opn(endpointConsoleUrl, { wait: false });
await open(endpointConsoleUrl, { wait: false });
context.print.info('Endpoint Console:');
context.print.success(endpointConsoleUrl);
}
Expand Down Expand Up @@ -121,7 +121,7 @@ async function openRekognitionUploadUrl(context, bucketName, region, folderPolic
const URL = folderPolicies === 'admin' ? `https://s3.console.aws.amazon.com/s3/buckets/${bucketName}/${prefixForAdminTrigger}/admin/?region=${region}`
: `https://s3.console.aws.amazon.com/s3/buckets/${bucketName}/${prefixForAdminTrigger}/?region=${region}`;
if (!printOnlyURL) {
await opn(URL, { wait: false });
await open(URL, { wait: false });
}
context.print.info(chalk`Rekognition endpoint to upload Images: {blue.underline ${URL}} (Amazon Rekognition only supports uploading PNG and JPEG files)`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import opn from 'opn';
import open from 'open';
import inferAssets from '../assets/inferQuestions';
import getAllDefaults from '../default-values/infer-defaults';
import regionMapper from '../assets/regionMapping';
Expand Down Expand Up @@ -245,7 +245,7 @@ async function getEndpoints(context, questionObj, params) {
async function createEndpoint(context, defaultValues) {
const endpointConsoleUrl =
`https://${defaultValues.region}.console.aws.amazon.com/sagemaker/home?region=${defaultValues.region}#/endpoints/create`;
await opn(endpointConsoleUrl, { wait: false });
await open(endpointConsoleUrl, { wait: false });
context.print.info('SageMaker Console:');
context.print.success(endpointConsoleUrl);
await inquirer.prompt({
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-category-xr/lib/xr-manager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs-extra');
const path = require('path');
const inquirer = require('inquirer');
const opn = require('opn');
const open = require('open');
const chalk = require('chalk');
const { URL } = require('url');

Expand Down Expand Up @@ -222,7 +222,7 @@ async function remove(context) {

function console(context) {
context.print.info(chalk.green(SUMERIAN_CONSOLE_URL));
opn(SUMERIAN_CONSOLE_URL, { wait: false });
open(SUMERIAN_CONSOLE_URL, { wait: false });
}

function getProjectNameFromPath(urlPath) {
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-category-xr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"fs-extra": "^8.1.0",
"fuzzy": "^0.1.3",
"inquirer": "^6.5.1",
"opn": "^5.3.0",
"open": "^6.4.0",
"uuid": "^3.3.2"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"chalk": "^2.4.2",
"chalk-pipe": "^2.0.0",
"esm": "^3.2.25",
"env-editor": "^0.4.0",
"figlet": "^1.2.1",
"folder-hash": "^2.0.0",
"fs-extra": "^8.1.0",
Expand All @@ -51,7 +52,6 @@
"lodash": "^4.17.15",
"mime-types": "^2.1.24",
"moment": "^2.24.0",
"open-in-editor": "^2.2.0",
"optionator": "^0.8.2",
"ora": "^3.4.0",
"promise-sequential": "^1.1.1",
Expand Down

0 comments on commit 6767445

Please sign in to comment.