Skip to content

Commit 29d1c05

Browse files
committed
tests(metrics): fix handlers type
1 parent 8269677 commit 29d1c05

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

Diff for: packages/metrics/jest.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
2+
'runner': 'groups',
23
'preset': 'ts-jest',
34
'transform': {
45
'^.+\\.ts?$': 'ts-jest',

Diff for: packages/metrics/tests/unit/Metrics.test.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ interface LooseObject {
1616
[key: string]: string
1717
}
1818

19+
type DummyEvent = {
20+
key1: string
21+
key2: string
22+
key3: string
23+
};
24+
25+
/**
26+
* Metrics tests
27+
*
28+
* @group metrics
29+
* @group unit/Metrics
30+
*/
31+
1932
describe('Class: Metrics', () => {
2033
const originalEnvironmentVariables = process.env;
2134

@@ -229,7 +242,7 @@ describe('Class: Metrics', () => {
229242
test('Cold start metric should only be written out once and flushed automatically', async () => {
230243
const metrics = new Metrics({ namespace: 'test' });
231244

232-
const handler = async (_event: unknown, _context: unknown): Promise<void> => {
245+
const handler = async (_event: DummyEvent, _context: Context): Promise<void> => {
233246
// Should generate only one log
234247
metrics.captureColdStartMetric();
235248
};
@@ -363,7 +376,7 @@ describe('Class: Metrics', () => {
363376
expect.assertions(1);
364377

365378
const metrics = new Metrics({ namespace: 'test' });
366-
const handler = async (_event: unknown, _context: unknown): Promise<void> => {
379+
const handler = async (_event: DummyEvent, _context: Context): Promise<void> => {
367380
metrics.raiseOnEmptyMetrics();
368381
// Logic goes here
369382
metrics.purgeStoredMetrics();

Diff for: packages/metrics/tests/unit/middleware/middy.test.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import { logMetrics } from '../../../../metrics/src/middleware';
22
import { Metrics, MetricUnits } from '../../../../metrics/src';
33
import middy from '@middy/core';
4+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
5+
// @ts-ignore
6+
import * as event from '../../../../../tests/resources/events/custom/hello-world.json';
47
import { ExtraOptions } from '../../../src/types';
58

69
const consoleSpy = jest.spyOn(console, 'log').mockImplementation();
710
const mockDate = new Date(1466424490000);
811
const dateSpy = jest.spyOn(global, 'Date').mockImplementation(() => mockDate as unknown as string);
912

13+
/**
14+
* Metrics tests
15+
*
16+
* @group metrics
17+
* @group unit/middleware
18+
*/
1019
describe('Middy middleware', () => {
1120

1221
beforeEach(() => {
@@ -17,7 +26,6 @@ describe('Middy middleware', () => {
1726

1827
describe('logMetrics', () => {
1928

20-
const event = { foo: 'bar' };
2129
const getRandomInt = (): number => Math.floor(Math.random() * 1000000000);
2230
const awsRequestId = getRandomInt().toString();
2331

0 commit comments

Comments
 (0)