Skip to content

Commit f907103

Browse files
Update tests
1 parent 3e49e70 commit f907103

File tree

5 files changed

+33
-31
lines changed

5 files changed

+33
-31
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"node": ">=6"
4141
},
4242
"dependencies": {
43-
"@splitsoftware/splitio-commons": "1.12.1-rc.6",
43+
"@splitsoftware/splitio-commons": "1.12.1-rc.7",
4444
"@types/google.analytics": "0.0.40",
4545
"@types/ioredis": "^4.28.0",
4646
"bloom-filters": "^3.0.0",

src/__tests__/browserSuites/push-corner-cases.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getStorageHash } from '@splitsoftware/splitio-commons/src/storages/KeyBuilder';
12
import splitChangesMock1 from '../mocks/splitchanges.since.-1.json';
23
import splitKillMessage from '../mocks/message.SPLIT_KILL.1457552650000.json';
34
import authPushEnabledNicolas from '../mocks/auth.pushEnabled.nicolas@split.io.json';
@@ -9,7 +10,6 @@ window.EventSource = EventSourceMock;
910

1011
import { SplitFactory } from '../../';
1112
import { settingsFactory } from '../../settings';
12-
import { getStorageHash } from '@splitsoftware/splitio-commons/src/storages/KeyBuilder';
1313

1414
const userKey = 'nicolas@split.io';
1515

src/__tests__/browserSuites/ready-from-cache.spec.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { getStorageHash } from '@splitsoftware/splitio-commons/src/storages/KeyBuilder';
12
import { SplitFactory } from '../../';
23

34
import splitChangesMock1 from '../mocks/splitchanges.since.-1.json';
45
import splitChangesMock2 from '../mocks/splitchanges.since.1457552620999.json';
56
import mySegmentsNicolas from '../mocks/mysegments.nicolas@split.io.json';
6-
import { getStorageHash } from '@splitsoftware/splitio-commons/src/storages/KeyBuilder';
77

88
import { nearlyEqual } from '../testUtils';
99

@@ -256,7 +256,7 @@ export default function (fetchMock, assert) {
256256
t.plan(12 * 2 + 5);
257257

258258
fetchMock.get(testUrls.sdk + '/splitChanges?since=25', function () {
259-
t.equal(localStorage.getItem('readyFromCache_3.SPLITIO.split.always_on'), alwaysOnSplitInverted, 'splits must not be cleaned from cache');
259+
t.equal(localStorage.getItem('readyFromCache_3.SPLITIO.split.always_on'), alwaysOnSplitInverted, 'feature flags must not be cleaned from cache');
260260
return new Promise(res => { setTimeout(() => res({ status: 200, body: { ...splitChangesMock1, since: 25 }, headers: {} }), 200); }); // 400ms is how long it'll take to reply with Splits, no SDK_READY should be emitted before that.
261261
});
262262
fetchMock.get(testUrls.sdk + '/splitChanges?since=1457552620999', { status: 200, body: splitChangesMock2 });
@@ -371,11 +371,11 @@ export default function (fetchMock, assert) {
371371
events: 'https://events.baseurl/readyFromCacheWithData4'
372372
};
373373
localStorage.clear();
374-
t.plan(9 * 2 + 5);
375374

376375
fetchMock.get(testUrls.sdk + '/splitChanges?since=-1', function () {
377376
t.equal(localStorage.getItem('some_user_item'), 'user_item', 'user items at localStorage must not be changed');
378-
t.equal(localStorage.length, 1, 'split cache data must be cleaned from localStorage');
377+
t.equal(localStorage.getItem('readyFromCache_4.SPLITIO.hash'), expectedHashNullFilter, 'storage hash must not be changed');
378+
t.equal(localStorage.length, 2, 'feature flags cache data must be cleaned from localStorage');
379379
return { status: 200, body: splitChangesMock1 };
380380
});
381381
fetchMock.get(testUrls.sdk + '/splitChanges?since=1457552620999', { status: 200, body: splitChangesMock2 });
@@ -461,6 +461,8 @@ export default function (fetchMock, assert) {
461461
t.equal(localStorage.getItem('some_user_item'), 'user_item', 'user items at localStorage must not be changed');
462462
t.equal(localStorage.getItem('readyFromCache_4.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
463463
t.true(nearlyEqual(parseInt(localStorage.getItem('readyFromCache_4.SPLITIO.splits.lastUpdated')), Date.now() - 1000 /* 1000 ms between last Split and MySegments fetch */), 'lastUpdated must correspond to the timestamp of the last successfully fetched Splits');
464+
465+
t.end();
464466
});
465467
});
466468
t.true(Date.now() - startTime >= 1000, 'It should emit SDK_READY after syncing with the cloud.');
@@ -478,7 +480,7 @@ export default function (fetchMock, assert) {
478480

479481
/** Fetch specific splits **/
480482

481-
assert.test(t => { // Testing when we start with cached data but without storage hash (JS SDK version 10.24.0 and below), and a valid split filter config
483+
assert.test(t => { // Testing when we start with cached data but without storage hash (JS SDK <=v10.24.0 and Browser SDK <=v0.12.0), and a valid split filter config
482484
const testUrls = {
483485
sdk: 'https://sdk.baseurl/readyFromCache_5',
484486
events: 'https://events.baseurl/readyFromCache_5'
@@ -512,7 +514,7 @@ export default function (fetchMock, assert) {
512514
const manager = splitio.manager();
513515

514516
client.once(client.Event.SDK_READY_FROM_CACHE, () => {
515-
t.fail('It should not emit SDK_READY_FROM_CACHE because localstorage is cleaned and there isn\'t cached data');
517+
t.fail('It should not emit SDK_READY_FROM_CACHE because localStorage is cleaned and there isn\'t cached feature flags');
516518
t.end();
517519
});
518520

@@ -522,8 +524,8 @@ export default function (fetchMock, assert) {
522524
client.destroy().then(() => {
523525
t.equal(localStorage.getItem('some_user_item'), 'user_item', 'user items at localStorage must not be changed');
524526
t.equal(localStorage.getItem('readyFromCache_5.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
525-
t.equal(localStorage.getItem('readyFromCache_5.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'split declarations must be cached');
526-
t.equal(localStorage.getItem('readyFromCache_5.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'split declarations must be cached');
527+
t.equal(localStorage.getItem('readyFromCache_5.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'feature flag declarations must be cached');
528+
t.equal(localStorage.getItem('readyFromCache_5.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'feature flag declarations must be cached');
527529
t.equal(localStorage.getItem('readyFromCache_5.SPLITIO.hash'), expectedHashWithFilter, 'Storage hash must correspond to the one for the SDK key and feature flag filter query');
528530
t.equal(localStorage.getItem('readyFromCache_5.SPLITIO.splits.filterQuery'), null);
529531
t.end();
@@ -567,8 +569,8 @@ export default function (fetchMock, assert) {
567569

568570
client.destroy().then(() => {
569571
t.equal(localStorage.getItem('readyFromCache_5B.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
570-
t.equal(localStorage.getItem('readyFromCache_5B.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'split declarations must be cached');
571-
t.equal(localStorage.getItem('readyFromCache_5B.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'split declarations must be cached');
572+
t.equal(localStorage.getItem('readyFromCache_5B.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'feature flag declarations must be cached');
573+
t.equal(localStorage.getItem('readyFromCache_5B.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'feature flag declarations must be cached');
572574
t.equal(localStorage.getItem('readyFromCache_5B.SPLITIO.hash'), expectedHashWithFilter, 'Storage hash must correspond to the split filter query and SDK key');
573575
t.end();
574576
});
@@ -618,8 +620,8 @@ export default function (fetchMock, assert) {
618620
client.destroy().then(() => {
619621
t.equal(localStorage.getItem('some_user_item'), 'user_item', 'user items at localStorage must not be changed');
620622
t.equal(localStorage.getItem('readyFromCache_6.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
621-
t.equal(localStorage.getItem('readyFromCache_6.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'split declarations must be cached');
622-
t.equal(localStorage.getItem('readyFromCache_6.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'split declarations must be cached');
623+
t.equal(localStorage.getItem('readyFromCache_6.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'feature flag declarations must be cached');
624+
t.equal(localStorage.getItem('readyFromCache_6.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'feature flag declarations must be cached');
623625
t.equal(localStorage.getItem('readyFromCache_6.SPLITIO.hash'), expectedHash, 'Storage hash must correspond to the split filter query and SDK key');
624626
t.end();
625627
});
@@ -671,8 +673,8 @@ export default function (fetchMock, assert) {
671673
client.destroy().then(() => {
672674
t.equal(localStorage.getItem('some_user_item'), 'user_item', 'user items at localStorage must not be changed');
673675
t.equal(localStorage.getItem('readyFromCache_7.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
674-
t.equal(localStorage.getItem('readyFromCache_7.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'split declarations must be cached');
675-
t.equal(localStorage.getItem('readyFromCache_7.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'split declarations must be cached');
676+
t.equal(localStorage.getItem('readyFromCache_7.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'feature flag declarations must be cached');
677+
t.equal(localStorage.getItem('readyFromCache_7.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'feature flag declarations must be cached');
676678
t.equal(localStorage.getItem('readyFromCache_7.SPLITIO.hash'), expectedHash, 'Storage hash must correspond to the split filter query and SDK key');
677679
t.end();
678680
});
@@ -724,7 +726,7 @@ export default function (fetchMock, assert) {
724726
const manager = splitio.manager();
725727

726728
client.once(client.Event.SDK_READY_FROM_CACHE, () => {
727-
t.fail('It should not emit SDK_READY_FROM_CACHE because all splits were removed from cache since the filter query changed.');
729+
t.fail('It should not emit SDK_READY_FROM_CACHE because all feature flags were removed from cache since the filter query changed.');
728730
t.end();
729731
});
730732

@@ -734,9 +736,9 @@ export default function (fetchMock, assert) {
734736
client.destroy().then(() => {
735737
t.equal(localStorage.getItem('some_user_item'), 'user_item', 'user items at localStorage must not be changed');
736738
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
737-
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'split declarations must be cached');
738-
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'split declarations must be cached');
739-
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.split.p3__split'), JSON.stringify(splitDeclarations.p3__split), 'split declarations must be cached');
739+
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'feature flag declarations must be cached');
740+
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'feature flag declarations must be cached');
741+
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.split.p3__split'), JSON.stringify(splitDeclarations.p3__split), 'feature flag declarations must be cached');
740742
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.hash'), expectedHashNullFilter, 'Storage hash must correspond to the split filter query and SDK key');
741743
t.end();
742744
});
@@ -784,9 +786,9 @@ export default function (fetchMock, assert) {
784786
client.destroy().then(() => {
785787
t.equal(localStorage.getItem('some_user_item'), 'user_item', 'user items at localStorage must not be changed');
786788
t.equal(localStorage.getItem('readyFromCache_9.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
787-
t.equal(localStorage.getItem('readyFromCache_9.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'split declarations must be cached');
788-
t.equal(localStorage.getItem('readyFromCache_9.SPLITIO.split.p3__split'), JSON.stringify(splitDeclarations.p3__split), 'split declarations must be cached');
789-
t.equal(localStorage.getItem('readyFromCache_9.SPLITIO.hash'), getStorageHash({ ...baseConfig, sync: { __splitFiltersValidation: { queryString: '&names=no%20exist%20trim,no_exist,p3__split&prefixes=no%20exist%20trim,p2' } } }), 'splits.filterQuery must correspond to the split filter query');
789+
t.equal(localStorage.getItem('readyFromCache_9.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'feature flag declarations must be cached');
790+
t.equal(localStorage.getItem('readyFromCache_9.SPLITIO.split.p3__split'), JSON.stringify(splitDeclarations.p3__split), 'feature flag declarations must be cached');
791+
t.equal(localStorage.getItem('readyFromCache_9.SPLITIO.hash'), getStorageHash({ ...baseConfig, sync: { __splitFiltersValidation: { queryString: '&names=no%20exist%20trim,no_exist,p3__split&prefixes=no%20exist%20trim,p2' } } }), 'Storage hash must correspond to the split filter query and SDK key');
790792
t.end();
791793
});
792794
});

src/__tests__/errorCatching/browser.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Here we are testing exceptions and the handler should be ours, we need to avoid tape-catch
2+
import { getStorageHash } from '@splitsoftware/splitio-commons/src/storages/KeyBuilder';
23
import tape from 'tape';
34
import includes from 'lodash/includes';
45
import fetchMock from '../testUtils/fetchMock';
@@ -9,7 +10,6 @@ import splitChangesMock2 from '../mocks/splitChanges.since.1500492097547.till.15
910
import splitChangesMock3 from '../mocks/splitChanges.since.1500492297547.json';
1011
import { SplitFactory } from '../../';
1112
import { settingsFactory } from '../../settings';
12-
import { getStorageHash } from '@splitsoftware/splitio-commons/src/storages/KeyBuilder';
1313

1414
const settings = settingsFactory({
1515
core: {

0 commit comments

Comments
 (0)