Skip to content

Commit

Permalink
fix: pulling with env append to local files (#13227)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rtpascual authored and Justin Shih committed Sep 27, 2023
1 parent 9ab5ba8 commit 678f0bb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
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

0 comments on commit 678f0bb

Please sign in to comment.