-
Notifications
You must be signed in to change notification settings - Fork 821
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: keeps hooks intact when attaching backend (#11179)
* fix: keeps hooks intact when attach backend * chore: address comments * fix: remove running pull on windows * chore: preserve yarn.lock file * chore: removes old hooks test file * chore: address comments Co-authored-by: Akshay Upadhyay <[email protected]>
- Loading branch information
Showing
5 changed files
with
59 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import { getBackendAmplifyMeta } from './projectMeta'; | ||
|
||
export function getAppId(projRoot: string): string { | ||
/** | ||
* fetches appId from amplify meta | ||
*/ | ||
export const getAppId = (projRoot: string): string => { | ||
const meta = getBackendAmplifyMeta(projRoot); | ||
return meta.providers.awscloudformation.AmplifyAppId; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { | ||
addFunction, | ||
amplifyPullNonInteractive, | ||
amplifyPushAuth, | ||
createNewProjectDir, | ||
deleteProject, | ||
deleteProjectDir, | ||
getBackendAmplifyMeta, | ||
getHooksDirPath, | ||
initJSProjectWithProfile, | ||
transformCurrentProjectToGitPulledProject, | ||
} from '@aws-amplify/amplify-e2e-core'; | ||
import * as fs from 'fs-extra'; | ||
import * as path from 'path'; | ||
|
||
describe('runtime hooks', () => { | ||
let projRoot: string; | ||
beforeEach(async () => { | ||
projRoot = await createNewProjectDir('hooks'); | ||
}); | ||
|
||
afterEach(async () => { | ||
await deleteProject(projRoot); | ||
deleteProjectDir(projRoot); | ||
}); | ||
|
||
it('hooks should not get deleted when pulling a project from git and running amplify pull', async () => { | ||
await initJSProjectWithProfile(projRoot, { envName: 'staging', disableAmplifyAppCreation: false }); | ||
const appId = getBackendAmplifyMeta(projRoot)?.providers?.awscloudformation?.AmplifyAppId; | ||
expect(appId).toBeDefined(); | ||
const hooksDirPath = getHooksDirPath(projRoot); | ||
expect(fs.existsSync(hooksDirPath)).toBe(true); | ||
fs.removeSync(path.join(hooksDirPath, 'pre-push.js.sample')); | ||
fs.removeSync(path.join(hooksDirPath, 'post-push.sh.sample')); | ||
fs.writeFileSync(path.join(hooksDirPath, 'pre-push.js'), `console.log('hello');`); | ||
await addFunction(projRoot, { functionTemplate: 'Hello World' }, 'nodejs'); | ||
await amplifyPushAuth(projRoot); | ||
// grab the appId from the meta file | ||
transformCurrentProjectToGitPulledProject(projRoot); | ||
await amplifyPullNonInteractive(projRoot, { appId, envName: 'staging' }); | ||
expect(fs.existsSync(hooksDirPath)).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters