Skip to content

Commit

Permalink
Fix formatting (yarn run biome check --apply)
Browse files Browse the repository at this point in the history
  • Loading branch information
aliu39 committed Jan 15, 2025
1 parent 776bb58 commit fae120b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ window.UnleashClient = class {
};

window.Sentry = Sentry;
window.sentryUnleashIntegration = Sentry.unleashIntegration({unleashClientClass: window.UnleashClient});
window.sentryUnleashIntegration = Sentry.unleashIntegration({ unleashClientClass: window.UnleashClient });

Sentry.init({
dsn: 'https://[email protected]/1337',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ sentryTest('Logs and returns if isEnabled does not match expected signature', as
// Expected error logs.
expect(errorLogs).toEqual(
expect.arrayContaining([
expect.stringContaining('[Feature Flags] UnleashClient.isEnabled does not match expected signature. arg0: my-feature (string), result: my-feature (string)'),
expect.stringContaining('[Feature Flags] UnleashClient.isEnabled does not match expected signature. arg0: 999 (number), result: 999 (number)'),
expect.stringContaining('[Feature Flags] UnleashClient.isEnabled does not match expected signature. arg0: [object Object] (object), result: [object Object] (object)'),
expect.stringContaining(
'[Feature Flags] UnleashClient.isEnabled does not match expected signature. arg0: my-feature (string), result: my-feature (string)',
),
expect.stringContaining(
'[Feature Flags] UnleashClient.isEnabled does not match expected signature. arg0: 999 (number), result: 999 (number)',
),
expect.stringContaining(
'[Feature Flags] UnleashClient.isEnabled does not match expected signature. arg0: [object Object] (object), result: [object Object] (object)',
),
]),
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ window.UnleashClient = class {
};

window.Sentry = Sentry;
window.sentryUnleashIntegration = Sentry.unleashIntegration({unleashClientClass: window.UnleashClient});
window.sentryUnleashIntegration = Sentry.unleashIntegration({ unleashClientClass: window.UnleashClient });

Sentry.init({
dsn: 'https://[email protected]/1337',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,22 @@ import type { UnleashClient, UnleashClientClass } from './types';
* Sentry.captureException(new Error('something went wrong'));
* ```
*/
export const unleashIntegration = defineIntegration(({unleashClientClass}: {unleashClientClass: UnleashClientClass}) => {
return {
name: 'Unleash',
export const unleashIntegration = defineIntegration(
({ unleashClientClass }: { unleashClientClass: UnleashClientClass }) => {
return {
name: 'Unleash',

processEvent(event: Event, _hint: EventHint, _client: Client): Event {
return copyFlagsFromScopeToEvent(event);
},
processEvent(event: Event, _hint: EventHint, _client: Client): Event {
return copyFlagsFromScopeToEvent(event);
},

setupOnce() {
const unleashClientPrototype = unleashClientClass.prototype as UnleashClient;
fill(unleashClientPrototype, 'isEnabled', _wrappedIsEnabled);
},
};
}) satisfies IntegrationFn;
setupOnce() {
const unleashClientPrototype = unleashClientClass.prototype as UnleashClient;
fill(unleashClientPrototype, 'isEnabled', _wrappedIsEnabled);
},
};
},
) satisfies IntegrationFn;

/**
* Wraps the UnleashClient.isEnabled method to capture feature flag evaluations. Its only side effect is writing to Sentry scope.
Expand All @@ -53,15 +55,19 @@ export const unleashIntegration = defineIntegration(({unleashClientClass}: {unle
* @param original - The original method.
* @returns Wrapped method. Results should match the original.
*/
function _wrappedIsEnabled(original: (this: UnleashClient, ...args: unknown[]) => unknown): (this: UnleashClient, ...args: unknown[]) => unknown {
function _wrappedIsEnabled(
original: (this: UnleashClient, ...args: unknown[]) => unknown,
): (this: UnleashClient, ...args: unknown[]) => unknown {
return function (this: UnleashClient, ...args: unknown[]): unknown {
const toggleName = args[0];
const result = original.apply(this, args);

if (typeof toggleName === 'string' && typeof result === 'boolean') {
insertFlagToScope(toggleName, result);
} else {
logger.error(`[Feature Flags] UnleashClient.isEnabled does not match expected signature. arg0: ${toggleName} (${typeof toggleName}), result: ${result} (${typeof result})`);
logger.error(
`[Feature Flags] UnleashClient.isEnabled does not match expected signature. arg0: ${toggleName} (${typeof toggleName}), result: ${result} (${typeof result})`,
);
}
return result;
};
Expand Down

0 comments on commit fae120b

Please sign in to comment.