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: pulling with env append to local files #13227

Merged
merged 8 commits into from
Sep 27, 2023
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
2 changes: 1 addition & 1 deletion packages/amplify-cli/src/attach-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const backupAmplifyFolder = (): void => {
});
}
try {
fs.moveSync(amplifyDirPath, backupAmplifyDirPath);
fs.copySync(amplifyDirPath, backupAmplifyDirPath);
} catch (e) {
if (e.code === 'EPERM') {
throw new AmplifyError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ describe('attach amplify to git-cloned project', () => {
expect(changedFiles).toMatchInlineSnapshot(`
[
".gitignore",
"amplify/README.md",
]
`); // there is a .gitignore newline and the amplify/README.md file is modified after pull
`); // there is a .gitignore newline after pull
expect(getTeamProviderInfo(projRoot)).toEqual(preCleanTpi);
});
});
20 changes: 20 additions & 0 deletions packages/amplify-e2e-tests/src/__tests__/pull.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import {
amplifyPullNonInteractive,
amplifyPullWithCtrlCOnFrameworkPrompt,
} from '@aws-amplify/amplify-e2e-core';
import { stateManager } from '@aws-amplify/amplify-cli-core';
import * as fs from 'fs-extra';
import * as path from 'path';
import { addEnvironment } from '../environment/env';

describe('amplify pull in two directories', () => {
let projRoot: string;
Expand Down Expand Up @@ -57,6 +59,24 @@ describe('amplify pull in two directories', () => {
await amplifyPullWithCtrlCOnFrameworkPrompt(projRoot2, { appId, envName });
await amplifyPull(projRoot2, { appId, envName, emptyDir: true });
});

it('appends pulled env to local-aws-info contents instead of overriding existing env', async () => {
const envName = 'testing';
const newEnvName = 'newenv';
const expectedEnvs = [envName, newEnvName];

// add both envs to project
await initJSProjectWithProfile(projRoot, { envName, disableAmplifyAppCreation: false });
await addEnvironment(projRoot, { envName: newEnvName });

// pull twice for both envs in other directory
const appId = getBackendAmplifyMeta(projRoot)?.providers?.awscloudformation?.AmplifyAppId;
await amplifyPullNonInteractive(projRoot2, { appId, envName: envName });
await amplifyPullNonInteractive(projRoot2, { appId, envName: newEnvName });

// assert that local-aws-info.json contains both envs
expect(Object.keys(stateManager.getLocalAWSInfo(projRoot2))).toEqual(expectedEnvs);
});
});

describe('amplify pull', () => {
Expand Down