@@ -13,6 +13,14 @@ import {
1313 ResourceNotFoundException ,
1414} from "@aws-sdk/client-lambda" ;
1515
16+ import dotenv from "dotenv" ;
17+ const __filename = fileURLToPath ( import . meta. url ) ;
18+ const __dirname = dirname ( __filename ) ;
19+
20+ dotenv . config ( {
21+ path : join ( __dirname , "../../../../.env" ) ,
22+ } ) ;
23+
1624// Colors for output
1725const COLORS = {
1826 RED : "\x1b[0;31m" ,
@@ -33,9 +41,6 @@ const log = {
3341 console . error ( `${ COLORS . RED } [ERROR]${ COLORS . NC } ${ msg } ` ) ,
3442} ;
3543
36- const __filename = fileURLToPath ( import . meta. url ) ;
37- const __dirname = dirname ( __filename ) ;
38-
3944// Configuration
4045const CONFIG = {
4146 AWS_REGION : process . env . AWS_REGION || "us-east-1" ,
@@ -62,20 +67,17 @@ class IntegrationTestRunner {
6267 this . cleanupOnExit = options . cleanupOnExit !== false ;
6368 this . runtime = options . runtime ;
6469 this . isGitHubActions = ! ! process . env . GITHUB_ACTIONS ;
65- /** @type {Record<string, string> | undefined } */
70+ /** @type {Record<string, {functionName: string, qualifier: string} > | undefined } */
6671 this . functionNameMap = undefined ;
6772 /** @type {import('@aws-sdk/client-lambda').LambdaClient | null } */
6873 this . lambdaClient = null ;
6974
7075 // Set up cleanup handler
7176 if ( this . cleanupOnExit ) {
72- process . on ( "exit" , ( ) => this . cleanup ( ) ) ;
7377 process . on ( "SIGINT" , ( ) => {
74- this . cleanup ( ) ;
7578 process . exit ( 130 ) ;
7679 } ) ;
7780 process . on ( "SIGTERM" , ( ) => {
78- this . cleanup ( ) ;
7981 process . exit ( 143 ) ;
8082 } ) ;
8183 }
@@ -140,7 +142,7 @@ class IntegrationTestRunner {
140142 }
141143
142144 const examples = this . getIntegrationExamples ( ) ;
143- /** @type {Record<string, string> } */
145+ /** @type {Record<string, {functionName: string, qualifier: string} > } */
144146 const functionNameMap = { } ;
145147
146148 // Get runtime suffix from argument or environment variable
@@ -173,15 +175,23 @@ class IntegrationTestRunner {
173175 }
174176
175177 const handlerFile = exampleHandler . replace ( / \. h a n d l e r $ / , "" ) ;
176- functionNameMap [ handlerFile ] = functionName ;
178+ functionNameMap [ handlerFile ] = {
179+ functionName,
180+ qualifier : example . capacityProviderConfig
181+ ? "$LATEST.PUBLISHED"
182+ : "$LATEST" ,
183+ } ;
177184 }
178185
179186 this . functionNameMap = functionNameMap ;
180187 return functionNameMap ;
181188 }
182189
183- // Deploy Lambda functions
184- async deployFunctions ( ) {
190+ /**
191+ * Deploy Lambda functions
192+ * @param {string | undefined } testPattern
193+ */
194+ async deployFunctions ( testPattern ) {
185195 log . info ( "Deploying Lambda functions..." ) ;
186196
187197 if ( ! process . env . AWS_ACCOUNT_ID ) {
@@ -198,27 +208,28 @@ class IntegrationTestRunner {
198208
199209 // Extract handler file name from catalog
200210 const handlerFile = exampleHandler . replace ( / \. h a n d l e r $ / , "" ) ;
201- const functionName = functionNameMap [ handlerFile ] ;
211+ const { functionName } = functionNameMap [ handlerFile ] ;
202212
203- log . info ( `Deploying function: ${ functionName } (handler: ${ handlerFile } )` ) ;
213+ if ( ! testPattern || handlerFile . includes ( testPattern ) ) {
214+ log . info (
215+ `Deploying function: ${ functionName } (handler: ${ handlerFile } )` ,
216+ ) ;
204217
205- // Package the function
206- this . execCommand ( `npm run package -- "${ handlerFile } "` , {
207- cwd : examplesDir ,
208- } ) ;
218+ // Package the function
219+ this . execCommand ( `npm run package -- "${ handlerFile } "` , {
220+ cwd : examplesDir ,
221+ } ) ;
209222
210- // Deploy using npm script with runtime parameter
211- const deployCommand = `npm run deploy -- "${ handlerFile } " '${ functionName } ' --runtime ${ this . runtime } ` ;
223+ // Deploy using npm script with runtime parameter
224+ const deployCommand = `npm run deploy -- "${ handlerFile } " '${ functionName } ' --runtime ${ this . runtime } ` ;
212225
213- this . execCommand ( deployCommand , {
214- cwd : examplesDir ,
215- } ) ;
216- log . success ( `Deployed function: ${ functionName } ` ) ;
226+ this . execCommand ( deployCommand , {
227+ cwd : examplesDir ,
228+ } ) ;
229+ log . success ( `Deployed function: ${ functionName } ` ) ;
230+ }
217231 }
218232
219- log . info ( "Function name map:" ) ;
220- console . log ( JSON . stringify ( functionNameMap , null , 2 ) ) ;
221-
222233 if ( this . isGitHubActions ) {
223234 if ( ! process . env . GITHUB_OUTPUT ) {
224235 throw new Error ( "Could not find GITHUB_OUTPUT environment variable" ) ;
@@ -239,9 +250,11 @@ class IntegrationTestRunner {
239250 const examplesDir = CONFIG . EXAMPLES_PACKAGE_PATH ;
240251
241252 const functionsWithQualifier = Object . fromEntries (
242- Object . entries ( this . getFunctionNameMap ( ) ) . map ( ( [ key , value ] ) => {
243- return [ key , `${ value } :$LATEST` ] ;
244- } ) ,
253+ Object . entries ( this . getFunctionNameMap ( ) ) . map (
254+ ( [ key , { functionName, qualifier } ] ) => {
255+ return [ key , `${ functionName } :${ qualifier } ` ] ;
256+ } ,
257+ ) ,
245258 ) ;
246259
247260 // Set additional environment variables
@@ -250,8 +263,6 @@ class IntegrationTestRunner {
250263 LAMBDA_ENDPOINT : CONFIG . LAMBDA_ENDPOINT ,
251264 } ;
252265
253- log . info ( "Running Jest integration tests with function map:" ) ;
254- console . log ( JSON . stringify ( functionsWithQualifier , null , 2 ) ) ;
255266 log . info ( `Lambda Endpoint: ${ CONFIG . LAMBDA_ENDPOINT } ` ) ;
256267
257268 // Build test command with optional pattern
@@ -282,7 +293,7 @@ class IntegrationTestRunner {
282293 // Initialize Lambda client for cleanup
283294 const lambdaClient = this . initializeLambdaClient ( ) ;
284295
285- for ( const functionName of Object . values ( functionNameMap ) ) {
296+ for ( const { functionName } of Object . values ( functionNameMap ) ) {
286297 log . info ( `Deleting function: ${ functionName } ` ) ;
287298
288299 const deleteCommand = new DeleteFunctionCommand ( {
@@ -329,7 +340,7 @@ class IntegrationTestRunner {
329340 }
330341
331342 if ( ! testOnly ) {
332- await this . deployFunctions ( ) ;
343+ await this . deployFunctions ( testPattern ) ;
333344 }
334345
335346 if ( ! deployOnly ) {
0 commit comments