@@ -6,16 +6,22 @@ const {beforeAll, afterAll, test, expect} = require("@jest/globals"),
6
6
7
7
const cloudFormation = new AWS . CloudFormation ( )
8
8
9
+ const isUsingEphemeralStack = ! process . env . hasOwnProperty ( 'STACK_NAME' )
9
10
let stackName
10
11
let apiEndpoint
11
12
12
13
beforeAll ( async ( ) => {
13
- stackName = generateEphemeralStackName ( )
14
+ stackName = isUsingEphemeralStack ? generateEphemeralStackName ( ) : process . env [ 'STACK_NAME' ]
14
15
15
- console . log ( `Starting cloudformation deployment of stack ${ stackName } ` )
16
- const { stdout } = await exec ( `./deploy.sh ${ stackName } ` )
17
- console . log ( 'Deployment finished' )
18
- console . log ( stdout )
16
+ if ( isUsingEphemeralStack ) {
17
+ console . log ( `Starting cloudformation deployment of stack ${ stackName } ` )
18
+ const { stdout } = await exec ( `./deploy.sh ${ stackName } ` )
19
+ console . log ( 'Deployment finished' )
20
+ console . log ( stdout )
21
+ }
22
+ else {
23
+ console . log ( `Using existing stack ${ stackName } as application target` )
24
+ }
19
25
20
26
const cloudformationStacks = await cloudFormation . describeStacks ( { StackName : stackName } ) . promise ( )
21
27
const apiID = cloudformationStacks
@@ -52,8 +58,13 @@ function twoCharacter(number) {
52
58
}
53
59
54
60
afterAll ( async ( ) => {
55
- console . log ( `Calling cloudformation to delete stack ${ stackName } ` )
56
- await cloudFormation . deleteStack ( { StackName : stackName } ) . promise ( )
61
+ if ( isUsingEphemeralStack ) {
62
+ console . log ( `Calling cloudformation to delete stack ${ stackName } ` )
63
+ await cloudFormation . deleteStack ( { StackName : stackName } ) . promise ( )
64
+ }
65
+ else {
66
+ console . log ( `Leaving stack ${ stackName } as deployed` )
67
+ }
57
68
} )
58
69
59
70
test ( 'API should return 200 exit code and expected content' , async ( ) => {
0 commit comments