-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: e2e for non-interactive init/pull in git-cloned project (#11365)
- Loading branch information
1 parent
c4d6dc2
commit 03cee46
Showing
18 changed files
with
386 additions
and
160 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,6 +178,7 @@ | |
"uint", | ||
"unauth", | ||
"unlink", | ||
"unstaged", | ||
"updateamplify", | ||
"urls", | ||
"userpool", | ||
|
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
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,13 @@ | ||
/** | ||
* Shape of awscloudformation object within `--profile` payload for init/pull | ||
*/ | ||
export type AwsProviderConfig = { | ||
configLevel: string, | ||
useProfile: boolean, | ||
profileName: string, | ||
} | ||
|
||
/** | ||
* Shape of `--categories` payload for init/pull | ||
*/ | ||
export type CategoriesConfig = Record<string, unknown>; |
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,7 +1,9 @@ | ||
/* eslint-disable import/no-cycle */ | ||
export * from './amplifyPull'; | ||
export * from './amplifyPush'; | ||
export * from './deleteProject'; | ||
export * from './initProjectHelper'; | ||
export * from './pull-headless'; | ||
export * from './adminUI'; | ||
export * from './overrideStack'; | ||
export * from './non-interactive-init'; |
56 changes: 56 additions & 0 deletions
56
packages/amplify-e2e-core/src/init/non-interactive-init.ts
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,56 @@ | ||
import execa from 'execa'; | ||
// eslint-disable-next-line import/no-cycle | ||
import { getCLIPath, TEST_PROFILE_NAME } from '..'; | ||
import { CategoriesConfig, AwsProviderConfig } from './headless-types'; | ||
|
||
/** | ||
* Executes a non-interactive init to attach a local project to an existing cloud environment | ||
*/ | ||
export const nonInteractiveInitAttach = async ( | ||
projRoot: string, | ||
amplifyInitConfig: AmplifyInitConfig, | ||
categoriesConfig?: CategoriesConfig, | ||
awsProviderConfig = getAwsProviderConfig(), | ||
): Promise<void> => { | ||
const args = [ | ||
'init', | ||
'--yes', | ||
'--amplify', | ||
JSON.stringify(amplifyInitConfig), | ||
'--providers', | ||
JSON.stringify({ | ||
awscloudformation: awsProviderConfig, | ||
}), | ||
]; | ||
if (categoriesConfig) { | ||
args.push('--categories', JSON.stringify(categoriesConfig)); | ||
} | ||
await execa(getCLIPath(), args, { cwd: projRoot }); | ||
}; | ||
|
||
/** | ||
* Returns an AmplifyConfig object with a default editor | ||
*/ | ||
export const getAmplifyInitConfig = (projectName: string, envName: string): AmplifyInitConfig => ({ | ||
projectName, | ||
envName, | ||
defaultEditor: 'code', | ||
}); | ||
|
||
/** | ||
* Returns a default AwsProviderConfig | ||
*/ | ||
export const getAwsProviderConfig = (): AwsProviderConfig => ({ | ||
configLevel: 'project', | ||
useProfile: true, | ||
profileName: TEST_PROFILE_NAME, | ||
}); | ||
|
||
/** | ||
* Shape of `--amplify` payload for init/pull | ||
*/ | ||
export type AmplifyInitConfig = { | ||
projectName: string, | ||
envName: string, | ||
defaultEditor: string, | ||
}; |
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,50 +1,36 @@ | ||
/* eslint-disable jsdoc/require-jsdoc */ | ||
// eslint-disable-next-line import/no-cycle | ||
import { nspawn as spawn, getCLIPath } from '..'; | ||
|
||
export function amplifyOverrideRoot(cwd: string, settings: { testingWithLatestCodebase?: boolean }) { | ||
return new Promise((resolve, reject) => { | ||
const args = ['override', 'project']; | ||
export const amplifyOverrideRoot = (cwd: string, settings: { testingWithLatestCodebase?: boolean }): Promise<void> => { | ||
const args = ['override', 'project']; | ||
|
||
spawn(getCLIPath(settings.testingWithLatestCodebase), args, { cwd, stripColors: true }) | ||
.wait('Do you want to edit override.ts file now?') | ||
.sendNo() | ||
.sendEof() | ||
.run((err: Error) => { | ||
if (!err) { | ||
resolve({}); | ||
} else { | ||
reject(err); | ||
} | ||
}); | ||
}); | ||
} | ||
return spawn(getCLIPath(settings.testingWithLatestCodebase), args, { cwd, stripColors: true }) | ||
.wait('Do you want to edit override.ts file now?') | ||
.sendNo() | ||
.sendEof() | ||
.runAsync(); | ||
}; | ||
|
||
export function amplifyOverrideAuth(cwd: string, settings: {}) { | ||
return new Promise((resolve, reject) => { | ||
const args = ['override', 'auth']; | ||
export const amplifyOverrideAuth = (cwd: string): Promise<void> => { | ||
const args = ['override', 'auth']; | ||
|
||
spawn(getCLIPath(), args, { cwd, stripColors: true }) | ||
.wait('Do you want to edit override.ts file now?') | ||
.sendNo() | ||
.sendEof() | ||
.run((err: Error) => { | ||
if (!err) { | ||
resolve({}); | ||
} else { | ||
reject(err); | ||
} | ||
}); | ||
}); | ||
} | ||
return spawn(getCLIPath(), args, { cwd, stripColors: true }) | ||
.wait('Do you want to edit override.ts file now?') | ||
.sendNo() | ||
.sendEof() | ||
.runAsync(); | ||
}; | ||
|
||
export function amplifyOverrideApi(cwd: string, settings: any) { | ||
export const amplifyOverrideApi = (cwd: string): Promise<void> => { | ||
const args = ['override', 'api']; | ||
const chain = spawn(getCLIPath(), args, { cwd, stripColors: true }); | ||
chain.wait('Do you want to edit override.ts file now?').sendNo().sendEof(); | ||
return chain.runAsync(); | ||
} | ||
}; | ||
|
||
export function buildOverrides(cwd: string, settings: any) { | ||
export const buildOverrides = (cwd: string): Promise<void> => { | ||
const args = ['build']; | ||
const chain = spawn(getCLIPath(), args, { cwd, stripColors: true }); | ||
return chain.runAsync(); | ||
} | ||
}; |
Oops, something went wrong.