Skip to content

Commit 733518a

Browse files
authored
test: add e2e testing for config generation (#682)
* test: add e2e testing for config generation * remove unused imports * test * fix tests * fix tests * use getClientConfigPath in assertPostDeployment * remove unused import * remove createProject from MinimalWithTypescriptIdiomTestProject * remove sandbox config test and move testing all config formats to pipeline deploy test * remove unused import * add new method for asserting client config generation
1 parent 85e6191 commit 733518a

File tree

8 files changed

+74
-21
lines changed

8 files changed

+74
-21
lines changed

.changeset/gold-dancers-punch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/integration-tests': patch
3+
---
4+
5+
Add e2e testing for config generation

package-lock.json

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/integration-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"@aws-amplify/backend-auth": "0.3.3",
99
"@aws-amplify/backend-secret": "^0.3.0",
1010
"@aws-amplify/backend-storage": "0.3.0",
11+
"@aws-amplify/client-config": "^0.4.0",
1112
"@aws-amplify/data-schema": "^0.12.9",
1213
"@aws-sdk/client-amplify": "^3.440.0",
1314
"@aws-sdk/client-cloudformation": "^3.421.0",

packages/integration-tests/src/test-e2e/deployment.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
import assert from 'node:assert';
2222
import { TestBranch, amplifyAppPool } from '../amplify_app_pool.js';
2323
import { BackendIdentifier } from '@aws-amplify/plugin-types';
24+
import { ClientConfigFormat } from '@aws-amplify/client-config';
2425
import { testConcurrencyLevel } from './test_concurrency.js';
2526

2627
const testProjectCreators = getTestProjectCreators();
@@ -75,6 +76,28 @@ void describe(
7576
branchBackendIdentifier.name
7677
)
7778
);
79+
80+
// test generating all client formats
81+
for (const format of Object.values(ClientConfigFormat)) {
82+
await amplifyCli(
83+
[
84+
'generate',
85+
'config',
86+
'--branch',
87+
testBranch.branchName,
88+
'--app-id',
89+
testBranch.appId,
90+
'--format',
91+
format,
92+
],
93+
testProject.projectDirPath
94+
).run();
95+
96+
await testProject.assertClientConfigExists(
97+
testProject.projectDirPath,
98+
format
99+
);
100+
}
78101
});
79102
});
80103
});

packages/integration-tests/src/test-project-setup/data_storage_auth_with_triggers.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,4 @@ class DataStorageAuthWithTriggerTestProject extends TestProjectBase {
154154
await this.secretClient.removeSecret(backendId, secretName);
155155
}
156156
};
157-
158-
assertPostDeployment = async (): Promise<void> => {
159-
const clientConfig = await fs.readFile(
160-
path.join(this.projectDirPath, 'amplifyconfiguration.json'),
161-
'utf-8'
162-
);
163-
// check that the client config is a valid json object
164-
// we're not validating content here because it was causing e2e noise for small updates without providing value
165-
// individual components of the client config are tested at the unit / integration level
166-
JSON.parse(clientConfig);
167-
};
168157
}

packages/integration-tests/src/test-project-setup/minimal_with_typescript_idioms.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { TestProjectBase } from './test_project_base.js';
22
import fs from 'fs/promises';
3-
import assert from 'node:assert';
4-
import path from 'path';
53
import { createEmptyAmplifyProject } from './create_empty_amplify_project.js';
64
import { CloudFormationClient } from '@aws-sdk/client-cloudformation';
75
import { TestProjectCreator } from './test_project_creator.js';
@@ -65,11 +63,4 @@ class MinimalWithTypescriptIdiomTestProject extends TestProjectBase {
6563
) {
6664
super(name, projectDirPath, projectAmplifyDirPath, cfnClient);
6765
}
68-
69-
assertPostDeployment = async (): Promise<void> => {
70-
const clientConfigStats = await fs.stat(
71-
path.join(this.projectDirPath, 'amplifyconfiguration.json')
72-
);
73-
assert.ok(clientConfigStats.isFile());
74-
};
7566
}

packages/integration-tests/src/test-project-setup/test_project_base.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { BackendIdentifierConversions } from '@aws-amplify/platform-core';
22
import { BackendIdentifier } from '@aws-amplify/plugin-types';
3+
import {
4+
ClientConfigFormat,
5+
getClientConfigPath,
6+
} from '@aws-amplify/client-config';
37
import { amplifyCli } from '../process-controller/process_controller.js';
48
import {
59
confirmDeleteSandbox,
@@ -12,6 +16,8 @@ import {
1216
CloudFormationClient,
1317
DeleteStackCommand,
1418
} from '@aws-sdk/client-cloudformation';
19+
import fsp from 'fs/promises';
20+
import assert from 'node:assert';
1521

1622
/**
1723
* Keeps test project update info.
@@ -26,7 +32,6 @@ export type TestProjectUpdate = {
2632
* The base abstract class for test project.
2733
*/
2834
export abstract class TestProjectBase {
29-
abstract assertPostDeployment: () => Promise<void>;
3035
abstract readonly sourceProjectAmplifyDirPath: URL;
3136

3237
/**
@@ -90,4 +95,25 @@ export abstract class TestProjectBase {
9095
async getUpdates(): Promise<TestProjectUpdate[]> {
9196
return [];
9297
}
98+
99+
/**
100+
* Verify the project after deployment.
101+
*/
102+
async assertPostDeployment(): Promise<void> {
103+
await this.assertClientConfigExists(
104+
this.projectDirPath,
105+
ClientConfigFormat.JSON
106+
);
107+
}
108+
109+
/**
110+
* Verify client config file is generated with the provided directory and format.
111+
*/
112+
async assertClientConfigExists(dir?: string, format?: ClientConfigFormat) {
113+
const clientConfigStats = await fsp.stat(
114+
await getClientConfigPath(dir ?? this.projectDirPath, format)
115+
);
116+
117+
assert.ok(clientConfigStats.isFile());
118+
}
93119
}

packages/integration-tests/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
{ "path": "../backend-auth" },
77
{ "path": "../backend-secret" },
88
{ "path": "../backend-storage" },
9+
{ "path": "../client-config" },
910
{ "path": "../platform-core" }
1011
],
1112
"exclude": ["**/node_modules", "**/lib", "src/e2e-tests", "test-projects"]

0 commit comments

Comments
 (0)