Skip to content

Commit 72332c0

Browse files
committed
Reverted to local context/event usage in tests
1 parent be07b77 commit 72332c0

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

packages/tracing/tests/unit/Tracer.test.ts

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { LambdaInterface } from '../../examples/utils/lambda';
2-
import { Events, ContextExamples } from '@aws-lambda-powertools/commons';
32
import { Tracer } from '../../src';
43
import { Callback, Context } from 'aws-lambda/handler';
54
import { Segment, setContextMissingStrategy, Subsegment } from 'aws-xray-sdk-core';
@@ -10,8 +9,25 @@ jest.spyOn(console, 'error').mockImplementation(() => null);
109

1110
describe('Class: Tracer', () => {
1211
const ENVIRONMENT_VARIABLES = process.env;
13-
const event = Events.Custom.CustomEvent;
14-
const context = ContextExamples.helloworldContext;
12+
const event = {
13+
key1: 'value1',
14+
key2: 'value2',
15+
key3: 'value3',
16+
};
17+
const context = {
18+
callbackWaitsForEmptyEventLoop: true,
19+
functionVersion: '$LATEST',
20+
functionName: 'foo-bar-function',
21+
memoryLimitInMB: '128',
22+
logGroupName: '/aws/lambda/foo-bar-function-123456abcdef',
23+
logStreamName: '2021/03/09/[$LATEST]abcdef123456abcdef123456abcdef123456',
24+
invokedFunctionArn: 'arn:aws:lambda:eu-central-1:123456789012:function:Example',
25+
awsRequestId: 'c6af9ac6-7b61-11e6-9a41-93e8deadbeef',
26+
getRemainingTimeInMillis: () => 1234,
27+
done: () => console.log('Done!'),
28+
fail: () => console.log('Failed!'),
29+
succeed: () => console.log('Succeeded!'),
30+
};
1531

1632
beforeEach(() => {
1733
Tracer.coldStart = true;
@@ -556,7 +572,7 @@ describe('Class: Tracer', () => {
556572
}
557573

558574
// Act
559-
await new Lambda().handler(Events.Custom.CustomEvent, context, () => console.log('Lambda invoked!'));
575+
await new Lambda().handler(event, context, () => console.log('Lambda invoked!'));
560576

561577
// Assess
562578
expect(captureAsyncFuncSpy).toHaveBeenCalledTimes(0);

packages/tracing/tests/unit/middy.test.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,27 @@ import middy from '@middy/core';
33
import { Tracer } from './../../src';
44
import type { Context, Handler } from 'aws-lambda/handler';
55
import { Segment, setContextMissingStrategy, Subsegment } from 'aws-xray-sdk-core';
6-
import { ContextExamples } from '@aws-lambda-powertools/commons';
76

87
jest.spyOn(console, 'debug').mockImplementation(() => null);
98
jest.spyOn(console, 'warn').mockImplementation(() => null);
109
jest.spyOn(console, 'error').mockImplementation(() => null);
1110

1211
describe('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

Comments
 (0)