forked from aws-amplify/amplify-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployment.test.ts
191 lines (176 loc) · 6.08 KB
/
deployment.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import { after, afterEach, before, beforeEach, describe, it } from 'node:test';
import {
createTestDirectory,
deleteTestDirectory,
rootTestDir,
} from '../setup_test_directory.js';
import fs from 'fs/promises';
import { shortUuid } from '../short_uuid.js';
import { getTestProjectCreators } from '../test-project-setup/test_project_creator.js';
import { TestProjectBase } from '../test-project-setup/test_project_base.js';
import { PredicatedActionBuilder } from '../process-controller/predicated_action_queue_builder.js';
import { ampxCli } from '../process-controller/process_controller.js';
import path from 'path';
import {
interruptSandbox,
rejectCleanupSandbox,
} from '../process-controller/predicated_action_macros.js';
import assert from 'node:assert';
import { TestBranch, amplifyAppPool } from '../amplify_app_pool.js';
import { BackendIdentifier } from '@aws-amplify/plugin-types';
import { ClientConfigFormat } from '@aws-amplify/client-config';
import { testConcurrencyLevel } from './test_concurrency.js';
import { TestCdkProjectBase } from '../test-project-setup/cdk/test_cdk_project_base.js';
import { getTestCdkProjectCreators } from '../test-project-setup/cdk/test_cdk_project_creator.js';
const testProjectCreators = getTestProjectCreators();
const testCdkProjectCreators = getTestCdkProjectCreators();
void describe('deployment tests', { concurrency: testConcurrencyLevel }, () => {
before(async () => {
await createTestDirectory(rootTestDir);
});
after(async () => {
await deleteTestDirectory(rootTestDir);
});
void describe('amplify deploys', async () => {
testProjectCreators.forEach((testProjectCreator) => {
void describe(`branch deploys ${testProjectCreator.name}`, () => {
let branchBackendIdentifier: BackendIdentifier;
let testBranch: TestBranch;
let testProject: TestProjectBase;
beforeEach(async () => {
testProject = await testProjectCreator.createProject(rootTestDir);
testBranch = await amplifyAppPool.createTestBranch();
branchBackendIdentifier = {
namespace: testBranch.appId,
name: testBranch.branchName,
type: 'branch',
};
});
afterEach(async () => {
await testProject.tearDown(branchBackendIdentifier);
});
void it(`[${testProjectCreator.name}] deploys fully`, async () => {
await testProject.deploy(branchBackendIdentifier);
await testProject.assertPostDeployment(branchBackendIdentifier);
const testBranchDetails = await amplifyAppPool.fetchTestBranchDetails(
testBranch
);
assert.ok(
testBranchDetails.backend?.stackArn,
'branch should have stack associated'
);
assert.ok(
testBranchDetails.backend?.stackArn?.includes(
branchBackendIdentifier.namespace
)
);
assert.ok(
testBranchDetails.backend?.stackArn?.includes(
branchBackendIdentifier.name
)
);
// test generating all client formats
for (const format of [
ClientConfigFormat.DART,
ClientConfigFormat.JSON,
]) {
await ampxCli(
[
'generate',
'outputs',
'--branch',
testBranch.branchName,
'--app-id',
testBranch.appId,
'--format',
format,
],
testProject.projectDirPath
).run();
await testProject.assertClientConfigExists(
testProject.projectDirPath,
format
);
}
});
});
});
void describe('fails on compilation error', async () => {
let testProject: TestProjectBase;
before(async () => {
// any project is fine
testProject = await testProjectCreators[0].createProject(rootTestDir);
await fs.cp(
testProject.sourceProjectAmplifyDirURL,
testProject.projectAmplifyDirPath,
{
recursive: true,
}
);
// inject failure
await fs.appendFile(
path.join(testProject.projectAmplifyDirPath, 'backend.ts'),
"this won't compile"
);
});
void describe('in sequence', { concurrency: false }, () => {
void it('in sandbox deploy', async () => {
await ampxCli(
['sandbox', '--dirToWatch', 'amplify'],
testProject.projectDirPath
)
.do(
new PredicatedActionBuilder().waitForLineIncludes(
'TypeScript validation check failed'
)
)
.do(interruptSandbox())
.do(rejectCleanupSandbox())
.run();
});
void it('in pipeline deploy', async () => {
await assert.rejects(() =>
ampxCli(
[
'pipeline-deploy',
'--branch',
'test-branch',
'--app-id',
`test-${shortUuid()}`,
],
testProject.projectDirPath,
{
env: { CI: 'true' },
}
)
.do(
new PredicatedActionBuilder().waitForLineIncludes(
'TypeScript validation check failed'
)
)
.run()
);
});
});
});
});
void describe('cdk deploys', () => {
testCdkProjectCreators.forEach((testCdkProjectCreator) => {
void describe(`${testCdkProjectCreator.name}`, () => {
let testCdkProject: TestCdkProjectBase;
beforeEach(async () => {
testCdkProject = await testCdkProjectCreator.createProject(
rootTestDir
);
});
afterEach(async () => {
await testCdkProject.tearDown();
});
void it(`deploys`, async () => {
await testCdkProject.deploy();
await testCdkProject.assertPostDeployment();
});
});
});
});
});