-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sdk option to bypass window undefined checks (#234)
* Add option to bypass window undefined check * allow logger interval as well * fix window check * check that flush interval is setup * bump v4.29.0
- Loading branch information
1 parent
94a3378
commit 1aab3f3
Showing
8 changed files
with
112 additions
and
55 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,4 +32,51 @@ describe('Verify behavior of StatsigClient outside of browser environment', () = | |
await client.initializeAsync(); | ||
client.shutdown(); | ||
}); | ||
|
||
test('Client ignores window undefined if specified in options', async () => { | ||
expect.assertions(8); | ||
|
||
// @ts-ignore | ||
global.fetch = jest.fn((url, params) => { | ||
if (url.toString().includes('rgstr')) { | ||
return Promise.resolve({ ok: true }); | ||
} | ||
if (url.toString().includes('initialize')) { | ||
return Promise.resolve({ | ||
ok: true, | ||
text: () => | ||
Promise.resolve( | ||
JSON.stringify(TestData), | ||
), | ||
}); | ||
} | ||
}); | ||
|
||
// verify window is undefined | ||
expect(typeof window).toBe('undefined'); | ||
|
||
const client = new StatsigClient( | ||
'client-xyz', | ||
{ email: '[email protected]' }, | ||
{ ignoreWindowUndefined: true }, | ||
); | ||
|
||
await client.initializeAsync(); | ||
// flush interval is setup | ||
// @ts-ignore | ||
expect(client.getLogger().flushInterval).not.toBeNull(); | ||
|
||
// initialized from network (fetch mock) | ||
expect(client.checkGate('test_gate')).toBe(false); | ||
expect(client.checkGate('i_dont_exist')).toBe(false); | ||
expect(client.checkGate('always_on_gate')).toBe(true); | ||
expect(client.checkGate('on_for_statsig_email')).toBe(true); | ||
expect(client.getConfig('test_config').get('number', 10)).toEqual(7); | ||
expect(client.getConfig('test_config').getEvaluationDetails()).toEqual({ | ||
reason: EvaluationReason.Network, | ||
time: expect.any(Number), | ||
}); | ||
|
||
client.shutdown(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"disableAutoEventLogging": true, | ||
"gates": { | ||
"AoZS0F06Ub+W2ONx+94rPTS7MRxuxa+GnXro5Q1uaGY=": true | ||
}, | ||
"feature_gates": { | ||
"AoZS0F06Ub+W2ONx+94rPTS7MRxuxa+GnXro5Q1uaGY=": { | ||
"value": true, | ||
"rule_id": "ruleID123", | ||
"name": "AoZS0F06Ub+W2ONx+94rPTS7MRxuxa+GnXro5Q1uaGY=", | ||
"secondary_exposures": [ | ||
{ | ||
"gate": "dependent_gate_1", | ||
"gateValue": "true", | ||
"ruleID": "rule_1" | ||
}, | ||
{ | ||
"gate": "dependent_gate_2", | ||
"gateValue": "false", | ||
"ruleID": "default" | ||
} | ||
] | ||
} | ||
}, | ||
"dynamic_configs": { | ||
"RMv0YJlLOBe7cY7HgZ3Jox34R0Wrk7jLv3DZyBETA7I=": { | ||
"value": { | ||
"bool": true, | ||
"number": 2, | ||
"string": "string", | ||
"object": { | ||
"key": "value", | ||
"key2": 123 | ||
}, | ||
"boolStr1": "true", | ||
"boolStr2": "FALSE", | ||
"numberStr1": "3", | ||
"numberStr2": "3.3", | ||
"numberStr3": "3.3.3" | ||
}, | ||
"rule_id": "ruleID" | ||
} | ||
}, | ||
"layer_configs": {}, | ||
"has_updates": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters