Skip to content

Commit b38653a

Browse files
committed
require passed featureList in order to override locally
1 parent 216f237 commit b38653a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

packages/browser-sdk/src/feature/features.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ export class FeaturesClient {
274274
return this.features;
275275
}
276276

277+
getFetchedFeatures(): FetchedFeatures {
278+
return this.fetchedFeatures;
279+
}
280+
277281
public async fetchFeatures(): Promise<FetchedFeatures | undefined> {
278282
const params = this.fetchParams();
279283
try {

packages/browser-sdk/test/features.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { afterAll, beforeEach, describe, expect, test, vi } from "vitest";
22

33
import { version } from "../package.json";
4+
import { FeatureDefinitions } from "../src/client";
45
import {
56
FEATURES_EXPIRE_MS,
67
FeaturesClient,
@@ -36,6 +37,7 @@ function featuresClientFactory() {
3637
newFeaturesClient: function newFeaturesClient(
3738
options?: FeaturesOptions,
3839
context?: any,
40+
featureList: FeatureDefinitions = [],
3941
) {
4042
return new FeaturesClient(
4143
httpClient,
@@ -45,7 +47,7 @@ function featuresClientFactory() {
4547
other: { eventId: "big-conference1" },
4648
...context,
4749
},
48-
[],
50+
featureList,
4951
testLogger,
5052
{
5153
cache,
@@ -302,16 +304,20 @@ describe("FeaturesClient unit tests", () => {
302304
test("handled overrides for features not returned by API", async () => {
303305
// change the response so we can validate that we'll serve the stale cache
304306
const { newFeaturesClient } = featuresClientFactory();
307+
305308
// localStorage.clear();
306-
const client = newFeaturesClient();
309+
const client = newFeaturesClient(undefined, undefined, ["featureB"]);
307310
await client.initialize();
308311

309312
let updated = false;
310313
client.onUpdated(() => {
311314
updated = true;
312315
});
313316

314-
expect(client.getFeatures().featureB).toBeUndefined();
317+
expect(client.getFeatures().featureB.isEnabled).toBe(false);
318+
expect(client.getFeatures().featureB.isEnabledOverride).toBe(null);
319+
320+
expect(client.getFetchedFeatures()?.featureB).toBeUndefined();
315321

316322
client.setFeatureOverride("featureB", true);
317323

0 commit comments

Comments
 (0)