33 *
44 * @group e2e/layers/all
55 */
6- import { App } from 'aws-cdk-lib' ;
7- import { LayerVersion } from 'aws-cdk-lib/aws-lambda' ;
8- import { LayerPublisherStack } from '../../src/layer-publisher-stack' ;
6+ import { join } from 'node:path' ;
97import {
10- TestStack ,
118 TestInvocationLogs ,
12- invokeFunctionOnce ,
9+ TestStack ,
1310 generateTestUniqueName ,
11+ invokeFunctionOnce ,
1412} from '@aws-lambda-powertools/testing-utils' ;
1513import { TestNodejsFunction } from '@aws-lambda-powertools/testing-utils/resources/lambda' ;
14+ import { App } from 'aws-cdk-lib' ;
15+ import { LayerVersion } from 'aws-cdk-lib/aws-lambda' ;
16+ import packageJson from '../../package.json' ;
17+ import { LayerPublisherStack } from '../../src/layer-publisher-stack' ;
1618import {
1719 RESOURCE_NAME_PREFIX ,
1820 SETUP_TIMEOUT ,
1921 TEARDOWN_TIMEOUT ,
2022} from './constants' ;
21- import { join } from 'node:path' ;
22- import packageJson from '../../package.json' ;
2323
2424jest . spyOn ( console , 'log' ) . mockImplementation ( ) ;
2525
@@ -39,7 +39,7 @@ function assertLogs(
3939 *
4040 * The lambda function is invoked once and the logs are collected. The goal of the test is to verify that the layer creation and usage works as expected.
4141 */
42- describe ( ` Layers E2E tests` , ( ) => {
42+ describe ( ' Layers E2E tests' , ( ) => {
4343 const testStack = new TestStack ( {
4444 stackNameProps : {
4545 stackNamePrefix : RESOURCE_NAME_PREFIX ,
@@ -96,7 +96,7 @@ describe(`Layers E2E tests`, () => {
9696 ) ;
9797
9898 // Add a lambda function for each output format to the test stack
99- cases . forEach ( ( outputFormat ) => {
99+ for ( const outputFormat of cases ) {
100100 new TestNodejsFunction (
101101 testStack ,
102102 {
@@ -120,7 +120,7 @@ describe(`Layers E2E tests`, () => {
120120 ...( outputFormat === 'ESM' && { outputFormat : 'ESM' } ) ,
121121 }
122122 ) ;
123- } ) ;
123+ }
124124
125125 // Deploy the test stack
126126 await testStack . deploy ( ) ;
@@ -141,28 +141,31 @@ describe(`Layers E2E tests`, () => {
141141 describe . each ( cases ) (
142142 'utilities tests for %s output format' ,
143143 ( outputFormat ) => {
144- let invocationLogs : TestInvocationLogs ;
145- beforeAll ( ( ) => {
144+ it ( 'should have no errors in the logs, which indicates the pacakges version matches the expected one' , ( ) => {
146145 const maybeInvocationLogs = invocationLogsMap . get ( outputFormat ) ;
147146 assertLogs ( maybeInvocationLogs ) ;
148- invocationLogs = maybeInvocationLogs ;
149- } ) ;
150-
151- it ( 'should have no errors in the logs, which indicates the pacakges version matches the expected one' , ( ) => {
147+ const invocationLogs = maybeInvocationLogs ;
152148 const logs = invocationLogs . getFunctionLogs ( 'ERROR' ) ;
153149
154150 expect ( logs . length ) . toBe ( 0 ) ;
155151 } ) ;
156152
157153 it ( 'should have one warning related to missing Metrics namespace' , ( ) => {
154+ const maybeInvocationLogs = invocationLogsMap . get ( outputFormat ) ;
155+ assertLogs ( maybeInvocationLogs ) ;
156+ const invocationLogs = maybeInvocationLogs ;
158157 const logs = invocationLogs . getFunctionLogs ( 'WARN' ) ;
159158
160159 expect ( logs . length ) . toBe ( 1 ) ;
161160 expect ( logs [ 0 ] ) . toContain ( 'Namespace should be defined, default used' ) ;
162161 } ) ;
163162
164163 it ( 'should have one info log related to coldstart metric' , ( ) => {
164+ const maybeInvocationLogs = invocationLogsMap . get ( outputFormat ) ;
165+ assertLogs ( maybeInvocationLogs ) ;
166+ const invocationLogs = maybeInvocationLogs ;
165167 const logs = invocationLogs . getFunctionLogs ( ) ;
168+
166169 const emfLogEntry = logs . find ( ( log ) =>
167170 log . match (
168171 / { " _ a w s " : { " T i m e s t a m p " : \d + , " C l o u d W a t c h M e t r i c s " : \[ \{ " N a m e s p a c e " : " \S + " , " D i m e n s i o n s " : \[ \[ " s e r v i c e " \] \] , " M e t r i c s " : \[ \{ " N a m e " : " C o l d S t a r t " , " U n i t " : " C o u n t " \} \] \} \] } , " s e r v i c e " : " \S + " , " C o l d S t a r t " : 1 } /
@@ -173,6 +176,9 @@ describe(`Layers E2E tests`, () => {
173176 } ) ;
174177
175178 it ( 'should have one debug log with tracer subsegment info' , ( ) => {
179+ const maybeInvocationLogs = invocationLogsMap . get ( outputFormat ) ;
180+ assertLogs ( maybeInvocationLogs ) ;
181+ const invocationLogs = maybeInvocationLogs ;
176182 const logs = invocationLogs . getFunctionLogs ( 'DEBUG' ) ;
177183
178184 expect ( logs . length ) . toBe ( 1 ) ;
0 commit comments