Skip to content

Commit 1ffbaf1

Browse files
authored
test: add codegen test matrix (#766)
* test: add codegen test matrix * add matrix options * add matrix cases * add matrix test in spec * fix e2e * debug e2e * Revert "debug e2e" This reverts commit 4f6f051. * rm windows for codegen matrix
1 parent 3abb124 commit 1ffbaf1

File tree

13 files changed

+615
-71
lines changed

13 files changed

+615
-71
lines changed

.codebuild/e2e_workflow.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ batch:
6868
debug-session: true
6969
depend-on:
7070
- publish_to_local_registry
71+
- identifier: codegen_matrix
72+
buildspec: .codebuild/run_e2e_tests.yml
73+
env:
74+
compute-type: BUILD_GENERAL1_LARGE
75+
variables:
76+
TEST_SUITE: src/__tests__/codegen-matrix.test.ts
77+
CLI_REGION: ap-southeast-2
78+
debug-session: true
79+
depend-on:
80+
- publish_to_local_registry
7181
- identifier: >-
7282
l_add_codegen_ios_configure_codegen_android_configure_codegen_js_graphql_codegen_android
7383
buildspec: .codebuild/run_e2e_tests.yml

.codebuild/e2e_workflow_base.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,13 @@ batch:
6868
debug-session: true
6969
depend-on:
7070
- publish_to_local_registry
71+
- identifier: codegen_matrix
72+
buildspec: .codebuild/run_e2e_tests.yml
73+
env:
74+
compute-type: BUILD_GENERAL1_LARGE
75+
variables:
76+
TEST_SUITE: src/__tests__/codegen-matrix.test.ts
77+
CLI_REGION: ap-southeast-2
78+
debug-session: true
79+
depend-on:
80+
- publish_to_local_registry

packages/amplify-codegen-e2e-core/src/categories/codegen.ts

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AmplifyFrontend } from '../utils';
1+
import { AmplifyFrontend, singleSelect } from '../utils';
22
import { getCLIPath, nspawn as spawn } from '..';
33

44
export function generateModels(cwd: string, outputDir?: string, settings: { errMessage?: string } = {}): Promise<void> {
@@ -76,35 +76,69 @@ export function generateTypes(cwd: string) : Promise<void> {
7676

7777
// CLI workflow to add codegen to Amplify project
7878
export function addCodegen(cwd: string, settings: any = {}): Promise<void> {
79+
const defaultSettings = {
80+
params: [],
81+
isAPINotAdded: false,
82+
isCodegenAdded: false,
83+
frontendType: AmplifyFrontend.javascript,
84+
framework: 'none',
85+
codegenTarget: 'typescript',
86+
isStatementGenerated: true,
87+
statementNamePattern: '\r', // default value
88+
maxDepth: '\r', // default value
89+
isTypeGenerated: true,
90+
typeFileName: '\r', // default value
91+
}
92+
const mergedSettings = { ...defaultSettings, ...settings };
7993
return new Promise((resolve, reject) => {
80-
const params = settings.params
81-
? ['codegen', 'add', ...settings.params]
94+
const params = mergedSettings.params
95+
? ['codegen', 'add', ...mergedSettings.params]
8296
: ['codegen', 'add'];
8397
const chain = spawn(getCLIPath(), params, { cwd, stripColors: true });
84-
if (settings.isAPINotAdded) {
98+
if(mergedSettings.frontendType === AmplifyFrontend.flutter) {
99+
chain.wait("Flutter only supports the command $amplify codegen models. All the other codegen commands are not supported.");
100+
}
101+
else if (mergedSettings.isAPINotAdded) {
85102
chain.wait("There are no GraphQL APIs available.");
86103
chain.wait("Add by running $amplify api add");
87104
}
88-
else if (settings.isCodegenAdded) {
105+
else if (mergedSettings.isCodegenAdded) {
89106
chain.wait("Codegen support only one GraphQL API per project");
90107
}
91108
else {
92-
if (settings.frontendType === AmplifyFrontend.javascript) {
93-
chain.wait('Choose the code generation language target').sendCarriageReturn();
109+
if (mergedSettings.frontendType === AmplifyFrontend.javascript) {
110+
chain.wait('Choose the code generation language target');
111+
if (mergedSettings.framework === 'angular' || mergedSettings.framework === 'ionic') {
112+
singleSelect(chain, mergedSettings.codegenTarget, ['angular', 'typescript']);
113+
} else {
114+
singleSelect(chain, mergedSettings.codegenTarget, ['javascript', 'typescript', 'flow']);
115+
}
94116
}
95117
chain
96118
.wait('Enter the file name pattern of graphql queries, mutations and subscriptions')
97-
.sendCarriageReturn()
98-
.wait('Do you want to generate/update all possible GraphQL operations')
99-
.sendLine('y')
100-
.wait('Enter maximum statement depth [increase from default if your schema is deeply')
101-
.sendCarriageReturn();
102-
if (settings.frontendType === AmplifyFrontend.ios) {
119+
.sendLine(mergedSettings.statementNamePattern)
120+
.wait('Do you want to generate/update all possible GraphQL operations');
121+
if (mergedSettings.isStatementGenerated) {
122+
chain
123+
.sendLine('y')
124+
.wait('Enter maximum statement depth [increase from default if your schema is deeply')
125+
.sendLine(mergedSettings.maxDepth);
126+
} else {
127+
chain.sendLine('n');
128+
}
129+
130+
const isTypeGenIncluded = mergedSettings.frontendType === AmplifyFrontend.ios
131+
|| (mergedSettings.frontendType === AmplifyFrontend.javascript && mergedSettings.codegenTarget !== 'javascript');
132+
if (isTypeGenIncluded) {
103133
chain
104134
.wait('Enter the file name for the generated code')
105-
.sendCarriageReturn()
106-
.wait('Do you want to generate code for your newly created GraphQL API')
107-
.sendCarriageReturn();
135+
.sendLine(mergedSettings.typeFileName)
136+
.wait('Do you want to generate code for your newly created GraphQL API');
137+
if (mergedSettings.isTypeGenerated) {
138+
chain.sendLine('y');
139+
} else {
140+
chain.sendLine('n');
141+
}
108142
}
109143
}
110144

packages/amplify-codegen-e2e-core/src/configure/index.ts

Lines changed: 119 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ const defaultSettings = {
1313
userName: '\r',
1414
};
1515

16+
const defaultProjectSettings = {
17+
name: '\r',
18+
envName: 'integtest',
19+
editor: '\r',
20+
frontendType: 'javascript',
21+
framework: 'none',
22+
srcDir: '\r',
23+
distDir: '\r',
24+
buildCmd: '\r',
25+
startCmd: '\r',
26+
};
27+
1628
export const amplifyRegions = [
1729
'us-east-1',
1830
'us-east-2',
@@ -34,8 +46,11 @@ export const amplifyRegions = [
3446
'sa-east-1',
3547
];
3648

37-
const configurationOptions = ['project', 'profile', 'containers'];
38-
const profileOptions = ['cancel', 'update', 'remove'];
49+
const configurationOptions = ['Project information', 'AWS Profile setting', 'Advanced: Container-based deployments'];
50+
const profileOptions = ['No', 'Update AWS Profile', 'Remove AWS Profile'];
51+
const authenticationOptions = ['AWS profile', 'AWS access keys'];
52+
const javaScriptFrameworkList = [ 'none', 'angular', 'ember', 'ionic', 'react', 'react-native', 'vue' ];
53+
3954

4055
const MANDATORY_PARAMS = ['accessKeyId', 'secretAccessKey', 'region'];
4156

@@ -77,18 +92,52 @@ export function amplifyConfigure(settings: AmplifyConfiguration): Promise<void>
7792
});
7893
}
7994

80-
export function amplifyConfigureProject(settings: { cwd: string; enableContainers: boolean }): Promise<void> {
81-
const { enableContainers = false, cwd } = settings;
95+
export function amplifyConfigureProject(settings: {
96+
cwd: string;
97+
enableContainers?: boolean;
98+
configLevel?: string;
99+
profileOption?: string;
100+
authenticationOption?: string;
101+
region?: string;
102+
}): Promise<void> {
103+
const {
104+
cwd,
105+
enableContainers = false,
106+
profileOption = profileOptions[0],
107+
authenticationOption,
108+
configLevel = 'project',
109+
region = defaultSettings.region,
110+
} = settings;
82111

83112
return new Promise((resolve, reject) => {
84113
const chain = spawn(getCLIPath(), ['configure', 'project'], { cwd, stripColors: true }).wait('Which setting do you want to configure?');
114+
85115
if (enableContainers) {
86-
singleSelect(chain, 'containers', configurationOptions);
87-
chain.wait('Do you want to enable container-based deployments?').sendLine('y');
116+
singleSelect(chain, configurationOptions[2], configurationOptions);
117+
chain.wait('Do you want to enable container-based deployments?').sendConfirmYes();
88118
} else {
89-
singleSelect(chain, 'profile', configurationOptions);
90-
chain.wait('Do you want to update or remove the project level AWS profile?');
91-
singleSelect(chain, profileOptions[0], profileOptions);
119+
singleSelect(chain, configurationOptions[1], configurationOptions);
120+
121+
if (configLevel === 'project') {
122+
chain.wait('Do you want to update or remove the project level AWS profile?');
123+
singleSelect(chain, profileOption, profileOptions);
124+
} else {
125+
chain.wait('Do you want to set the project level configuration').sendConfirmYes();
126+
}
127+
128+
if (profileOption === profileOptions[1] || configLevel === 'general') {
129+
chain.wait('Select the authentication method you want to use:');
130+
singleSelect(chain, authenticationOption, authenticationOptions);
131+
132+
if (authenticationOption === authenticationOptions[0]) {
133+
chain.wait('Please choose the profile you want to use').sendCarriageReturn(); // Default profile
134+
} else if (authenticationOption === authenticationOptions[1]) {
135+
chain.wait('accessKeyId:').sendLine(process.env.AWS_ACCESS_KEY_ID);
136+
chain.wait('secretAccessKey:').sendLine(process.env.AWS_SECRET_ACCESS_KEY);
137+
chain.wait('region:');
138+
singleSelect(chain, region, amplifyRegions);
139+
}
140+
}
92141
}
93142

94143
chain.wait('Successfully made configuration changes to your project.').run((err: Error) => {
@@ -100,3 +149,64 @@ export function amplifyConfigureProject(settings: { cwd: string; enableContainer
100149
});
101150
});
102151
}
152+
153+
export function amplifyConfigureProjectInfo(settings: {
154+
cwd: string,
155+
frontendType: string,
156+
}): Promise<void> {
157+
const {
158+
cwd,
159+
} = settings;
160+
const s = { ...defaultProjectSettings, ...settings };
161+
return new Promise((resolve, reject) => {
162+
const chain = spawn(getCLIPath(), ['configure', 'project'], { cwd, stripColors: true }).wait('Which setting do you want to configure?');
163+
singleSelect(chain, configurationOptions[0], configurationOptions);
164+
chain
165+
.wait('Enter a name for the project')
166+
.sendLine(s.name)
167+
.wait('Choose your default editor:')
168+
.sendLine(s.editor)
169+
.wait("Choose the type of app that you're building")
170+
.sendLine(s.frontendType);
171+
172+
switch (s.frontendType) {
173+
case 'javascript':
174+
chain.wait('What javascript framework are you using');
175+
singleSelect(chain, s.framework, javaScriptFrameworkList);
176+
chain
177+
.wait('Source Directory Path:')
178+
.sendLine(s.srcDir)
179+
.wait('Distribution Directory Path:')
180+
.sendLine(s.distDir)
181+
.wait('Build Command:')
182+
.sendLine(s.buildCmd)
183+
.wait('Start Command:')
184+
.sendLine(s.startCmd);
185+
break;
186+
case 'android':
187+
chain
188+
.wait('Where is your Res directory')
189+
.sendLine(s.srcDir);
190+
break;
191+
case 'ios':
192+
break;
193+
case 'flutter':
194+
chain
195+
.wait('Where do you want to store your configuration file?')
196+
.sendLine(s.srcDir);
197+
break;
198+
default:
199+
throw new Error(`Frontend type ${s.frontendType} is not supported.`);
200+
}
201+
202+
chain
203+
.wait('Successfully made configuration changes to your project.')
204+
.run((err: Error) => {
205+
if (!err) {
206+
resolve();
207+
} else {
208+
reject(err);
209+
}
210+
});
211+
})
212+
}

packages/amplify-codegen-e2e-core/src/init/initProjectHelper.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const defaultSettings = {
88
envName: 'integtest',
99
editor: '\r',
1010
appType: '\r',
11-
framework: '\r',
11+
framework: 'none',
1212
srcDir: '\r',
1313
distDir: '\r',
1414
buildCmd: '\r',
@@ -22,6 +22,8 @@ const defaultSettings = {
2222
providerConfig: undefined,
2323
};
2424

25+
const javaScriptFrameworkList = [ 'none', 'angular', 'ember', 'ionic', 'react', 'react-native', 'vue' ];
26+
2527
export function initJSProjectWithProfile(cwd: string, settings: Object = {}): Promise<void> {
2628
const s = { ...defaultSettings, ...settings };
2729
let env;
@@ -52,8 +54,11 @@ export function initJSProjectWithProfile(cwd: string, settings: Object = {}): Pr
5254
.sendLine(s.editor)
5355
.wait("Choose the type of app that you're building")
5456
.sendLine(s.appType)
55-
.wait('What javascript framework are you using')
56-
.sendLine(s.framework)
57+
.wait('What javascript framework are you using');
58+
59+
singleSelect(chain, s.framework, javaScriptFrameworkList);
60+
61+
chain
5762
.wait('Source Directory Path:')
5863
.sendLine(s.srcDir)
5964
.wait('Distribution Directory Path:')
@@ -73,7 +78,7 @@ export function initJSProjectWithProfile(cwd: string, settings: Object = {}): Pr
7378
}
7479

7580
chain
76-
.wait('Help improve Amplify CLI by sharing non sensitive configurations on failures')
81+
.wait('Help improve Amplify CLI by sharing non-sensitive project configurations on failures')
7782
.sendConfirmYes()
7883
.wait('Try "amplify add api" to create a backend API and then "amplify push" to deploy everything')
7984
.run((err: Error) => {
@@ -115,7 +120,7 @@ export function initAndroidProjectWithProfile(cwd: string, settings: Object): Pr
115120
.sendCarriageReturn()
116121
.wait('Please choose the profile you want to use')
117122
.sendLine(s.profileName)
118-
.wait('Help improve Amplify CLI by sharing non sensitive configurations on failures')
123+
.wait('Help improve Amplify CLI by sharing non-sensitive project configurations on failures')
119124
.sendConfirmYes()
120125
.wait('Try "amplify add api" to create a backend API and then "amplify push" to deploy everything')
121126
.run((err: Error) => {
@@ -157,17 +162,11 @@ export function initIosProjectWithProfile(cwd: string, settings: Object): Promis
157162
.sendCarriageReturn()
158163
.wait('Please choose the profile you want to use')
159164
.sendLine(s.profileName)
160-
.wait('Help improve Amplify CLI by sharing non sensitive configurations on failures')
165+
.wait('Help improve Amplify CLI by sharing non-sensitive project configurations on failures')
161166
.sendConfirmYes()
162167
.wait('Try "amplify add api" to create a backend API and then "amplify push" to deploy everything')
163-
.run((err: Error) => {
164-
if (!err) {
165-
addCITags(cwd);
166-
167-
resolve();
168-
} else {
169-
reject(err);
170-
}
168+
.run(() => {
169+
resolve();
171170
});
172171
});
173172
}
@@ -200,7 +199,7 @@ export function initFlutterProjectWithProfile(cwd: string, settings: Object): Pr
200199
singleSelect(chain, s.region, amplifyRegions);
201200

202201
chain
203-
.wait('Help improve Amplify CLI by sharing non sensitive configurations on failures')
202+
.wait('Help improve Amplify CLI by sharing non-sensitive project configurations on failures')
204203
.sendConfirmYes()
205204
.wait('Try "amplify add api" to create a backend API and then "amplify push" to deploy everything')
206205
.run((err: Error) => {

0 commit comments

Comments
 (0)