Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/amplify-e2e-core/src/categories/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { nspawn as spawn, KEY_DOWN_ARROW, getCLIPath } from '../../src';
import { nspawn as spawn, KEY_DOWN_ARROW, getCLIPath } from '..';

export function addPinpoint(cwd: string, settings: any) {
return new Promise((resolve, reject) => {
Expand All @@ -9,8 +9,8 @@ export function addPinpoint(cwd: string, settings: any) {
.sendLine(settings.wrongName)
.wait('Resource name should be alphanumeric')
.send('\b')
.delay(500) // Some delay required for autocomplete and terminal to catch up
.sendLine(settings.rightName)
.wait('Apps need authorization to send analytics events. Do you want to allow guests')
.sendLine('n')
.wait(`Successfully added resource ${settings.rightName} locally`)
.sendEof()
Expand Down
3 changes: 1 addition & 2 deletions packages/amplify-e2e-core/src/categories/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { nspawn as spawn, KEY_DOWN_ARROW } from '../../src';
import { getCLIPath, updateSchema, nspawn as spawn, KEY_DOWN_ARROW } from '..';
import * as fs from 'fs-extra';
import { getCLIPath, updateSchema } from '../../src';
import { selectRuntime, selectTemplate } from './lambda-function';
import { singleSelect, multiSelect } from '../utils/selectors';
import _ from 'lodash';
Expand Down
3 changes: 1 addition & 2 deletions packages/amplify-e2e-core/src/categories/auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { KEY_UP_ARROW } from '../utils';
import { nspawn as spawn, KEY_DOWN_ARROW, getCLIPath, getSocialProviders } from '../../src';
import { nspawn as spawn, KEY_UP_ARROW, KEY_DOWN_ARROW, getCLIPath, getSocialProviders } from '..';

export function addAuthWithDefault(cwd: string, settings: any = {}) {
return new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-e2e-core/src/categories/codegen.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCLIPath, nspawn as spawn } from '../../src';
import { getCLIPath, nspawn as spawn } from '..';

export function generateModels(cwd: string) {
return new Promise((resolve, reject) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/amplify-e2e-core/src/categories/hosting.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs-extra';
import path from 'path';
import { nspawn as spawn, getCLIPath, createNewProjectDir, KEY_DOWN_ARROW, readJsonFile } from '../../src';
import * as fs from 'fs-extra';
import * as path from 'path';
import { nspawn as spawn, getCLIPath, createNewProjectDir, KEY_DOWN_ARROW, readJsonFile } from '..';
import { spawnSync } from 'child_process';

export function addDEVHosting(cwd: string) {
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-e2e-core/src/categories/interactions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { nspawn as spawn, getCLIPath } from '../../src';
import { nspawn as spawn, getCLIPath } from '..';

export function addSampleInteraction(cwd: string, settings: any) {
return new Promise((resolve, reject) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { nspawn as spawn, ExecutionContext, KEY_DOWN_ARROW, getCLIPath, getProjectMeta, invokeFunction } from '../../src';
import { nspawn as spawn, ExecutionContext, KEY_DOWN_ARROW, getCLIPath, getProjectMeta, invokeFunction } from '..';
import { Lambda } from 'aws-sdk';
import { singleSelect, multiSelect, moveUp, moveDown } from '../utils/selectors';

Expand Down
8 changes: 4 additions & 4 deletions packages/amplify-e2e-core/src/categories/lambda-layer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { JSONUtilities } from 'amplify-cli-core';
import fs from 'fs-extra';
import * as fs from 'fs-extra';
import * as path from 'path';
import _ from 'lodash';
import path from 'path';
import { nspawn as spawn, ExecutionContext, getCLIPath, KEY_DOWN_ARROW } from '../../src';
import { JSONUtilities } from 'amplify-cli-core';
import { nspawn as spawn, ExecutionContext, getCLIPath, KEY_DOWN_ARROW } from '..';
import { getLayerVersion, listVersions } from '../utils/sdk-calls';
import { multiSelect } from '../utils/selectors';

Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-e2e-core/src/categories/predictions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { nspawn as spawn, KEY_DOWN_ARROW, getCLIPath } from '../../src';
import { nspawn as spawn, KEY_DOWN_ARROW, getCLIPath } from '..';

// add convert resource
export function addConvert(cwd: string, settings: any) {
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-e2e-core/src/categories/storage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { nspawn as spawn, KEY_DOWN_ARROW, getCLIPath } from '../../src';
import { nspawn as spawn, KEY_DOWN_ARROW, getCLIPath } from '..';
import { singleSelect, multiSelect } from '../utils/selectors';

export function addSimpleDDB(cwd: string, settings: any) {
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-e2e-core/src/configure/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { nspawn as spawn, getCLIPath, singleSelect } from '../../src';
import { nspawn as spawn, getCLIPath, singleSelect } from '..';

type AmplifyConfiguration = {
accessKeyId: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-e2e-core/src/init/amplifyPull.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCLIPath, nspawn as spawn } from '../../src';
import { getCLIPath, nspawn as spawn } from '..';

export function amplifyPull(cwd: string, settings: { override?: boolean; emptyDir?: boolean; appId?: string; withRestore?: boolean }) {
return new Promise((resolve, reject) => {
Expand Down
3 changes: 1 addition & 2 deletions packages/amplify-e2e-core/src/init/deleteProject.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { nspawn as spawn, retry } from '../../src';
import { getCLIPath, describeCloudFormationStack, getProjectMeta } from '../../src';
import { nspawn as spawn, retry, getCLIPath, describeCloudFormationStack, getProjectMeta } from '..';

export const deleteProject = async (cwd: string, profileConfig?: any) => {
const { StackName: stackName, Region: region } = getProjectMeta(cwd).providers.awscloudformation;
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-e2e-core/src/init/initProjectHelper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { nspawn as spawn, getCLIPath, singleSelect } from '../../src';
import { nspawn as spawn, getCLIPath, singleSelect } from '..';

const defaultSettings = {
name: '\r',
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-e2e-core/src/init/pull-headless.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { nspawn as spawn, getCLIPath } from '../../src';
import { nspawn as spawn, getCLIPath } from '..';

const defaultSettings = {
name: '\r',
Expand Down
112 changes: 104 additions & 8 deletions packages/amplify-e2e-core/src/utils/nexpect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ export type ExecutionContext = {
sendLine: (line: string) => ExecutionContext;
sendCarriageReturn: () => ExecutionContext;
send: (line: string) => ExecutionContext;
sendKeyDown: (repeat?: number) => ExecutionContext;
sendKeyUp: (repeat?: number) => ExecutionContext;
sendConfirmYes: () => ExecutionContext;
sendConfirmNo: () => ExecutionContext;
sendEof: () => ExecutionContext;
delay: (milliseconds: number) => ExecutionContext;
run: (cb: (err: any, signal?: any) => void) => ExecutionContext;
};

Expand Down Expand Up @@ -109,7 +114,7 @@ function chain(context: Context): ExecutionContext {
},
name: '_expect',
shift: true,
description: '[expect] ' + expectation,
description: `[expect] ${expectation}`,
requiresInput: true,
expectation: expectation,
};
Expand All @@ -129,7 +134,7 @@ function chain(context: Context): ExecutionContext {
},
name: '_wait',
shift: false,
description: '[wait] ' + expectation,
description: `[wait] ${expectation}`,
requiresInput: true,
expectation: expectation,
};
Expand All @@ -139,12 +144,12 @@ function chain(context: Context): ExecutionContext {
sendLine: function(line: string): ExecutionContext {
let _sendline: ExecutionStep = {
fn: () => {
context.process.write(line + EOL);
context.process.write(`${line}${EOL}`);
return true;
},
name: '_sendline',
shift: true,
description: '[sendline] ' + line,
description: `[sendline] ${line}`,
requiresInput: false,
};
context.queue.push(_sendline);
Expand All @@ -158,7 +163,7 @@ function chain(context: Context): ExecutionContext {
},
name: '_sendline',
shift: true,
description: '[sendline] ',
description: '[sendline] <CR>',
requiresInput: false,
};
context.queue.push(_sendline);
Expand All @@ -172,7 +177,69 @@ function chain(context: Context): ExecutionContext {
},
name: '_send',
shift: true,
description: '[send] ' + line,
description: `[send] ${line}`,
requiresInput: false,
};
context.queue.push(_send);
return chain(context);
},
sendKeyDown: function(repeat?: number): ExecutionContext {
const repeatitions = repeat ? Math.max(1, repeat) : 1;
var _send: ExecutionStep = {
fn: () => {
for (let i = 0; i < repeatitions; i++) {
context.process.write(KEY_DOWN_ARROW);
}
return true;
},
name: '_send',
shift: true,
description: `'[send] <Down> (${repeatitions})`,
requiresInput: false,
};
context.queue.push(_send);
return chain(context);
},
sendKeyUp: function(repeat?: number): ExecutionContext {
const repeatitions = repeat ? Math.max(1, repeat) : 1;
var _send: ExecutionStep = {
fn: () => {
for (let i = 0; i < repeatitions; i++) {
context.process.write(KEY_UP_ARROW);
}
return true;
},
name: '_send',
shift: true,
description: `'[send] <Up> (${repeatitions})`,
requiresInput: false,
};
context.queue.push(_send);
return chain(context);
},
sendConfirmYes: function(): ExecutionContext {
var _send: ExecutionStep = {
fn: () => {
context.process.write(`Y${EOL}`);
return true;
},
name: '_send',
shift: true,
description: `'[send] Y <CR>`,
requiresInput: false,
};
context.queue.push(_send);
return chain(context);
},
sendConfirmNo: function(): ExecutionContext {
var _send: ExecutionStep = {
fn: () => {
context.process.write(`N${EOL}`);
return true;
},
name: '_send',
shift: true,
description: `'[send] N <CR>`,
requiresInput: false,
};
context.queue.push(_send);
Expand All @@ -192,6 +259,23 @@ function chain(context: Context): ExecutionContext {
context.queue.push(_sendEof);
return chain(context);
},
delay: function(milliseconds: number): ExecutionContext {
var _delay: ExecutionStep = {
fn: () => {
const startCallback = Date.now();

while (Date.now() - startCallback < milliseconds) {}

return true;
},
shift: true,
name: '_delay',
description: `'[delay] (${milliseconds})`,
requiresInput: false,
};
context.queue.push(_delay);
return chain(context);
},
run: function(callback: (err: any, code?: number, signal?: string | number) => void): ExecutionContext {
let errState: any = null;
let responded = false;
Expand Down Expand Up @@ -269,7 +353,8 @@ function chain(context: Context): ExecutionContext {
onError(new Error('Cannot process non-function on nexpect stack.'), true);
return false;
} else if (
['_expect', '_sendline', '_send', '_wait', '_sendEof', '_pauseRecording', '_resumeRecording'].indexOf(currentFnName) === -1
['_expect', '_sendline', '_send', '_wait', '_sendEof', '_delay', '_pauseRecording', '_resumeRecording'].indexOf(currentFnName) ===
-1
) {
//
// If the `currentFn` is a function, but not those set by `.sendline()` or
Expand Down Expand Up @@ -494,12 +579,23 @@ export function nspawn(command: string | string[], params: string[] = [], option
}

let childEnv = undefined;
let pushEnv = undefined;

// For push operations in E2E we have to explicitly disable the Amplify Console App creation
// as for the tests that need it, it is already enabled for init, setting the env var here
// disables the post push check we have in the CLI.
if (params.length > 0 && params[0].toLowerCase() === 'push') {
pushEnv = {
CLI_DEV_INTERNAL_DISABLE_AMPLIFY_APP_CREATION: '1',
};
}

// If we have an environment passed in we've to add the current process' environment, otherwised the forked
// process would not have $PATH and others that is required to run amplify-cli successfully.
if (options.env) {
if (options.env || pushEnv) {
childEnv = {
...process.env,
...pushEnv,
...options.env,
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-e2e-core/src/utils/pinpoint.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Pinpoint } from 'aws-sdk';
import { getCLIPath, nspawn as spawn, singleSelect, amplifyRegions } from '../../src';
import { getCLIPath, nspawn as spawn, singleSelect, amplifyRegions } from '..';
import _ from 'lodash';

const settings = {
Expand Down
16 changes: 14 additions & 2 deletions packages/amplify-e2e-core/src/utils/projectMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,25 @@ function getProjectMeta(projectRoot: string) {
}

function getProjectTags(projectRoot: string) {
const metaFilePath = path.join(projectRoot, 'amplify', '#current-cloud-backend', 'tags.json');
return JSON.parse(fs.readFileSync(metaFilePath, 'utf8'));
const projectTagsFilePath = path.join(projectRoot, 'amplify', '#current-cloud-backend', 'tags.json');
return JSON.parse(fs.readFileSync(projectTagsFilePath, 'utf8'));
}

function getBackendAmplifyMeta(projectRoot: string) {
const metaFilePath = path.join(projectRoot, 'amplify', 'backend', 'amplify-meta.json');
return JSON.parse(fs.readFileSync(metaFilePath, 'utf8'));
}

function getBackendConfig(projectRoot: string) {
const backendFConfigFilePath = path.join(projectRoot, 'amplify', 'backend', 'backend-config.json');
return JSON.parse(fs.readFileSync(backendFConfigFilePath, 'utf8'));
}

function getTeamProviderInfo(projectRoot: string) {
const teamProviderFilePath = path.join(projectRoot, 'amplify', 'team-provider-info.json');
return JSON.parse(fs.readFileSync(teamProviderFilePath, 'utf8'));
}

function getS3StorageBucketName(projectRoot: string) {
const meta = getProjectMeta(projectRoot);
const storage = meta['storage'];
Expand Down Expand Up @@ -66,4 +76,6 @@ export {
getAWSConfigIOSPath,
getS3StorageBucketName,
getAmplifyDirPath,
getBackendConfig,
getTeamProviderInfo,
};
2 changes: 1 addition & 1 deletion packages/amplify-e2e-core/src/utils/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExecutionContext } from '../../src';
import { ExecutionContext } from '..';

export const moveDown = (chain: ExecutionContext, nMoves: number) =>
Array.from(Array(nMoves).keys()).reduce((chain, _idx) => chain.send('j'), chain);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,9 @@ async function downloadBackend(context, backendEnv, awsConfig) {
absolute: true,
});
const amplifyDir = pathManager.getAmplifyDirPath();
const isPulling = context.input.command === 'pull' || (context.input.command === 'env' && context.input.subCommands[0] === 'pull');

if (context.exeInfo && context.exeInfo.restoreBackend) {
if ((context.exeInfo && context.exeInfo.restoreBackend) || isPulling) {
// If backend must be restored then copy out the config files and overwrite existing ones.
for (const cliJSONFilePath of cliJSONFiles) {
const targetPath = path.join(amplifyDir, path.basename(cliJSONFilePath));
Expand Down