@@ -17,6 +17,25 @@ describe('Middy middleware', () => {
17
17
18
18
describe ( 'logMetrics' , ( ) => {
19
19
20
+ const event = { foo : 'bar' } ;
21
+ const getRandomInt = ( ) : number => Math . floor ( Math . random ( ) * 1000000000 ) ;
22
+ const awsRequestId = getRandomInt ( ) . toString ( ) ;
23
+
24
+ const context = {
25
+ callbackWaitsForEmptyEventLoop : true ,
26
+ functionVersion : '$LATEST' ,
27
+ functionName : 'foo-bar-function' ,
28
+ memoryLimitInMB : '128' ,
29
+ logGroupName : '/aws/lambda/foo-bar-function' ,
30
+ logStreamName : '2021/03/09/[$LATEST]abcdef123456abcdef123456abcdef123456' ,
31
+ invokedFunctionArn : 'arn:aws:lambda:eu-central-1:123456789012:function:foo-bar-function' ,
32
+ awsRequestId : awsRequestId ,
33
+ getRemainingTimeInMillis : ( ) => 1234 ,
34
+ done : ( ) => console . log ( 'Done!' ) ,
35
+ fail : ( ) => console . log ( 'Failed!' ) ,
36
+ succeed : ( ) => console . log ( 'Succeeded!' ) ,
37
+ } ;
38
+
20
39
test ( 'when a metrics instance is passed WITH custom options, it prints the metrics in the stdout' , async ( ) => {
21
40
22
41
// Prepare
@@ -32,24 +51,6 @@ describe('Middy middleware', () => {
32
51
captureColdStartMetric : true
33
52
} ;
34
53
const handler = middy ( lambdaHandler ) . use ( logMetrics ( metrics , metricsOptions ) ) ;
35
- const event = { foo : 'bar' } ;
36
- const getRandomInt = ( ) : number => Math . floor ( Math . random ( ) * 1000000000 ) ;
37
-
38
- const awsRequestId = getRandomInt ( ) . toString ( ) ;
39
- const context = {
40
- callbackWaitsForEmptyEventLoop : true ,
41
- functionVersion : '$LATEST' ,
42
- functionName : 'foo-bar-function' ,
43
- memoryLimitInMB : '128' ,
44
- logGroupName : '/aws/lambda/foo-bar-function' ,
45
- logStreamName : '2021/03/09/[$LATEST]abcdef123456abcdef123456abcdef123456' ,
46
- invokedFunctionArn : 'arn:aws:lambda:eu-central-1:123456789012:function:foo-bar-function' ,
47
- awsRequestId : awsRequestId ,
48
- getRemainingTimeInMillis : ( ) => 1234 ,
49
- done : ( ) => console . log ( 'Done!' ) ,
50
- fail : ( ) => console . log ( 'Failed!' ) ,
51
- succeed : ( ) => console . log ( 'Succeeded!' ) ,
52
- } ;
53
54
54
55
// Act
55
56
await handler ( event , context , ( ) => console . log ( 'Lambda invoked!' ) ) ;
@@ -102,24 +103,6 @@ describe('Middy middleware', () => {
102
103
} ;
103
104
104
105
const handler = middy ( lambdaHandler ) . use ( logMetrics ( metrics ) ) ;
105
- const event = { foo : 'bar' } ;
106
- const getRandomInt = ( ) : number => Math . floor ( Math . random ( ) * 1000000000 ) ;
107
-
108
- const awsRequestId = getRandomInt ( ) . toString ( ) ;
109
- const context = {
110
- callbackWaitsForEmptyEventLoop : true ,
111
- functionVersion : '$LATEST' ,
112
- functionName : 'foo-bar-function' ,
113
- memoryLimitInMB : '128' ,
114
- logGroupName : '/aws/lambda/foo-bar-function' ,
115
- logStreamName : '2021/03/09/[$LATEST]abcdef123456abcdef123456abcdef123456' ,
116
- invokedFunctionArn : 'arn:aws:lambda:eu-central-1:123456789012:function:foo-bar-function' ,
117
- awsRequestId : awsRequestId ,
118
- getRemainingTimeInMillis : ( ) => 1234 ,
119
- done : ( ) => console . log ( 'Done!' ) ,
120
- fail : ( ) => console . log ( 'Failed!' ) ,
121
- succeed : ( ) => console . log ( 'Succeeded!' ) ,
122
- } ;
123
106
124
107
// Act
125
108
await handler ( event , context , ( ) => console . log ( 'Lambda invoked!' ) ) ;
@@ -155,24 +138,6 @@ describe('Middy middleware', () => {
155
138
raiseOnEmptyMetrics : true
156
139
} ;
157
140
const handler = middy ( lambdaHandler ) . use ( logMetrics ( [ metrics ] , metricsOptions ) ) ;
158
- const event = { foo : 'bar' } ;
159
- const getRandomInt = ( ) : number => Math . floor ( Math . random ( ) * 1000000000 ) ;
160
-
161
- const awsRequestId = getRandomInt ( ) . toString ( ) ;
162
- const context = {
163
- callbackWaitsForEmptyEventLoop : true ,
164
- functionVersion : '$LATEST' ,
165
- functionName : 'foo-bar-function' ,
166
- memoryLimitInMB : '128' ,
167
- logGroupName : '/aws/lambda/foo-bar-function' ,
168
- logStreamName : '2021/03/09/[$LATEST]abcdef123456abcdef123456abcdef123456' ,
169
- invokedFunctionArn : 'arn:aws:lambda:eu-central-1:123456789012:function:foo-bar-function' ,
170
- awsRequestId : awsRequestId ,
171
- getRemainingTimeInMillis : ( ) => 1234 ,
172
- done : ( ) => console . log ( 'Done!' ) ,
173
- fail : ( ) => console . log ( 'Failed!' ) ,
174
- succeed : ( ) => console . log ( 'Succeeded!' ) ,
175
- } ;
176
141
177
142
// Act
178
143
await handler ( event , context , ( ) => console . log ( 'Lambda invoked!' ) ) ;
0 commit comments