forked from aws-amplify/amplify-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sandbox.test.ts
110 lines (99 loc) · 3.7 KB
/
sandbox.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { after, before, describe, it } from 'node:test';
import {
createTestDirectory,
deleteTestDirectory,
rootTestDir,
} from '../setup_test_directory.js';
import { getTestProjectCreators } from '../test-project-setup/test_project_creator.js';
import { TestProjectBase } from '../test-project-setup/test_project_base.js';
import { userInfo } from 'os';
import { ampxCli } from '../process-controller/process_controller.js';
import {
ensureDeploymentTimeLessThan,
interruptSandbox,
rejectCleanupSandbox,
replaceFiles,
waitForConfigUpdateAfterDeployment,
} from '../process-controller/predicated_action_macros.js';
import { BackendIdentifier } from '@aws-amplify/plugin-types';
import { testConcurrencyLevel } from './test_concurrency.js';
import {
amplifySharedSecretNameKey,
createAmplifySharedSecretName,
} from '../shared_secret.js';
const testProjectCreators = getTestProjectCreators();
void describe('sandbox tests', { concurrency: testConcurrencyLevel }, () => {
before(async () => {
await createTestDirectory(rootTestDir);
});
after(async () => {
await deleteTestDirectory(rootTestDir);
});
void describe('amplify deploys', async () => {
testProjectCreators.forEach((testProjectCreator) => {
void describe(`sandbox deploys ${testProjectCreator.name}`, () => {
let testProject: TestProjectBase;
let sandboxBackendIdentifier: BackendIdentifier;
before(async () => {
testProject = await testProjectCreator.createProject(rootTestDir);
sandboxBackendIdentifier = {
type: 'sandbox',
namespace: testProject.name,
name: userInfo().username,
};
});
after(async () => {
await testProject.tearDown(sandboxBackendIdentifier);
});
void describe('in sequence', { concurrency: false }, () => {
const sharedSecretsEnv = {
[amplifySharedSecretNameKey]: createAmplifySharedSecretName(),
};
void it(`[${testProjectCreator.name}] deploys fully`, async () => {
await testProject.deploy(
sandboxBackendIdentifier,
sharedSecretsEnv
);
await testProject.assertPostDeployment(sandboxBackendIdentifier);
});
void it('generates config after sandbox --once deployment', async () => {
const processController = ampxCli(
['sandbox', '--once'],
testProject.projectDirPath,
{
env: sharedSecretsEnv,
}
);
await processController
.do(waitForConfigUpdateAfterDeployment())
.run();
await testProject.assertPostDeployment(sandboxBackendIdentifier);
});
void it(`[${testProjectCreator.name}] hot-swaps a change`, async () => {
const updates = await testProject.getUpdates();
if (updates.length > 0) {
const processController = ampxCli(
['sandbox', '--dirToWatch', 'amplify'],
testProject.projectDirPath,
{
env: sharedSecretsEnv,
}
);
for (const update of updates) {
processController
.do(replaceFiles(update.replacements))
.do(ensureDeploymentTimeLessThan(update.deployThresholdSec));
}
// Execute the process.
await processController
.do(interruptSandbox())
.do(rejectCleanupSandbox())
.run();
await testProject.assertPostDeployment(sandboxBackendIdentifier);
}
});
});
});
});
});
});