Skip to content

Commit b5960f8

Browse files
authored
test: include amplify app in smoke tests (#13259)
* test: include amplify app in smoke tests suite * chore: add some prints * test: debug * test: less tests * test: generate * chore: try this * test: try this * test: undo that * chore: why * chore: try that * test: try this * test: try this * test: try this * test: try this * test: try this * test: try this * test: try this * chore: this works * test: try this * test: try this * Revert "test: try this" This reverts commit 4762355. * test: try this
1 parent cf8a76a commit b5960f8

File tree

10 files changed

+301
-226
lines changed

10 files changed

+301
-226
lines changed

.github/actions/run-smoke-tests/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,5 @@ runs:
7070
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce #v3.1.2
7171
if: always()
7272
with:
73-
name: test report
73+
name: test report ${{ runner.os }}
7474
path: packages/amplify-e2e-tests/amplify-e2e-reports

.github/workflows/smoke-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ on:
1919

2020
env:
2121
NODE_OPTIONS: --max-old-space-size=8096
22+
IS_AMPLIFY_CLI_SMOKE_TEST_RUN: true
2223

2324
jobs:
2425
run-smoke-tests:

codebuild_specs/e2e_workflow_generated.yml

Lines changed: 198 additions & 188 deletions
Large diffs are not rendered by default.

codebuild_specs/wait_for_ids.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
"l_schema_model_b_schema_model_d_auth_5f",
139139
"l_schema_predictions_model_migration_auth_3c",
140140
"l_searchable_migration",
141+
"l_smoketest_amplify_app",
141142
"l_storage_1b_function_11_function_2b",
142143
"l_storage_5",
143144
"l_storage_migration_v10",

packages/amplify-e2e-core/src/utils/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ export * from './credentials-rotator';
3636
*/
3737
export const isCI = (): boolean => JSON.parse(process.env.CI || 'false') && JSON.parse(process.env.CIRCLECI || 'false');
3838

39+
/**
40+
* Whether the current run is smoke test run.
41+
*/
42+
export const isSmokeTestRun = (): boolean => JSON.parse(process.env.IS_AMPLIFY_CLI_SMOKE_TEST_RUN || 'false');
43+
3944
// eslint-disable-next-line spellcheck/spell-checker
4045
export const TEST_PROFILE_NAME = isCI() ? 'amplify-integ-test-user' : 'default';
4146

packages/amplify-e2e-tests/src/__tests__/amplify-app.test.ts

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
1-
import {
2-
amplifyAppAndroid,
3-
amplifyAppIos,
4-
amplifyAppAngular,
5-
amplifyAppReact,
6-
amplifyModelgen,
7-
amplifyPush,
8-
addIntegAccountInConfig,
9-
} from '../amplify-app-helpers/amplify-app-setup';
10-
import { createNewProjectDir, deleteProject, deleteProjectDir, isCI } from '@aws-amplify/amplify-e2e-core';
1+
import { amplifyAppAndroid, amplifyAppIos, amplifyAppAngular } from '../amplify-app-helpers/amplify-app-setup';
2+
import { createNewProjectDir, deleteProjectDir, isCI } from '@aws-amplify/amplify-e2e-core';
113
import { AmplifyFrontend } from '@aws-amplify/amplify-cli-core';
124
import {
135
validateProject,
146
validateProjectConfig,
157
validateApi,
168
validateBackendConfig,
17-
validateModelgen,
18-
validateAmplifyPush,
199
validateFeatureFlags,
2010
} from '../amplify-app-helpers/amplify-app-validation';
2111

@@ -30,7 +20,7 @@ describe('amplify-app platform tests', () => {
3020
deleteProjectDir(projRoot);
3121
});
3222

33-
jest.setTimeout(1000 * 60 * 30); // 30 minutes is suffice as push operations are taking time
23+
jest.setTimeout(1000 * 60 * 30); // 30 minutes is enough as push operations are taking time
3424

3525
it('should set up an android project', async () => {
3626
await amplifyAppAndroid(projRoot);
@@ -64,19 +54,4 @@ describe('amplify-app platform tests', () => {
6454
validateBackendConfig(projRoot);
6555
validateFeatureFlags(projRoot);
6656
});
67-
68-
it('should set up a react project and run scripts', async () => {
69-
await amplifyAppReact(projRoot);
70-
validateProject(projRoot, AmplifyFrontend.javascript);
71-
validateProjectConfig(projRoot, AmplifyFrontend.javascript, 'react');
72-
validateApi(projRoot);
73-
validateBackendConfig(projRoot);
74-
validateFeatureFlags(projRoot);
75-
addIntegAccountInConfig(projRoot);
76-
await amplifyModelgen(projRoot);
77-
validateModelgen(projRoot);
78-
await amplifyPush(projRoot);
79-
validateAmplifyPush(projRoot);
80-
await deleteProject(projRoot);
81-
});
8257
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { amplifyAppReact, amplifyModelgen, amplifyPush, addIntegAccountInConfig } from '../../amplify-app-helpers/amplify-app-setup';
2+
import { createNewProjectDir, deleteProject, deleteProjectDir, getCLIPath } from '@aws-amplify/amplify-e2e-core';
3+
import { AmplifyFrontend } from '@aws-amplify/amplify-cli-core';
4+
import {
5+
validateProject,
6+
validateProjectConfig,
7+
validateApi,
8+
validateBackendConfig,
9+
validateModelgen,
10+
validateAmplifyPush,
11+
validateFeatureFlags,
12+
} from '../../amplify-app-helpers/amplify-app-validation';
13+
import execa from 'execa';
14+
15+
describe('amplify-app platform tests', () => {
16+
let projRoot: string;
17+
18+
beforeAll(async () => {
19+
const cliPath = getCLIPath();
20+
const cliVersion = (await execa(cliPath, ['version'])).stdout;
21+
// Print CLI path, CLI version and process.env.AMPLIFY_PATH for reference
22+
// Code generated by amplify-app honors AMPLIFY_PATH env variable
23+
console.log(`amplify-app tests: CLI path ${cliPath}, AMPLIFY_PATH=${process.env.AMPLIFY_PATH}, CLI version ${cliVersion}`);
24+
});
25+
26+
beforeEach(async () => {
27+
projRoot = await createNewProjectDir('amplify-app');
28+
});
29+
30+
afterEach(() => {
31+
deleteProjectDir(projRoot);
32+
});
33+
34+
jest.setTimeout(1000 * 60 * 30); // 30 minutes is enough as push operations are taking time
35+
36+
it('should set up a react project and run scripts', async () => {
37+
await amplifyAppReact(projRoot);
38+
validateProject(projRoot, AmplifyFrontend.javascript);
39+
validateProjectConfig(projRoot, AmplifyFrontend.javascript, 'react');
40+
validateApi(projRoot);
41+
validateBackendConfig(projRoot);
42+
validateFeatureFlags(projRoot);
43+
addIntegAccountInConfig(projRoot);
44+
await amplifyModelgen(projRoot);
45+
validateModelgen(projRoot);
46+
await amplifyPush(projRoot);
47+
validateAmplifyPush(projRoot);
48+
await deleteProject(projRoot);
49+
});
50+
});

packages/amplify-e2e-tests/src/amplify-app-helpers/amplify-app-setup.ts

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1-
import { nspawn as spawn, KEY_DOWN_ARROW, isCI } from '@aws-amplify/amplify-e2e-core';
1+
import { nspawn as spawn, KEY_DOWN_ARROW, isCI, isSmokeTestRun } from '@aws-amplify/amplify-e2e-core';
22
import * as fs from 'fs-extra';
33
import * as path from 'path';
44

5-
const npm = /^win/.test(process.platform) ? 'npm.cmd' : 'npm';
5+
const isRunningOnWindows = /^win/.test(process.platform);
6+
const npm = isRunningOnWindows ? 'npm.cmd' : 'npm';
7+
const npx = isRunningOnWindows ? 'npx.cmd' : 'npx';
68
const amplifyAppBinPath = path.join(__dirname, '..', '..', '..', 'amplify-app', 'bin', 'amplify-app');
7-
const spawnCommand = isCI() ? 'amplify-app' : amplifyAppBinPath;
9+
const getSpawnCommand = () => {
10+
if (isSmokeTestRun()) {
11+
return [npx, 'amplify-app', '--yes'];
12+
} else if (isCI() && !isRunningOnWindows) {
13+
return 'amplify-app';
14+
} else {
15+
return amplifyAppBinPath;
16+
}
17+
};
818

919
function amplifyAppAndroid(projRoot: string): Promise<void> {
1020
return new Promise((resolve, reject) => {
11-
spawn(spawnCommand, ['--platform', 'android'], { cwd: projRoot, stripColors: true })
21+
spawn(getSpawnCommand(), ['--platform', 'android'], { cwd: projRoot, stripColors: true })
1222
.wait('Successfully created base Amplify Project')
1323
.wait('Amplify setup completed successfully')
1424
.run(function (err) {
@@ -23,7 +33,7 @@ function amplifyAppAndroid(projRoot: string): Promise<void> {
2333

2434
function amplifyAppIos(projRoot: string): Promise<void> {
2535
return new Promise((resolve, reject) => {
26-
spawn(spawnCommand, ['--platform', 'ios'], { cwd: projRoot, stripColors: true })
36+
spawn(getSpawnCommand(), ['--platform', 'ios'], { cwd: projRoot, stripColors: true })
2737
.wait('Successfully created base Amplify Project')
2838
.wait('Amplify setup completed successfully')
2939
.run(function (err) {
@@ -38,7 +48,7 @@ function amplifyAppIos(projRoot: string): Promise<void> {
3848

3949
function amplifyAppAngular(projRoot: string): Promise<void> {
4050
return new Promise((resolve, reject) => {
41-
spawn(spawnCommand, [], { cwd: projRoot, stripColors: true })
51+
spawn(getSpawnCommand(), [], { cwd: projRoot, stripColors: true })
4252
.wait('What type of app are you building')
4353
.sendCarriageReturn()
4454
.wait('What javascript framework are you using')
@@ -54,8 +64,24 @@ function amplifyAppAngular(projRoot: string): Promise<void> {
5464
}
5565

5666
function amplifyAppReact(projRoot: string): Promise<void> {
67+
const env: Record<string, string> = {};
68+
if (isSmokeTestRun()) {
69+
// If we're smoke testing we have to prepend a directory component of AMPLIFY_PATH to PATH
70+
// Internally amplify-app spawns 'amplify' which makes OS look into PATH
71+
// However, yarn injects local binaries into PATH as well which makes OS find packages/amplify-cli/bin content
72+
// and packages are not fully built in smoke tests.
73+
// OS traverses PATH from left to right, so prepending forces it to use AMPLIFY_PATH location.
74+
if (!process.env.AMPLIFY_PATH) {
75+
throw new Error('AMPLIFY_PATH must be set in smoke tests');
76+
}
77+
const amplifyPathDir = path.parse(process.env.AMPLIFY_PATH).dir;
78+
let pathEnvVar = process.env.PATH;
79+
const separator = isRunningOnWindows ? ';' : ':';
80+
pathEnvVar = amplifyPathDir + separator + pathEnvVar;
81+
env['PATH'] = pathEnvVar;
82+
}
5783
return new Promise((resolve, reject) => {
58-
spawn(spawnCommand, [], { cwd: projRoot, stripColors: true })
84+
spawn(getSpawnCommand(), [], { cwd: projRoot, stripColors: true, env })
5985
.wait('What type of app are you building')
6086
.sendCarriageReturn()
6187
.wait('What javascript framework are you using')

packages/amplify-e2e-tests/src/amplify-app-helpers/amplify-app-validation.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import * as fs from 'fs-extra';
22
import * as path from 'path';
33
import { AmplifyFrontend, pathManager } from '@aws-amplify/amplify-cli-core';
44

5+
const npm = /^win/.test(process.platform) ? 'npm.cmd' : 'npm';
6+
57
function validateProject(projRoot: string, platform: AmplifyFrontend) {
68
expect(fs.existsSync(path.join(projRoot, 'amplify'))).toBe(true);
79
expect(fs.existsSync(path.join(projRoot, '.gitignore'))).toBe(true);
@@ -46,7 +48,7 @@ function validateProjectConfig(projRoot: string, platform: AmplifyFrontend, fram
4648
break;
4749
case 'react':
4850
expect(config['javascript']['framework']).toBe('react');
49-
expect(config['javascript']['config']['StartCommand']).toBe('npm run-script start');
51+
expect(config['javascript']['config']['StartCommand']).toBe(`${npm} run-script start`);
5052
break;
5153
default:
5254
expect(false).toBe(true);

scripts/split-e2e-tests-codebuild.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ const RUN_SOLO = [
4343
'src/__tests__/transformer-migrations/searchable-migration.test.ts',
4444
'src/__tests__/uibuilder.test.ts',
4545
];
46-
const DISABLE_COVERAGE = ['src/__tests__/datastore-modelgen.test.ts', 'src/__tests__/amplify-app.test.ts'];
46+
const DISABLE_COVERAGE = [
47+
'src/__tests__/datastore-modelgen.test.ts',
48+
'src/__tests__/amplify-app.test.ts',
49+
'src/__tests__/smoke-tests/smoketest-amplify-app.test.ts',
50+
];
4751
const TEST_EXCLUSIONS: { l: string[]; w: string[] } = {
4852
l: [],
4953
w: [
@@ -55,6 +59,7 @@ const TEST_EXCLUSIONS: { l: string[]; w: string[] } = {
5559
'src/__tests__/opensearch-simulator/opensearch-simulator.test.ts',
5660
'src/__tests__/storage-simulator/S3server.test.ts',
5761
'src/__tests__/amplify-app.test.ts',
62+
'src/__tests__/smoke-tests/smoketest-amplify-app.test.ts',
5863
// failing in parsing JSON strings on powershell
5964
'src/__tests__/auth_2g.test.ts',
6065
'src/__tests__/auth_12.test.ts',

0 commit comments

Comments
 (0)