Skip to content

Commit

Permalink
fix: remove running pull on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Akshay Upadhyay committed Oct 19, 2022
1 parent 009a44b commit 5c3d6be
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
37 changes: 37 additions & 0 deletions packages/amplify-e2e-tests/src/__tests__/hooks-a.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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);
});
});
34 changes: 34 additions & 0 deletions packages/amplify-e2e-tests/src/__tests__/hooks-b.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
addFunction, createNewProjectDir,
deleteProject,
deleteProjectDir, getHooksDirPath, initJSProjectWithProfile,
} 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('test hook scripts with non zero exit code', async () => {
// eslint-disable-next-line spellcheck/spell-checker
await initJSProjectWithProfile(projRoot, { envName: 'enva' });
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-add.js'), 'process.exit(1);');

// amplify process should exit as the hook script exited with non zero exit code
await expect(addFunction(projRoot, { functionTemplate: 'Hello World' }, 'nodejs')).rejects.toThrow();
// expect function to be not created
expect(fs.readdirSync(path.join(projRoot, 'amplify', 'backend'))).not.toContain('function');
});
});
2 changes: 1 addition & 1 deletion scripts/split-e2e-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const WINDOWS_TEST_ALLOWLIST: string[] = [
'schema-auth-11-c_pkg',
'auth_6_pkg',
'frontend_config_drift_pkg',
'hooks_pkg',
'hooks-b_pkg',
'plugin_pkg',
'schema-versioned_pkg',
'schema-auth-3_pkg',
Expand Down

0 comments on commit 5c3d6be

Please sign in to comment.