Skip to content

Commit

Permalink
test: split e2e test file (#12150)
Browse files Browse the repository at this point in the history
* test: split e2e test file

* test: update windows smoke test list

* fix: typos

* Update parameter-store-2.test.ts

* Update split-e2e-tests-v2.ts

---------

Co-authored-by: Kamil Sobol <[email protected]>
  • Loading branch information
jhockett and sobolk authored Mar 3, 2023
1 parent d954a83 commit e5f00c3
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 85 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
addAuthWithEmailVerificationAndUserPoolGroupTriggers,
addFunction,
amplifyPull,
amplifyPushAuth,
createNewProjectDir,
deleteProject,
Expand All @@ -10,10 +8,6 @@ import {
generateRandomShortId,
getAppId,
getProjectMeta,
getTeamProviderInfo,
gitCleanFdx,
gitCommitAll,
gitInit,
initJSProjectWithProfile,
} from '@aws-amplify/amplify-e2e-core';
import { addEnvironmentCarryOverEnvVars, checkoutEnvironment, removeEnvironment } from '../environment/env';
Expand Down Expand Up @@ -108,82 +102,3 @@ describe('upload and delete parameters', () => {
);
});
});

describe('parameters in Parameter Store', () => {
let projRoot: string;
const envName = 'enva';

beforeAll(async () => {
projRoot = await createNewProjectDir('multi-env-parameters-test');
});

afterAll(async () => {
await deleteProject(projRoot);
deleteProjectDir(projRoot);
});

it('hydrates missing parameters into TPI on pull', async () => {
await initJSProjectWithProfile(projRoot, { disableAmplifyAppCreation: false, envName });
const meta = getProjectMeta(projRoot);
expect(meta).toBeDefined();
const appId = getAppId(projRoot);
expect(appId).toBeDefined();
const region = meta.providers.awscloudformation.Region;
expect(region).toBeDefined();
await gitInit(projRoot);
await gitCommitAll(projRoot); // commit all just after init, so no categories block exists in TPI yet

const envVariableName = 'envVariableName';
const envVariableValue = 'envVariableValue';

const fnName = `parameterstestfn${generateRandomShortId()}`;
await addFunction(
projRoot,
{
name: fnName,
functionTemplate: 'Hello World',
environmentVariables: {
key: envVariableName,
value: envVariableValue,
},
},
'nodejs',
);
await addAuthWithEmailVerificationAndUserPoolGroupTriggers(projRoot);
await amplifyPushAuth(projRoot);
const expectedParamsAfterPush = [
{ name: 'deploymentBucketName' },
{ name: envVariableName, value: envVariableValue },
{ name: 's3Key' },
];
await expectParametersOptionalValue(expectedParamsAfterPush, [], region, appId, envName, 'function', fnName);

const preCleanTpi = getTeamProviderInfo(projRoot);

// test pull --restore same dir
await gitCleanFdx(projRoot); // clear TPI
await amplifyPull(projRoot, { appId, envName, withRestore: true, emptyDir: true });
const postPullWithRestoreTpi = getTeamProviderInfo(projRoot);
expect(postPullWithRestoreTpi).toEqual(preCleanTpi);

// test pull same dir
await gitCleanFdx(projRoot); // clear TPI
await amplifyPull(projRoot, { appId, envName, withRestore: false, emptyDir: true });
const postPullWithoutRestoreTpi = getTeamProviderInfo(projRoot);
expect(postPullWithoutRestoreTpi).toEqual(preCleanTpi);

expect(await getTpiAfterPullInEmptyDir(appId, envName, true)).toEqual(preCleanTpi);
expect(await getTpiAfterPullInEmptyDir(appId, envName, false)).toEqual(preCleanTpi);
});

const getTpiAfterPullInEmptyDir = async (appId: string, envName: string, withRestore: boolean): Promise<Record<string, any>> => {
let emptyDir: string;
try {
emptyDir = await createNewProjectDir('empty-dir-parameters-test');
await amplifyPull(emptyDir, { appId, envName, withRestore, emptyDir: true });
return getTeamProviderInfo(emptyDir);
} finally {
deleteProjectDir(emptyDir);
}
};
});
97 changes: 97 additions & 0 deletions packages/amplify-e2e-tests/src/__tests__/parameter-store-2.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import {
addAuthWithEmailVerificationAndUserPoolGroupTriggers,
addFunction,
amplifyPull,
amplifyPushAuth,
createNewProjectDir,
deleteProject,
deleteProjectDir,
expectParametersOptionalValue,
generateRandomShortId,
getAppId,
getProjectMeta,
getTeamProviderInfo,
gitCleanFdx,
gitCommitAll,
gitInit,
initJSProjectWithProfile,
} from '@aws-amplify/amplify-e2e-core';

describe('parameters in Parameter Store', () => {
let projRoot: string;
const envName = 'enva';

beforeEach(async () => {
projRoot = await createNewProjectDir('multi-env');
});

afterEach(async () => {
await deleteProject(projRoot);
deleteProjectDir(projRoot);
});

it('hydrates missing parameters into TPI on pull', async () => {
await initJSProjectWithProfile(projRoot, { disableAmplifyAppCreation: false, envName });
const meta = getProjectMeta(projRoot);
expect(meta).toBeDefined();
const appId = getAppId(projRoot);
expect(appId).toBeDefined();
const region = meta.providers.awscloudformation.Region;
expect(region).toBeDefined();
await gitInit(projRoot);
await gitCommitAll(projRoot); // commit all just after init, so no categories block exists in TPI yet

const envVariableName = 'envVariableName';
const envVariableValue = 'envVariableValue';

const fnName = `parameterstestfn${generateRandomShortId()}`;
await addFunction(
projRoot,
{
name: fnName,
functionTemplate: 'Hello World',
environmentVariables: {
key: envVariableName,
value: envVariableValue,
},
},
'nodejs',
);
await addAuthWithEmailVerificationAndUserPoolGroupTriggers(projRoot);
await amplifyPushAuth(projRoot);
const expectedParamsAfterPush = [
{ name: 'deploymentBucketName' },
{ name: envVariableName, value: envVariableValue },
{ name: 's3Key' },
];
await expectParametersOptionalValue(expectedParamsAfterPush, [], region, appId, envName, 'function', fnName);

const preCleanTpi = getTeamProviderInfo(projRoot);

// test pull --restore same dir
await gitCleanFdx(projRoot); // clear TPI
await amplifyPull(projRoot, { appId, envName, withRestore: true, emptyDir: true });
const postPullWithRestoreTpi = getTeamProviderInfo(projRoot);
expect(postPullWithRestoreTpi).toEqual(preCleanTpi);

// test pull same dir
await gitCleanFdx(projRoot); // clear TPI
await amplifyPull(projRoot, { appId, envName, withRestore: false, emptyDir: true });
const postPullWithoutRestoreTpi = getTeamProviderInfo(projRoot);
expect(postPullWithoutRestoreTpi).toEqual(preCleanTpi);

expect(await getTpiAfterPullInEmptyDir(appId, envName, true)).toEqual(preCleanTpi);
expect(await getTpiAfterPullInEmptyDir(appId, envName, false)).toEqual(preCleanTpi);
});

const getTpiAfterPullInEmptyDir = async (appId: string, envName: string, withRestore: boolean): Promise<Record<string, any>> => {
let emptyDir: string;
try {
emptyDir = await createNewProjectDir('empty-dir-parameters-test');
await amplifyPull(emptyDir, { appId, envName, withRestore, emptyDir: true });
return getTeamProviderInfo(emptyDir);
} finally {
deleteProjectDir(emptyDir);
}
};
});
4 changes: 4 additions & 0 deletions scripts/split-e2e-tests-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const RUN_SOLO = [
'src/__tests__/geo-remove-3.test.ts',
'src/__tests__/geo-update-1.test.ts',
'src/__tests__/geo-update-2.test.ts',
'src/__tests__/hostingPROD.test.ts',
'src/__tests__/import_auth_1a.test.ts',
'src/__tests__/import_auth_1b.test.ts',
'src/__tests__/import_auth_2a.test.ts',
Expand Down Expand Up @@ -82,6 +83,9 @@ const WINDOWS_SMOKE_TESTS = [
'src/__tests__/hooks-b.test.ts',
// hosting
'src/__tests__/hostingPROD.test.ts',
// parameter store
'src/__tests__/parameter-store-1.test.ts',
'src/__tests__/parameter-store-2.test.ts',
// interactions
'src/__tests__/interactions.test.ts',
// schema auth test
Expand Down

0 comments on commit e5f00c3

Please sign in to comment.