From 678f0bb20b97281fae802b44d67535311be1d284 Mon Sep 17 00:00:00 2001 From: Roshane Pascual Date: Wed, 27 Sep 2023 09:48:56 -0700 Subject: [PATCH] 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 --- packages/amplify-cli/src/attach-backend.ts | 2 +- .../src/__tests__/git-clone-attach.test.ts | 3 +-- .../src/__tests__/pull.test.ts | 20 +++++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/amplify-cli/src/attach-backend.ts b/packages/amplify-cli/src/attach-backend.ts index 7b392358759..405ef20a1cc 100644 --- a/packages/amplify-cli/src/attach-backend.ts +++ b/packages/amplify-cli/src/attach-backend.ts @@ -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( diff --git a/packages/amplify-e2e-tests/src/__tests__/git-clone-attach.test.ts b/packages/amplify-e2e-tests/src/__tests__/git-clone-attach.test.ts index fb3b57dfeec..ad7939eb021 100644 --- a/packages/amplify-e2e-tests/src/__tests__/git-clone-attach.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/git-clone-attach.test.ts @@ -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); }); }); diff --git a/packages/amplify-e2e-tests/src/__tests__/pull.test.ts b/packages/amplify-e2e-tests/src/__tests__/pull.test.ts index b2c8d4b6493..22f6f401542 100644 --- a/packages/amplify-e2e-tests/src/__tests__/pull.test.ts +++ b/packages/amplify-e2e-tests/src/__tests__/pull.test.ts @@ -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; @@ -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', () => {