Skip to content

ref: Remove convertIntegrationFnToClass #11343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ export {
getIntegrationsToSetup,
addIntegration,
defineIntegration,
// eslint-disable-next-line deprecation/deprecation
convertIntegrationFnToClass,
} from './integration';
export { applyScopeDataToEvent, mergeScopeData } from './utils/applyScopeDataToEvent';
export { prepareEvent } from './utils/prepareEvent';
Expand Down
20 changes: 1 addition & 19 deletions packages/core/src/integration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Client, Event, EventHint, Integration, IntegrationClass, IntegrationFn, Options } from '@sentry/types';
import type { Client, Event, EventHint, Integration, IntegrationFn, Options } from '@sentry/types';
import { arrayify, logger } from '@sentry/utils';
import { getClient } from './currentScopes';

Expand Down Expand Up @@ -169,24 +169,6 @@ function findIndex<T>(arr: T[], callback: (item: T) => boolean): number {
return -1;
}

/**
* Convert a new integration function to the legacy class syntax.
* In v8, we can remove this and instead export the integration functions directly.
*
* @deprecated This will be removed in v8!
*/
export function convertIntegrationFnToClass<Fn extends IntegrationFn>(
name: string,
fn: Fn,
): IntegrationClass<Integration> {
return Object.assign(
function ConvertedIntegration(...args: Parameters<Fn>): Integration {
return fn(...args);
},
{ id: name },
) as unknown as IntegrationClass<Integration>;
}

/**
* Define an integration function that can be used to create an integration instance.
* Note that this by design hides the implementation details of the integration, as they are considered internal.
Expand Down
79 changes: 1 addition & 78 deletions packages/core/test/lib/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ import type { Integration, Options } from '@sentry/types';
import { logger } from '@sentry/utils';
import { getCurrentScope } from '../../src/currentScopes';

import {
addIntegration,
convertIntegrationFnToClass,
getIntegrationsToSetup,
installedIntegrations,
setupIntegration,
} from '../../src/integration';
import { addIntegration, getIntegrationsToSetup, installedIntegrations, setupIntegration } from '../../src/integration';
import { setCurrentClient } from '../../src/sdk';
import { TestClient, getDefaultTestClientOptions } from '../mocks/client';

Expand Down Expand Up @@ -699,74 +693,3 @@ describe('addIntegration', () => {
expect(logs).toHaveBeenCalledWith('Integration skipped because it was already installed: test');
});
});

describe('convertIntegrationFnToClass', () => {
/* eslint-disable deprecation/deprecation */
it('works with a minimal integration', () => {
const integrationFn = () => ({
name: 'testName',
setupOnce: () => {},
});

const IntegrationClass = convertIntegrationFnToClass('testName', integrationFn);

expect(IntegrationClass.id).toBe('testName');

const integration = new IntegrationClass();
expect(integration).toEqual({
name: 'testName',
setupOnce: expect.any(Function),
});
});

it('works with options', () => {
const integrationFn = (_options: { num: number }) => ({
name: 'testName',
setupOnce: () => {},
});

const IntegrationClass = convertIntegrationFnToClass('testName', integrationFn);

expect(IntegrationClass.id).toBe('testName');

// not type safe options by default :(
new IntegrationClass();

const integration = new IntegrationClass({ num: 3 });
expect(integration).toEqual({
name: 'testName',
setupOnce: expect.any(Function),
});
});

it('works with integration hooks', () => {
const setup = jest.fn();
const setupOnce = jest.fn();
const processEvent = jest.fn();
const preprocessEvent = jest.fn();

const integrationFn = () => {
return {
name: 'testName',
setup,
setupOnce,
processEvent,
preprocessEvent,
};
};

const IntegrationClass = convertIntegrationFnToClass('testName', integrationFn);

expect(IntegrationClass.id).toBe('testName');

const integration = new IntegrationClass();
expect(integration).toEqual({
name: 'testName',
setupOnce,
setup,
processEvent,
preprocessEvent,
});
});
/* eslint-enable deprecation/deprecation */
});