Skip to content

Commit 678f0bb

Browse files
rtpascualJustin Shih
authored andcommitted
fix: pulling with env append to local files (#13227)
* fix: pulling with env append to local files * test: add e2e test * chore: remove unneeded condition * fix: revert prepareContext change * test: update expected changed files * test: change which dir to look for expected envs * test: update method to add second env to projRoot
1 parent 9ab5ba8 commit 678f0bb

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

packages/amplify-cli/src/attach-backend.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ const backupAmplifyFolder = (): void => {
125125
});
126126
}
127127
try {
128-
fs.moveSync(amplifyDirPath, backupAmplifyDirPath);
128+
fs.copySync(amplifyDirPath, backupAmplifyDirPath);
129129
} catch (e) {
130130
if (e.code === 'EPERM') {
131131
throw new AmplifyError(

packages/amplify-e2e-tests/src/__tests__/git-clone-attach.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,8 @@ describe('attach amplify to git-cloned project', () => {
120120
expect(changedFiles).toMatchInlineSnapshot(`
121121
[
122122
".gitignore",
123-
"amplify/README.md",
124123
]
125-
`); // there is a .gitignore newline and the amplify/README.md file is modified after pull
124+
`); // there is a .gitignore newline after pull
126125
expect(getTeamProviderInfo(projRoot)).toEqual(preCleanTpi);
127126
});
128127
});

packages/amplify-e2e-tests/src/__tests__/pull.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import {
1616
amplifyPullNonInteractive,
1717
amplifyPullWithCtrlCOnFrameworkPrompt,
1818
} from '@aws-amplify/amplify-e2e-core';
19+
import { stateManager } from '@aws-amplify/amplify-cli-core';
1920
import * as fs from 'fs-extra';
2021
import * as path from 'path';
22+
import { addEnvironment } from '../environment/env';
2123

2224
describe('amplify pull in two directories', () => {
2325
let projRoot: string;
@@ -57,6 +59,24 @@ describe('amplify pull in two directories', () => {
5759
await amplifyPullWithCtrlCOnFrameworkPrompt(projRoot2, { appId, envName });
5860
await amplifyPull(projRoot2, { appId, envName, emptyDir: true });
5961
});
62+
63+
it('appends pulled env to local-aws-info contents instead of overriding existing env', async () => {
64+
const envName = 'testing';
65+
const newEnvName = 'newenv';
66+
const expectedEnvs = [envName, newEnvName];
67+
68+
// add both envs to project
69+
await initJSProjectWithProfile(projRoot, { envName, disableAmplifyAppCreation: false });
70+
await addEnvironment(projRoot, { envName: newEnvName });
71+
72+
// pull twice for both envs in other directory
73+
const appId = getBackendAmplifyMeta(projRoot)?.providers?.awscloudformation?.AmplifyAppId;
74+
await amplifyPullNonInteractive(projRoot2, { appId, envName: envName });
75+
await amplifyPullNonInteractive(projRoot2, { appId, envName: newEnvName });
76+
77+
// assert that local-aws-info.json contains both envs
78+
expect(Object.keys(stateManager.getLocalAWSInfo(projRoot2))).toEqual(expectedEnvs);
79+
});
6080
});
6181

6282
describe('amplify pull', () => {

0 commit comments

Comments
 (0)