Skip to content

Commit 55c9a46

Browse files
authored
test(aws-serverless): Migrate to Vitest (#15487)
1 parent affca6d commit 55c9a46

File tree

7 files changed

+40
-27
lines changed

7 files changed

+40
-27
lines changed

packages/aws-serverless/jest.config.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/aws-serverless/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@
9393
"clean": "rimraf build dist-awslambda-layer coverage sentry-serverless-*.tgz",
9494
"fix": "eslint . --format stylish --fix",
9595
"lint": "eslint . --format stylish",
96-
"test": "jest",
97-
"test:watch": "jest --watch",
96+
"test": "vitest run",
97+
"test:watch": "vitest --watch",
9898
"yalc:publish": "yalc publish --push --sig"
9999
},
100100
"volta": {
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
export const lookup = jest.fn();
2-
export const resolveTxt = jest.fn();
1+
import { vi } from 'vitest';
2+
3+
export const lookup = vi.fn();
4+
export const resolveTxt = vi.fn();

packages/aws-serverless/test/sdk.test.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,29 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } fr
22

33
import type { Event } from '@sentry/core';
44
import type { Callback, Handler } from 'aws-lambda';
5+
import { beforeEach, describe, expect, test, vi } from 'vitest';
56

67
import { init, wrapHandler } from '../src/sdk';
78

8-
const mockSpanEnd = jest.fn();
9-
const mockStartInactiveSpan = jest.fn((...spanArgs) => ({ ...spanArgs }));
10-
const mockStartSpanManual = jest.fn((...spanArgs) => ({ ...spanArgs }));
11-
const mockFlush = jest.fn((...args) => Promise.resolve(args));
12-
const mockWithScope = jest.fn();
13-
const mockCaptureMessage = jest.fn();
14-
const mockCaptureException = jest.fn();
15-
const mockInit = jest.fn();
9+
const mockSpanEnd = vi.fn();
10+
const mockStartInactiveSpan = vi.fn((...spanArgs) => ({ ...spanArgs }));
11+
const mockStartSpanManual = vi.fn((...spanArgs) => ({ ...spanArgs }));
12+
const mockFlush = vi.fn((...args) => Promise.resolve(args));
13+
const mockWithScope = vi.fn();
14+
const mockCaptureMessage = vi.fn();
15+
const mockCaptureException = vi.fn();
16+
const mockInit = vi.fn();
1617

1718
const mockScope = {
18-
setTag: jest.fn(),
19-
setContext: jest.fn(),
20-
addEventProcessor: jest.fn(),
21-
setTransactionName: jest.fn(),
19+
setTag: vi.fn(),
20+
setContext: vi.fn(),
21+
addEventProcessor: vi.fn(),
22+
setTransactionName: vi.fn(),
2223
};
2324

24-
jest.mock('@sentry/node', () => {
25-
const original = jest.requireActual('@sentry/node');
25+
vi.mock('@sentry/node', async () => {
26+
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
27+
const original = (await vi.importActual('@sentry/node')) as typeof import('@sentry/node');
2628
return {
2729
...original,
2830
initWithoutDefaultIntegrations: (options: unknown) => {
@@ -115,7 +117,7 @@ describe('AWSLambda', () => {
115117
fortySix: 'o_O',
116118
};
117119

118-
jest.clearAllMocks();
120+
vi.clearAllMocks();
119121
});
120122

121123
describe('wrapHandler() options', () => {
@@ -495,7 +497,7 @@ describe('AWSLambda', () => {
495497
const scopeFunction = mockCaptureException.mock.calls[0][1];
496498
const event: Event = { exception: { values: [{}] } };
497499
let evtProcessor: ((e: Event) => Event) | undefined = undefined;
498-
scopeFunction({ addEventProcessor: jest.fn().mockImplementation(proc => (evtProcessor = proc)) });
500+
scopeFunction({ addEventProcessor: vi.fn().mockImplementation(proc => (evtProcessor = proc)) });
499501

500502
expect(evtProcessor).toBeInstanceOf(Function);
501503
// @ts-expect-error just mocking around...

packages/aws-serverless/test/utils.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { afterEach, describe, expect, test, vi } from 'vitest';
12
import { eventContextExtractor, getAwsTraceData } from '../src/utils';
23

3-
const mockExtractContext = jest.fn();
4-
jest.mock('@opentelemetry/api', () => {
5-
const actualApi = jest.requireActual('@opentelemetry/api');
4+
const mockExtractContext = vi.fn();
5+
vi.mock('@opentelemetry/api', async () => {
6+
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
7+
const actualApi = (await vi.importActual('@opentelemetry/api')) as typeof import('@opentelemetry/api');
68
return {
79
...actualApi,
810
propagation: {
@@ -63,7 +65,7 @@ describe('getTraceData', () => {
6365

6466
describe('eventContextExtractor', () => {
6567
afterEach(() => {
66-
jest.clearAllMocks();
68+
vi.clearAllMocks();
6769
});
6870

6971
test('passes sentry trace data to the propagation extractor', () => {

packages/aws-serverless/tsconfig.test.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"extends": "./tsconfig.json",
33

4-
"include": ["test/**/*"],
4+
"include": ["test/**/*", "vite.config.ts"],
55

66
"compilerOptions": {
77
// should include all types from `./tsconfig.json` plus types for all test frameworks used
8-
"types": ["node", "jest"]
8+
"types": ["node"]
99

1010
// other package-specific, test-specific options
1111
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import baseConfig from '../../vite/vite.config';
2+
3+
export default {
4+
...baseConfig,
5+
test: {
6+
...baseConfig.test,
7+
},
8+
};

0 commit comments

Comments
 (0)