Skip to content

Commit 9588fec

Browse files
committed
review comments 1
1 parent 300f2d4 commit 9588fec

File tree

10 files changed

+35
-21
lines changed

10 files changed

+35
-21
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const FLAG_BUFFER_SIZE = 100; // Corresponds to constant in featureFlags.ts, in browser utils.

dev-packages/browser-integration-tests/suites/integrations/featureFlags/featureFlags/basic/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { sentryTest } from '../../../../../utils/fixtures';
44

55
import { envelopeRequestParser, shouldSkipFeatureFlagsTest, waitForErrorRequest } from '../../../../../utils/helpers';
66

7-
const FLAG_BUFFER_SIZE = 100; // Corresponds to constant in featureFlags.ts, in browser utils.
7+
import { FLAG_BUFFER_SIZE } from '../../constants'
88

99
sentryTest('Basic test with eviction, update, and no async tasks', async ({ getLocalTestUrl, page }) => {
1010
if (shouldSkipFeatureFlagsTest()) {

dev-packages/browser-integration-tests/suites/integrations/featureFlags/launchdarkly/basic/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { sentryTest } from '../../../../../utils/fixtures';
44

55
import { envelopeRequestParser, shouldSkipFeatureFlagsTest, waitForErrorRequest } from '../../../../../utils/helpers';
66

7-
const FLAG_BUFFER_SIZE = 100; // Corresponds to constant in featureFlags.ts, in browser utils.
7+
import { FLAG_BUFFER_SIZE } from '../../constants'
88

99
sentryTest('Basic test with eviction, update, and no async tasks', async ({ getLocalTestUrl, page }) => {
1010
if (shouldSkipFeatureFlagsTest()) {

dev-packages/browser-integration-tests/suites/integrations/featureFlags/openfeature/basic/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { sentryTest } from '../../../../../utils/fixtures';
44

55
import { envelopeRequestParser, shouldSkipFeatureFlagsTest, waitForErrorRequest } from '../../../../../utils/helpers';
66

7-
const FLAG_BUFFER_SIZE = 100; // Corresponds to constant in featureFlags.ts, in browser utils.
7+
import { FLAG_BUFFER_SIZE } from '../../constants'
88

99
sentryTest('Basic test with eviction, update, and no async tasks', async ({ getLocalTestUrl, page }) => {
1010
if (shouldSkipFeatureFlagsTest()) {

dev-packages/browser-integration-tests/suites/integrations/featureFlags/openfeature/errorHook/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { sentryTest } from '../../../../../utils/fixtures';
44

55
import { envelopeRequestParser, shouldSkipFeatureFlagsTest, waitForErrorRequest } from '../../../../../utils/helpers';
66

7-
const FLAG_BUFFER_SIZE = 100; // Corresponds to constant in featureFlags.ts, in browser utils.
7+
import { FLAG_BUFFER_SIZE } from '../../constants'
88

99
sentryTest('Flag evaluation error hook', async ({ getLocalTestUrl, page }) => {
1010
if (shouldSkipFeatureFlagsTest()) {

dev-packages/browser-integration-tests/suites/integrations/featureFlags/statsig/basic/test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { sentryTest } from '../../../../../utils/fixtures';
44

55
import { envelopeRequestParser, shouldSkipFeatureFlagsTest, waitForErrorRequest } from '../../../../../utils/helpers';
66

7-
const FLAG_BUFFER_SIZE = 100; // Corresponds to constant in featureFlags.ts, in browser utils.
7+
import { FLAG_BUFFER_SIZE } from '../../constants'
88

99
sentryTest('Basic test with eviction, update, and no async tasks', async ({ getLocalTestUrl, page }) => {
1010
if (shouldSkipFeatureFlagsTest()) {
@@ -25,10 +25,14 @@ sentryTest('Basic test with eviction, update, and no async tasks', async ({ getL
2525
await page.evaluate(bufferSize => {
2626
const client = (window as any).statsigClient;
2727
for (let i = 1; i <= bufferSize; i++) {
28-
client.checkGate(`feat${i}`, false);
28+
client.checkGate(`feat${i}`); // values default to false
2929
}
30-
client.checkGate(`feat${bufferSize + 1}`, true); // eviction
31-
client.checkGate('feat3', true); // update
30+
31+
client.setMockGateValue(`feat${bufferSize + 1}`, true);
32+
client.checkGate(`feat${bufferSize + 1}`); // eviction
33+
34+
client.setMockGateValue('feat3', true);
35+
client.checkGate('feat3'); // update
3236
}, FLAG_BUFFER_SIZE);
3337

3438
const reqPromise = waitForErrorRequest(page);

dev-packages/browser-integration-tests/suites/integrations/featureFlags/statsig/init.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@ import * as Sentry from '@sentry/browser';
33
class MockStatsigClient {
44
constructor() {
55
this._gateEvaluationListeners = [];
6+
this._mockGateValues = {};
67
}
78

89
on(event, listener) {
910
this._gateEvaluationListeners.push(listener);
1011
}
1112

12-
checkGate(name, defaultVal) {
13-
// Note the actual StatsigClient.checkGate does not take a defaultVal.
13+
checkGate(name) {
14+
const value = this._mockGateValues[name] || false; // unknown features default to false.
1415
this._gateEvaluationListeners.forEach(listener => {
15-
listener({ gate: { name, value: defaultVal } });
16+
listener({ gate: { name, value } });
1617
});
17-
return defaultVal;
18+
return value;
19+
}
20+
21+
setMockGateValue(name, value) {
22+
this._mockGateValues[name] = value;
1823
}
1924
}
2025

dev-packages/browser-integration-tests/suites/integrations/featureFlags/statsig/withScope/test.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,22 @@ sentryTest('Flag evaluations in forked scopes are stored separately.', async ({
3030
const errorButton = document.querySelector('#error') as HTMLButtonElement;
3131
const client = (window as any).statsigClient;
3232

33-
client.checkGate('shared', true);
33+
client.setMockGateValue('shared', true);
34+
client.setMockGateValue('main', true);
35+
36+
client.checkGate('shared');
3437

3538
Sentry.withScope((scope: Scope) => {
36-
client.checkGate('forked', true);
37-
client.checkGate('shared', false);
39+
client.setMockGateValue('forked', true);
40+
client.setMockGateValue('shared', false); // override the value in the parent scope.
41+
42+
client.checkGate('forked');
43+
client.checkGate('shared');
3844
scope.setTag('isForked', true);
39-
if (errorButton) {
40-
errorButton.click();
41-
}
45+
errorButton.click();
4246
});
4347

44-
client.checkGate('main', true);
48+
client.checkGate('main');
4549
Sentry.getCurrentScope().setTag('isForked', false);
4650
errorButton.click();
4751
return true;

dev-packages/browser-integration-tests/suites/integrations/featureFlags/unleash/basic/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { sentryTest } from '../../../../../utils/fixtures';
44

55
import { envelopeRequestParser, shouldSkipFeatureFlagsTest, waitForErrorRequest } from '../../../../../utils/helpers';
66

7-
const FLAG_BUFFER_SIZE = 100; // Corresponds to constant in featureFlags.ts, in browser utils.
7+
import { FLAG_BUFFER_SIZE } from '../../constants'
88

99
sentryTest('Basic test with eviction, update, and no async tasks', async ({ getLocalTestUrl, page }) => {
1010
if (shouldSkipFeatureFlagsTest()) {

packages/browser/src/integrations/featureFlags/statsig/integration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { FeatureGate, StatsigClient } from './types';
1111
*
1212
* @example
1313
* ```
14-
* import { StatsigClient } from '';
14+
* import { StatsigClient } from '@statsig/js-client';
1515
* import * as Sentry from '@sentry/browser';
1616
*
1717
* const statsigClient = new StatsigClient();

0 commit comments

Comments
 (0)