Skip to content

Commit

Permalink
ref: Remove convertIntegrationFnToClass (getsentry#11343)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad authored and cadesalaberry committed Apr 19, 2024
1 parent 82a83cc commit 122d826
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 99 deletions.
2 changes: 0 additions & 2 deletions packages/core/src/index.ts
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
@@ -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
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 */
});

0 comments on commit 122d826

Please sign in to comment.