@@ -17,6 +17,7 @@ const mockEcsDescribeServices = jest.fn();
17
17
const mockCodeDeployCreateDeployment = jest . fn ( ) ;
18
18
const mockCodeDeployGetDeploymentGroup = jest . fn ( ) ;
19
19
const mockRunTask = jest . fn ( ) ;
20
+ const mockWaitUntilTasksStopped = jest . fn ( ) . mockRejectedValue ( new Error ( 'failed' ) ) ;
20
21
const mockEcsDescribeTasks = jest . fn ( ) ;
21
22
const config = {
22
23
region : ( ) => Promise . resolve ( 'fake-region' ) ,
@@ -38,6 +39,7 @@ describe('Deploy to ECS', () => {
38
39
describeServices : mockEcsDescribeServices ,
39
40
describeTasks : mockEcsDescribeTasks ,
40
41
runTask : mockRunTask ,
42
+ waitUntilTasksStopped : mockWaitUntilTasksStopped ,
41
43
} ;
42
44
43
45
const mockCodeDeployClient = {
@@ -1255,6 +1257,42 @@ describe('Deploy to ECS', () => {
1255
1257
expect ( waitUntilTasksStopped ) . toHaveBeenCalledTimes ( 1 ) ;
1256
1258
} ) ;
1257
1259
1260
+
1261
+ test ( 'error is caught if run task fails with (wait-for-task-stopped: true)' , async ( ) => {
1262
+ mockEcsDescribeTasks . mockImplementation (
1263
+ ( ) => Promise . resolve ( {
1264
+ failures : [ {
1265
+ reason : 'TASK_FAILED' ,
1266
+ arn : "arn:aws:ecs:us-east-1:111122223333:task-definition/TaskFamilyName:* is TASK_FAILED"
1267
+ } ] ,
1268
+ tasks : [ ] ,
1269
+ executionStoppedAt : 1
1270
+
1271
+ } )
1272
+ ) ;
1273
+
1274
+ await run ( ) ;
1275
+ expect ( core . setFailed ) . toHaveBeenCalledTimes ( 0 ) ;
1276
+ expect ( mockEcsDescribeTasks ) . toHaveBeenCalledTimes ( 0 ) ;
1277
+
1278
+ } ) ;
1279
+
1280
+ test ( 'error is caught if run task fails with (wait-for-task-stopped: true) and with service' , async ( ) => {
1281
+ mockEcsDescribeTasks . mockImplementation (
1282
+ ( ) => Promise . resolve ( {
1283
+ failures : [ {
1284
+ reason : 'SERVICE_FAILED' ,
1285
+ arn : "arn:aws:ecs:us-east-1:111122223333:service/ServiceName"
1286
+ } ] ,
1287
+ services : [ ] ,
1288
+ } )
1289
+ ) ;
1290
+
1291
+ await run ( ) ;
1292
+ expect ( core . setFailed ) . toHaveBeenCalledTimes ( 0 ) ;
1293
+ expect ( mockEcsDescribeTasks ) . toHaveBeenCalledTimes ( 0 ) ;
1294
+ } ) ;
1295
+
1258
1296
test ( 'error caught if AppSpec file is not formatted correctly' , async ( ) => {
1259
1297
mockEcsDescribeServices . mockImplementation (
1260
1298
( ) => Promise . resolve ( {
0 commit comments