Skip to content
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
4 changes: 3 additions & 1 deletion packages/experiment-browser/src/experimentClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,9 @@ export class ExperimentClient implements Client {

private storeVariants(variants: Variants, options?: FetchOptions): void {
let failedFlagKeys = options && options.flagKeys ? options.flagKeys : [];

if (failedFlagKeys.length === 0) {
this.storage.clear();
}
for (const key in variants) {
failedFlagKeys = failedFlagKeys.filter((flagKey) => flagKey !== key);
this.storage.put(key, variants[key]);
Expand Down
10 changes: 10 additions & 0 deletions packages/experiment-browser/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,16 @@ test('configure httpClient, success', async () => {
expect(v).toEqual({ value: 'key' });
});

test('existing storage variant removed when fetch without flag keys response stored', async () => {
const client = new ExperimentClient(API_KEY, {});
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
client.storage.put('not-fetched-variant', { value: 'on' });
await client.fetch(testUser);
const variant = client.variant('not-fetched-variant');
expect(variant).toEqual({});
});

// Testing with local api server, need to updated to use the production data.
const LOCAL_TEST_API = API_KEY; //'server-qz35UwzJ5akieoAdIgzM4m9MIiOLXLoz'; //'server-VY0FufBsdITI1Gv9y7RyUopLzk9m8t0n';
const local_test_user = testUser; //{ user_id: 'brian.giori@amplitude.com' };
Expand Down