Skip to content

Commit

Permalink
fix serverless test
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Dec 19, 2023
1 parent 0b6e01c commit 1cf0597
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 2 additions & 0 deletions packages/serverless/test/__mocks__/@sentry/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const captureException = jest.fn();
export const captureMessage = jest.fn();
export const withScope = jest.fn(cb => cb(fakeScope));
export const flush = jest.fn(() => Promise.resolve());
export const getClient = jest.fn(() => ({}));

export const resetMocks = (): void => {
fakeTransaction.setHttpStatus.mockClear();
Expand Down Expand Up @@ -68,4 +69,5 @@ export const resetMocks = (): void => {
captureMessage.mockClear();
withScope.mockClear();
flush.mockClear();
getClient.mockClear();
};
13 changes: 5 additions & 8 deletions packages/serverless/test/gcpfunction.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as domain from 'domain';
import * as SentryNode from '@sentry/node';
import type { Event } from '@sentry/types';
import type { Event, Integration } from '@sentry/types';

import * as Sentry from '../src';
import { wrapCloudEventFunction, wrapEventFunction, wrapHttpFunction } from '../src/gcpfunction';
Expand Down Expand Up @@ -234,8 +234,6 @@ describe('GCPFunction', () => {
// integration is included in the defaults and the necessary data is stored in `sdkProcessingMetadata`. The
// integration's tests cover testing that it uses that data correctly.
test('wrapHttpFunction request data prereqs', async () => {
expect.assertions(2);

Sentry.GCPFunction.init({});

const handler: HttpFunction = (_req, res) => {
Expand All @@ -245,11 +243,10 @@ describe('GCPFunction', () => {

await handleHttp(wrappedHandler);

expect(SentryNode.init).toHaveBeenCalledWith(
expect.objectContaining({
defaultIntegrations: expect.arrayContaining([expect.any(SentryNode.Integrations.RequestData)]),
}),
);
const initOptions = (SentryNode.init as unknown as jest.SpyInstance).mock.calls[0];
const defaultIntegrations = initOptions[0].defaultIntegrations.map((i: Integration) => i.name);

expect(defaultIntegrations).toContain('RequestData');

// @ts-expect-error see "Why @ts-expect-error" note
expect(SentryNode.fakeScope.setSDKProcessingMetadata).toHaveBeenCalledWith({
Expand Down

0 comments on commit 1cf0597

Please sign in to comment.