@@ -3,14 +3,27 @@ import middy from '@middy/core';
3
3
import { Tracer } from './../../src' ;
4
4
import type { Context , Handler } from 'aws-lambda/handler' ;
5
5
import { Segment , setContextMissingStrategy , Subsegment } from 'aws-xray-sdk-core' ;
6
- import { ContextExamples } from '@aws-lambda-powertools/commons' ;
7
6
8
7
jest . spyOn ( console , 'debug' ) . mockImplementation ( ( ) => null ) ;
9
8
jest . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => null ) ;
10
9
jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => null ) ;
11
10
12
11
describe ( 'Middy middlewares' , ( ) => {
13
12
const ENVIRONMENT_VARIABLES = process . env ;
13
+ const context = {
14
+ callbackWaitsForEmptyEventLoop : true ,
15
+ functionVersion : '$LATEST' ,
16
+ functionName : 'foo-bar-function' ,
17
+ memoryLimitInMB : '128' ,
18
+ logGroupName : '/aws/lambda/foo-bar-function-123456abcdef' ,
19
+ logStreamName : '2021/03/09/[$LATEST]abcdef123456abcdef123456abcdef123456' ,
20
+ invokedFunctionArn : 'arn:aws:lambda:eu-central-1:123456789012:function:Example' ,
21
+ awsRequestId : 'c6af9ac6-7b61-11e6-9a41-93e8deadbeef' ,
22
+ getRemainingTimeInMillis : ( ) => 1234 ,
23
+ done : ( ) => console . log ( 'Done!' ) ,
24
+ fail : ( ) => console . log ( 'Failed!' ) ,
25
+ succeed : ( ) => console . log ( 'Succeeded!' ) ,
26
+ } ;
14
27
15
28
beforeEach ( ( ) => {
16
29
Tracer . coldStart = true ;
@@ -36,7 +49,6 @@ describe('Middy middlewares', () => {
36
49
foo : 'bar'
37
50
} ) ;
38
51
const handler = middy ( lambdaHandler ) . use ( captureLambdaHandler ( tracer ) ) ;
39
- const context = Object . assign ( { } , ContextExamples . helloworldContext ) ;
40
52
41
53
// Act
42
54
await handler ( { } , context , ( ) => console . log ( 'Lambda invoked!' ) ) ;
@@ -59,7 +71,6 @@ describe('Middy middlewares', () => {
59
71
throw new Error ( 'Exception thrown!' ) ;
60
72
} ;
61
73
const handler = middy ( lambdaHandler ) . use ( captureLambdaHandler ( tracer ) ) ;
62
- const context = Object . assign ( { } , ContextExamples . helloworldContext ) ;
63
74
64
75
// Act & Assess
65
76
await expect ( handler ( { } , context , ( ) => console . log ( 'Lambda invoked!' ) ) ) . rejects . toThrowError ( Error ) ;
@@ -82,7 +93,6 @@ describe('Middy middlewares', () => {
82
93
foo : 'bar'
83
94
} ) ;
84
95
const handler = middy ( lambdaHandler ) . use ( captureLambdaHandler ( tracer ) ) ;
85
- const context = Object . assign ( { } , ContextExamples . helloworldContext ) ;
86
96
87
97
// Act
88
98
await handler ( { } , context , ( ) => console . log ( 'Lambda invoked!' ) ) ;
@@ -106,7 +116,6 @@ describe('Middy middlewares', () => {
106
116
foo : 'bar'
107
117
} ) ;
108
118
const handler = middy ( lambdaHandler ) . use ( captureLambdaHandler ( tracer ) ) ;
109
- const context = Object . assign ( { } , ContextExamples . helloworldContext ) ;
110
119
111
120
// Act
112
121
await handler ( { } , context , ( ) => console . log ( 'Lambda invoked!' ) ) ;
@@ -141,7 +150,6 @@ describe('Middy middlewares', () => {
141
150
throw new Error ( 'Exception thrown!' ) ;
142
151
} ;
143
152
const handler = middy ( lambdaHandler ) . use ( captureLambdaHandler ( tracer ) ) ;
144
- const context = Object . assign ( { } , ContextExamples . helloworldContext ) ;
145
153
146
154
// Act & Assess
147
155
await expect ( handler ( { } , context , ( ) => console . log ( 'Lambda invoked!' ) ) ) . rejects . toThrowError ( Error ) ;
@@ -170,7 +178,6 @@ describe('Middy middlewares', () => {
170
178
throw new Error ( 'Exception thrown!' ) ;
171
179
} ;
172
180
const handler = middy ( lambdaHandler ) . use ( captureLambdaHandler ( tracer ) ) ;
173
- const context = Object . assign ( { } , ContextExamples . helloworldContext ) ;
174
181
175
182
// Act & Assess
176
183
await expect ( handler ( { } , context , ( ) => console . log ( 'Lambda invoked!' ) ) ) . rejects . toThrowError ( Error ) ;
@@ -201,7 +208,6 @@ describe('Middy middlewares', () => {
201
208
foo : 'bar'
202
209
} ) ;
203
210
const handler = middy ( lambdaHandler ) . use ( captureLambdaHandler ( tracer ) ) ;
204
- const context = Object . assign ( { } , ContextExamples . helloworldContext ) ;
205
211
206
212
// Act
207
213
await handler ( { } , context , ( ) => console . log ( 'Lambda invoked!' ) ) ;
@@ -245,7 +251,6 @@ describe('Middy middlewares', () => {
245
251
foo : 'bar'
246
252
} ) ;
247
253
const handler = middy ( lambdaHandler ) . use ( captureLambdaHandler ( tracer ) ) ;
248
- const context = Object . assign ( { } , ContextExamples . helloworldContext ) ;
249
254
250
255
// Act
251
256
await handler ( { } , context , ( ) => console . log ( 'Lambda invoked!' ) ) ;
0 commit comments