Skip to content

Commit 8a7f22e

Browse files
author
Kamil Sobol
authored
Add flag to retain test project deployment. (#2151)
1 parent e4cdb59 commit 8a7f22e

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

.changeset/chilled-clouds-judge.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/integration-tests/README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,25 @@ or `npm run test:dir packages/integration-tests/lib/test-in-memory` (to run them
1717
The create-amplify e2e suite tests the first-time installation and setup of a new amplify backend project. To run this suite, run
1818
`npm run test:dir packages/integration-tests/lib/test-e2e/create_amplify.test.js`
1919

20-
## deployment tests
20+
## deployment and sandbox tests
2121

22-
To run end-to-end deployment tests, credentials to an AWS account must be available on the machine. Any credentials that will be picked up by the
22+
To run end-to-end deployment or sandbox tests, credentials to an AWS account must be available on the machine. Any credentials that will be picked up by the
2323
[default node credential provider](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html) should work.
24-
This include setting environment variables for a default profile.
24+
This includes setting environment variables for a default profile.
2525

26-
To run this suite, run
27-
`npm run test:dir packages/integration-tests/lib/test-e2e/deployment.test.js`
26+
To run deployment suite, run
27+
`npm run test:dir packages/integration-tests/lib/test-e2e/deployment/*.deployment.test.js`
28+
29+
To run sandbox suite, run
30+
`npm run test:dir packages/integration-tests/lib/test-e2e/sandbox/*.sandbox.test.js`
31+
32+
To run deployment or sandbox test for specific project, specify exact test file, for example
33+
`npm run test:dir packages/integration-tests/lib/test-e2e/sandbox/data_storage_auth_with_triggers.sandbox.test.js`
34+
35+
When working locally with sandbox tests, it is sometimes useful to retain deployment of test project to avoid full re-deployments while working
36+
on single test project incrementally. To retain deployment set `AMPLIFY_BACKEND_TESTS_RETAIN_TEST_PROJECT_DEPLOYMENT` environment
37+
variable to `true`. This flag disables project name randomization and deployment cleanup, so that subsequent runs of same test
38+
target the same CFN stacks. This option is not available for deployment tests (hotswap is not going to work there anyway).
2839

2940
## backend-output tests
3041

packages/integration-tests/src/test-e2e/sandbox/sandbox.test.template.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ export const defineSandboxTest = (testProjectCreator: TestProjectCreator) => {
4848
});
4949

5050
after(async () => {
51-
await testProject.tearDown(sandboxBackendIdentifier);
51+
if (
52+
process.env.AMPLIFY_BACKEND_TESTS_RETAIN_TEST_PROJECT_DEPLOYMENT !==
53+
'true'
54+
) {
55+
await testProject.tearDown(sandboxBackendIdentifier);
56+
}
5257
});
5358

5459
void describe('in sequence', { concurrency: false }, () => {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ export const createEmptyAmplifyProject = async (
1919
projectDotAmplifyDir: string;
2020
}> => {
2121
const projectRoot = await fs.mkdtemp(path.join(parentDir, projectDirName));
22-
const projectName = `${TEST_PROJECT_PREFIX}-${projectDirName}-${shortUuid()}`;
22+
let projectName = `${TEST_PROJECT_PREFIX}-${projectDirName}`;
23+
if (
24+
process.env.AMPLIFY_BACKEND_TESTS_RETAIN_TEST_PROJECT_DEPLOYMENT !== 'true'
25+
) {
26+
projectName += `-${shortUuid()}`;
27+
}
2328
await fs.writeFile(
2429
path.join(projectRoot, 'package.json'),
2530
JSON.stringify({ name: projectName, type: 'module' }, null, 2)

0 commit comments

Comments
 (0)