Skip to content

Commit 60e00fc

Browse files
authored
Merge pull request #597 from aws-amplify/fix-e2e-tests
chore: fix e2e tests related to flutter pubspec file
2 parents bc73678 + bfcab6f commit 60e00fc

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-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: 10 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);
@@ -110,6 +116,10 @@ describe('Amplify pull in sandbox app with codegen tests', () => {
110116
it(`should pull sandbox, download schema and generate models without deleting user files in ${config.frontendType} project`, async () => {
111117
//generate pre existing user file
112118
const userSourceCodePath = generateSourceCode(projectRoot, config.srcDir);
119+
// Flutter projects need min dart version to be met for modelgen to succeed.
120+
if (config?.frontendType === AmplifyFrontend.flutter) {
121+
createPubspecLockFile(projectRoot);
122+
};
113123
//pull sandbox app
114124
await amplifyPullSandbox(projectRoot, {
115125
appType: config.frontendType,

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

Lines changed: 24 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();
@@ -23,14 +25,34 @@ export async function testCodegenModels(config: AmplifyFrontendConfig, projectRo
2325
//generate pre existing user file
2426
const userSourceCodePath = generateSourceCode(projectRoot, config.srcDir);
2527

28+
// For flutter frontend, we need to have a pubspec lock file with supported dart version
29+
if (config?.frontendType === AmplifyFrontend.flutter) {
30+
createPubspecLockFile(projectRoot);
31+
}
32+
2633
//generate models
2734
await expect(generateModels(projectRoot, outputDir)).resolves.not.toThrow();
2835

2936
// pre-existing file should still exist
3037
expect(existsSync(userSourceCodePath)).toBe(true);
38+
3139
// datastore models are generated at correct location
3240
const dirToCheck = outputDir
3341
? path.join(projectRoot, outputDir)
3442
: path.join(projectRoot, config.modelgenDir);
3543
expect(isNotEmptyDir(dirToCheck)).toBe(true);
3644
}
45+
46+
export const createPubspecLockFile = (projectRoot: string) => {
47+
const lockFile = {
48+
packages: {
49+
amplify_flutter: {
50+
version: '2.0.0'
51+
},
52+
},
53+
};
54+
const pubspecPath = path.join(projectRoot, 'pubspec.lock');
55+
if (!existsSync(pubspecPath)) {
56+
writeFileSync(pubspecPath, yaml.dump(lockFile));
57+
}
58+
};

0 commit comments

Comments
 (0)