@@ -124,32 +124,33 @@ describe('Logger E2E tests, basic functionalities middy usage', () => {
124
124
) ;
125
125
} ) ;
126
126
127
- describe ( 'Log event' , ( ) => {
128
- it (
129
- 'should log the event as the first log of each invocation only' ,
130
- async ( ) => {
131
- for ( let i = 0 ; i < invocationCount ; i ++ ) {
132
- // Get log messages of the invocation
133
- const logMessages = invocationLogs [ i ] . getFunctionLogs ( ) ;
134
-
135
- for ( const [ index , message ] of logMessages . entries ( ) ) {
136
- const log = TestInvocationLogs . parseFunctionLog ( message ) ;
137
- // Check that the event is logged on the first log
138
- if ( index === 0 ) {
139
- expect ( log ) . toHaveProperty ( 'event' ) ;
140
- expect ( log . event ) . toStrictEqual (
141
- expect . objectContaining ( { foo : 'bar' } )
142
- ) ;
143
- // Check that the event is not logged again on the rest of the logs
144
- } else {
145
- expect ( log ) . not . toHaveProperty ( 'event' ) ;
146
- }
147
- }
148
- }
149
- } ,
150
- TEST_CASE_TIMEOUT
151
- ) ;
152
- } ) ;
127
+ it (
128
+ 'logs the event for every invocation, only once, and without keys from previous invocations' ,
129
+ async ( ) => {
130
+ const { RUNTIME_ADDED_KEY : runtimeAddedKey } = commonEnvironmentVars ;
131
+
132
+ for ( let i = 0 ; i < invocationCount ; i ++ ) {
133
+ // Get log messages of the invocation
134
+ const logMessages = invocationLogs [ i ] . getFunctionLogs ( ) ;
135
+
136
+ const eventLog = logMessages . filter ( ( log ) =>
137
+ log . includes ( 'Lambda invocation event' )
138
+ ) ;
139
+
140
+ // Check that the event log is logged only once
141
+ expect ( eventLog ) . toHaveLength ( 1 ) ;
142
+ const log = TestInvocationLogs . parseFunctionLog ( eventLog [ 0 ] ) ;
143
+ // Check that the event log is logged correctly
144
+ expect ( log ) . toHaveProperty ( 'event' ) ;
145
+ expect ( log . event ) . toStrictEqual (
146
+ expect . objectContaining ( { foo : 'bar' } )
147
+ ) ;
148
+ // Check that the event log does not contain keys from previous invocations
149
+ expect ( log ) . not . toHaveProperty ( runtimeAddedKey ) ;
150
+ }
151
+ } ,
152
+ TEST_CASE_TIMEOUT
153
+ ) ;
153
154
154
155
describe ( 'Persistent additional log keys and values' , ( ) => {
155
156
it (
@@ -201,33 +202,6 @@ describe('Logger E2E tests, basic functionalities middy usage', () => {
201
202
} ,
202
203
TEST_CASE_TIMEOUT
203
204
) ;
204
-
205
- it (
206
- 'should not leak any persistent keys added runtime since clearState is enabled' ,
207
- async ( ) => {
208
- const { RUNTIME_ADDED_KEY : runtimeAddedKey } = commonEnvironmentVars ;
209
-
210
- for ( let i = 0 ; i < invocationCount ; i ++ ) {
211
- // Get log messages of the invocation
212
- const logMessages = invocationLogs [ i ] . getFunctionLogs ( ) ;
213
-
214
- for ( const [ index , message ] of logMessages . entries ( ) ) {
215
- const log = TestInvocationLogs . parseFunctionLog ( message ) ;
216
- // Check that at the time of logging the event, which happens before the handler,
217
- // the key is NOT present
218
- if ( index === 0 ) {
219
- expect ( log ) . not . toHaveProperty ( runtimeAddedKey ) ;
220
- } else {
221
- // Check that all other logs that happen at runtime do contain the key
222
- expect ( log ) . toHaveProperty ( runtimeAddedKey ) ;
223
- // Check that the value is the same for all logs
224
- expect ( log [ runtimeAddedKey ] ) . toEqual ( 'bar' ) ;
225
- }
226
- }
227
- }
228
- } ,
229
- TEST_CASE_TIMEOUT
230
- ) ;
231
205
} ) ;
232
206
233
207
describe ( 'One-time additional log keys and values' , ( ) => {
0 commit comments