@@ -3,14 +3,27 @@ import middy from '@middy/core';
33import { Tracer } from './../../src' ;
44import type { Context , Handler } from 'aws-lambda/handler' ;
55import { Segment , setContextMissingStrategy , Subsegment } from 'aws-xray-sdk-core' ;
6- import { ContextExamples } from '@aws-lambda-powertools/commons' ;
76
87jest . spyOn ( console , 'debug' ) . mockImplementation ( ( ) => null ) ;
98jest . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => null ) ;
109jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => null ) ;
1110
1211describe ( 'Middy middlewares' , ( ) => {
1312 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+ } ;
1427
1528 beforeEach ( ( ) => {
1629 Tracer . coldStart = true ;
@@ -36,7 +49,6 @@ describe('Middy middlewares', () => {
3649 foo : 'bar'
3750 } ) ;
3851 const handler = middy ( lambdaHandler ) . use ( captureLambdaHandler ( tracer ) ) ;
39- const context = Object . assign ( { } , ContextExamples . helloworldContext ) ;
4052
4153 // Act
4254 await handler ( { } , context , ( ) => console . log ( 'Lambda invoked!' ) ) ;
@@ -59,7 +71,6 @@ describe('Middy middlewares', () => {
5971 throw new Error ( 'Exception thrown!' ) ;
6072 } ;
6173 const handler = middy ( lambdaHandler ) . use ( captureLambdaHandler ( tracer ) ) ;
62- const context = Object . assign ( { } , ContextExamples . helloworldContext ) ;
6374
6475 // Act & Assess
6576 await expect ( handler ( { } , context , ( ) => console . log ( 'Lambda invoked!' ) ) ) . rejects . toThrowError ( Error ) ;
@@ -82,7 +93,6 @@ describe('Middy middlewares', () => {
8293 foo : 'bar'
8394 } ) ;
8495 const handler = middy ( lambdaHandler ) . use ( captureLambdaHandler ( tracer ) ) ;
85- const context = Object . assign ( { } , ContextExamples . helloworldContext ) ;
8696
8797 // Act
8898 await handler ( { } , context , ( ) => console . log ( 'Lambda invoked!' ) ) ;
@@ -106,7 +116,6 @@ describe('Middy middlewares', () => {
106116 foo : 'bar'
107117 } ) ;
108118 const handler = middy ( lambdaHandler ) . use ( captureLambdaHandler ( tracer ) ) ;
109- const context = Object . assign ( { } , ContextExamples . helloworldContext ) ;
110119
111120 // Act
112121 await handler ( { } , context , ( ) => console . log ( 'Lambda invoked!' ) ) ;
@@ -141,7 +150,6 @@ describe('Middy middlewares', () => {
141150 throw new Error ( 'Exception thrown!' ) ;
142151 } ;
143152 const handler = middy ( lambdaHandler ) . use ( captureLambdaHandler ( tracer ) ) ;
144- const context = Object . assign ( { } , ContextExamples . helloworldContext ) ;
145153
146154 // Act & Assess
147155 await expect ( handler ( { } , context , ( ) => console . log ( 'Lambda invoked!' ) ) ) . rejects . toThrowError ( Error ) ;
@@ -170,7 +178,6 @@ describe('Middy middlewares', () => {
170178 throw new Error ( 'Exception thrown!' ) ;
171179 } ;
172180 const handler = middy ( lambdaHandler ) . use ( captureLambdaHandler ( tracer ) ) ;
173- const context = Object . assign ( { } , ContextExamples . helloworldContext ) ;
174181
175182 // Act & Assess
176183 await expect ( handler ( { } , context , ( ) => console . log ( 'Lambda invoked!' ) ) ) . rejects . toThrowError ( Error ) ;
@@ -201,7 +208,6 @@ describe('Middy middlewares', () => {
201208 foo : 'bar'
202209 } ) ;
203210 const handler = middy ( lambdaHandler ) . use ( captureLambdaHandler ( tracer ) ) ;
204- const context = Object . assign ( { } , ContextExamples . helloworldContext ) ;
205211
206212 // Act
207213 await handler ( { } , context , ( ) => console . log ( 'Lambda invoked!' ) ) ;
@@ -245,7 +251,6 @@ describe('Middy middlewares', () => {
245251 foo : 'bar'
246252 } ) ;
247253 const handler = middy ( lambdaHandler ) . use ( captureLambdaHandler ( tracer ) ) ;
248- const context = Object . assign ( { } , ContextExamples . helloworldContext ) ;
249254
250255 // Act
251256 await handler ( { } , context , ( ) => console . log ( 'Lambda invoked!' ) ) ;
0 commit comments