Skip to content

Commit

Permalink
Remove getStatus logs, to avoid noise when used before actions are di…
Browse files Browse the repository at this point in the history
…spatched
  • Loading branch information
EmilianoSanchez committed May 24, 2024
1 parent 7ea37b5 commit d0bb6f4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 25 deletions.
14 changes: 1 addition & 13 deletions src/__tests__/helpers.browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
initSplitSdk,
splitSdk,
} from '../asyncActions';
import { ERROR_GETSTATUS_NO_INITSPLITSDK, ERROR_TRACK_NO_INITSPLITSDK, WARN_GETSTATUS_NO_CLIENT } from '../constants';
import { ERROR_TRACK_NO_INITSPLITSDK } from '../constants';

/** Test targets */
import {
Expand Down Expand Up @@ -182,17 +182,10 @@ describe('getStatus', () => {
});

it('should return the default status if the SDK was not initialized', () => {
const errorSpy = jest.spyOn(console, 'error');

expect(getStatus()).toEqual(STATUS_INITIAL);
expect(errorSpy).toBeCalledWith(ERROR_GETSTATUS_NO_INITSPLITSDK);

errorSpy.mockRestore();
});

it('should return the status of the client associated to the provided key', () => {
const logSpy = jest.spyOn(console, 'log');

initSplitSdk({ config: sdkBrowserConfig });
getTreatments({ key: 'user_2', splitNames: ['split_1'] });
(splitSdk.factory as any).client().__emitter__.emit(Event.SDK_READY);
Expand All @@ -209,12 +202,7 @@ describe('getStatus', () => {
expect(getStatus('user_2')).toEqual(USER_2_STATUS);
expect(getStatus({ matchingKey: 'user_2', bucketingKey: '' })).toEqual(USER_2_STATUS);

expect(logSpy).not.toBeCalled();

// Non-existing client
expect(getStatus('non_existing_key')).toEqual(STATUS_INITIAL);
expect(logSpy).toBeCalledWith(WARN_GETSTATUS_NO_CLIENT);

logSpy.mockRestore();
});
});
4 changes: 0 additions & 4 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,8 @@ export const ERROR_TRACK_NO_INITSPLITSDK = errorNoInitSplitSdk('"track"');

export const ERROR_MANAGER_NO_INITSPLITSDK = errorNoInitSplitSdk('the manager');

export const ERROR_GETSTATUS_NO_INITSPLITSDK = errorNoInitSplitSdk('"getStatus"');

export const ERROR_SELECTOR_NO_SPLITSTATE = '[ERROR] To use selectors, "splitState" param must be a proper splitio piece of state';

export const ERROR_GETT_NO_PARAM_OBJECT = '[ERROR] "getTreatments" must be called with a param object containing a valid splitNames or flagSets properties';

export const WARN_FEATUREFLAGS_AND_FLAGSETS = '[WARN] Both splitNames and flagSets properties were provided. flagSets will be ignored';

export const WARN_GETSTATUS_NO_CLIENT = '[WARN] No client found for the provided key';
10 changes: 2 additions & 8 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { splitSdk, getClient } from './asyncActions';
import { IStatus, ITrackParams } from './types';
import { ERROR_TRACK_NO_INITSPLITSDK, ERROR_MANAGER_NO_INITSPLITSDK, ERROR_GETSTATUS_NO_INITSPLITSDK, WARN_GETSTATUS_NO_CLIENT } from './constants';
import { ERROR_TRACK_NO_INITSPLITSDK, ERROR_MANAGER_NO_INITSPLITSDK } from './constants';
import { __getStatus, matching } from './utils';

/**
Expand Down Expand Up @@ -106,13 +106,7 @@ export function getStatus(key?: SplitIO.SplitKey): IStatus {
const isMainClient = splitSdk.isDetached || !stringKey || stringKey === matching((splitSdk.config as SplitIO.IBrowserSettings).core.key);
const client = isMainClient ? splitSdk.factory.client() : splitSdk.sharedClients[stringKey];

if (client) {
return __getStatus(client);
} else {
console.log(WARN_GETSTATUS_NO_CLIENT);
}
} else {
console.error(ERROR_GETSTATUS_NO_INITSPLITSDK);
if (client) return __getStatus(client);
}

// Default status if SDK is not initialized or client is not found
Expand Down

0 comments on commit d0bb6f4

Please sign in to comment.