Skip to content

Commit 80404a3

Browse files
committed
test: fix android and flutter e2e tests
1 parent bc73678 commit 80404a3

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ function initializeFrontend(chain: ExecutionContext, config: AmplifyFrontendConf
116116
switch (config.frontendType) {
117117
case AmplifyFrontend.android:
118118
chain
119-
.send('j')
120-
.sendCarriageReturn()
119+
.sendLine('android')
121120
.wait('Where is your Res directory')
122121
.sendCarriageReturn()
123122
return;

packages/amplify-codegen-e2e-tests/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"graphql-tag": "^2.10.1",
3535
"lodash": "^4.17.19",
3636
"uuid": "^3.4.0",
37-
"yargs": "^15.1.0"
37+
"yargs": "^15.1.0",
38+
"js-yaml": "^4.0.0"
3839
},
3940
"devDependencies": {
4041
"@types/jest": "^27.0.0",

packages/amplify-codegen-e2e-tests/src/__tests__/pull-codegen.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ import {
1717
getAdminApp,
1818
amplifyPullSandbox,
1919
getProjectSchema,
20+
AmplifyFrontend,
2021
} from '@aws-amplify/amplify-codegen-e2e-core';
2122
import { existsSync } from 'fs';
2223
import path from 'path';
2324
import { isNotEmptyDir, generateSourceCode } from '../utils';
2425
import { JSONUtilities } from '@aws-amplify/amplify-cli-core';
2526
import { SandboxApp } from '../types/SandboxApp';
27+
import { createPubspecLockFile } from '../codegen-tests-base';
2628

2729
const schema = 'simple_model.graphql';
2830
const envName = 'pulltest';
@@ -72,6 +74,10 @@ describe('Amplify pull in amplify app with codegen tests', () => {
7274
it(`should generate models and do not delete user files by amplify pull in an empty folder of ${config.frontendType} app`, async () => {
7375
//generate pre existing user file
7476
const userSourceCodePath = generateSourceCode(emptyProjectRoot, config.srcDir);
77+
// Flutter projects need min dart version to be met for modelgen to succeed.
78+
if (config?.frontendType === AmplifyFrontend.flutter) {
79+
createPubspecLockFile(emptyProjectRoot);
80+
};
7581
//amplify pull in a new project
7682
await amplifyPull(emptyProjectRoot, { emptyDir: true, appId, frontendConfig: config });
7783
expect(existsSync(userSourceCodePath)).toBe(true);

packages/amplify-codegen-e2e-tests/src/codegen-tests-base/datastore-modelgen.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import {
44
updateApiSchema,
55
createRandomName,
66
generateModels,
7-
AmplifyFrontendConfig
7+
AmplifyFrontendConfig,
8+
AmplifyFrontend
89
} from '@aws-amplify/amplify-codegen-e2e-core';
9-
import { existsSync } from "fs";
10+
import { existsSync, writeFileSync } from "fs";
1011
import path from 'path';
1112
import { isNotEmptyDir, generateSourceCode } from '../utils';
13+
const yaml = require('js-yaml');
1214

1315
export async function testCodegenModels(config: AmplifyFrontendConfig, projectRoot: string, schema: string, outputDir?: string) {
1416
const name = createRandomName();
@@ -28,9 +30,28 @@ export async function testCodegenModels(config: AmplifyFrontendConfig, projectRo
2830

2931
// pre-existing file should still exist
3032
expect(existsSync(userSourceCodePath)).toBe(true);
33+
34+
// For flutter frontend, we need to have a pubspec lock file with supported dart version
35+
if (config?.frontendType === AmplifyFrontend.flutter) {
36+
createPubspecLockFile(projectRoot);
37+
}
3138
// datastore models are generated at correct location
3239
const dirToCheck = outputDir
3340
? path.join(projectRoot, outputDir)
3441
: path.join(projectRoot, config.modelgenDir);
3542
expect(isNotEmptyDir(dirToCheck)).toBe(true);
3643
}
44+
45+
export const createPubspecLockFile = (projectRoot: string) => {
46+
const lockFile = {
47+
packages: {
48+
amplify_flutter: {
49+
version: '2.0.0'
50+
},
51+
},
52+
};
53+
const pubspecPath = path.join(projectRoot, 'pubspec.lock');
54+
if (!existsSync(pubspecPath)) {
55+
writeFileSync(pubspecPath, yaml.dump(lockFile));
56+
}
57+
};

0 commit comments

Comments
 (0)