@@ -24,6 +24,7 @@ import {
2424} from "vitest"
2525import { createApp , type CreateAppParams } from "../../src/apps/createApp"
2626import { AwsSolutionsChecks } from "cdk-nag"
27+ import { ENV_DEFAULT_PREFIX } from "../../src/constants"
2728
2829describe ( "createApp" , ( ) => {
2930 const originalEnv = process . env
@@ -51,10 +52,10 @@ describe("createApp", () => {
5152
5253 describe ( "when all environment variables are set" , ( ) => {
5354 beforeEach ( ( ) => {
54- process . env . CDK_CONFIG_versionNumber = "1.2.3"
55- process . env . CDK_CONFIG_commitId = "abc123def456"
56- process . env . CDK_CONFIG_isPullRequest = "false"
57- process . env . CDK_CONFIG_environment = "test-environment"
55+ process . env [ ` ${ ENV_DEFAULT_PREFIX } versionNumber` ] = "1.2.3"
56+ process . env [ ` ${ ENV_DEFAULT_PREFIX } commitId` ] = "abc123def456"
57+ process . env [ ` ${ ENV_DEFAULT_PREFIX } isPullRequest` ] = "false"
58+ process . env [ ` ${ ENV_DEFAULT_PREFIX } environment` ] = "test-environment"
5859 } )
5960
6061 test ( "creates an App with correct configuration" , ( ) => {
@@ -124,10 +125,10 @@ describe("createApp", () => {
124125
125126 describe ( "when isPullRequest is true" , ( ) => {
126127 beforeEach ( ( ) => {
127- process . env . CDK_CONFIG_versionNumber = "0.0.1-pr"
128- process . env . CDK_CONFIG_commitId = "pr123"
129- process . env . CDK_CONFIG_isPullRequest = "true"
130- process . env . CDK_CONFIG_environment = "test-environment"
128+ process . env [ ` ${ ENV_DEFAULT_PREFIX } versionNumber` ] = "0.0.1-pr"
129+ process . env [ ` ${ ENV_DEFAULT_PREFIX } commitId` ] = "pr123"
130+ process . env [ ` ${ ENV_DEFAULT_PREFIX } isPullRequest` ] = "true"
131+ process . env [ ` ${ ENV_DEFAULT_PREFIX } environment` ] = "test-environment"
131132 } )
132133
133134 test ( "correctly modifies props" , ( ) => {
@@ -159,41 +160,41 @@ describe("createApp", () => {
159160 describe ( "when environment variables are missing" , ( ) => {
160161
161162 test ( "throws error when versionNumber is not set" , ( ) => {
162- process . env . CDK_CONFIG_commitId = "abc123"
163- process . env . CDK_CONFIG_isPullRequest = "false"
164- process . env . CDK_CONFIG_environment = "test-environment"
163+ process . env [ ` ${ ENV_DEFAULT_PREFIX } commitId` ] = "abc123"
164+ process . env [ ` ${ ENV_DEFAULT_PREFIX } isPullRequest` ] = "false"
165+ process . env [ ` ${ ENV_DEFAULT_PREFIX } environment` ] = "test-environment"
165166
166167 expect ( ( ) => {
167168 createApp ( buildParams ( ) )
168- } ) . toThrow ( " Environment variable CDK_CONFIG_versionNumber is not set" )
169+ } ) . toThrow ( ` Environment variable ${ ENV_DEFAULT_PREFIX } versionNumber is not set` )
169170 } )
170171
171172 test ( "throws error when commitId is not set" , ( ) => {
172- process . env . CDK_CONFIG_versionNumber = "1.0.0"
173- process . env . CDK_CONFIG_isPullRequest = "false"
174- process . env . CDK_CONFIG_environment = "test-environment"
173+ process . env [ ` ${ ENV_DEFAULT_PREFIX } versionNumber` ] = "1.0.0"
174+ process . env [ ` ${ ENV_DEFAULT_PREFIX } isPullRequest` ] = "false"
175+ process . env [ ` ${ ENV_DEFAULT_PREFIX } environment` ] = "test-environment"
175176
176177 expect ( ( ) => {
177178 createApp ( buildParams ( ) )
178- } ) . toThrow ( " Environment variable CDK_CONFIG_commitId is not set" )
179+ } ) . toThrow ( ` Environment variable ${ ENV_DEFAULT_PREFIX } commitId is not set` )
179180 } )
180181
181182 test ( "throws error when isPullRequest is not set" , ( ) => {
182- process . env . CDK_CONFIG_versionNumber = "1.0.0"
183- process . env . CDK_CONFIG_commitId = "abc123"
184- process . env . CDK_CONFIG_environment = "test-environment"
183+ process . env [ ` ${ ENV_DEFAULT_PREFIX } versionNumber` ] = "1.0.0"
184+ process . env [ ` ${ ENV_DEFAULT_PREFIX } commitId` ] = "abc123"
185+ process . env [ ` ${ ENV_DEFAULT_PREFIX } environment` ] = "test-environment"
185186 expect ( ( ) => {
186187 createApp ( buildParams ( ) )
187- } ) . toThrow ( " Environment variable CDK_CONFIG_isPullRequest is not set" )
188+ } ) . toThrow ( ` Environment variable ${ ENV_DEFAULT_PREFIX } isPullRequest is not set` )
188189 } )
189190
190191 test ( "throws error when environment is not set" , ( ) => {
191- process . env . CDK_CONFIG_versionNumber = "1.0.0"
192- process . env . CDK_CONFIG_commitId = "abc123"
193- process . env . CDK_CONFIG_isPullRequest = "false"
192+ process . env [ ` ${ ENV_DEFAULT_PREFIX } versionNumber` ] = "1.0.0"
193+ process . env [ ` ${ ENV_DEFAULT_PREFIX } commitId` ] = "abc123"
194+ process . env [ ` ${ ENV_DEFAULT_PREFIX } isPullRequest` ] = "false"
194195 expect ( ( ) => {
195196 createApp ( buildParams ( ) )
196- } ) . toThrow ( " Environment variable CDK_CONFIG_environment is not set" )
197+ } ) . toThrow ( ` Environment variable ${ ENV_DEFAULT_PREFIX } environment is not set` )
197198 } )
198199
199200 } )
0 commit comments