Skip to content

Commit a56e9d6

Browse files
Update tests
1 parent a09713f commit a56e9d6

5 files changed

Lines changed: 31 additions & 29 deletions

File tree

.github/workflows/ci-cd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
run: BUILD_BRANCH=$(echo "${GITHUB_REF#refs/heads/}") npm run build
4848

4949
- name: Store assets
50-
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/update_localstorage_clear' || github.ref == 'refs/heads/main') }}
50+
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/development' || github.ref == 'refs/heads/main') }}
5151
uses: actions/upload-artifact@v3
5252
with:
5353
name: assets
@@ -58,7 +58,7 @@ jobs:
5858
name: Upload assets
5959
runs-on: ubuntu-20.04
6060
needs: build
61-
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/update_localstorage_clear' }}
61+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/development' }}
6262
strategy:
6363
matrix:
6464
environment:

CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
0.13.0 (December XX, 2023)
1+
0.13.0 (December 12, 2023)
22
- Added support for Flag Sets in "consumer" and "partial consumer" modes (pluggable storage).
33
- Updated SDK cache for browsers using localStorage, to clear cached feature flag definitions before initiating the synchronization process, if the cache was previously synchronized with a different SDK key (i.e., a different environment) or different Split Filter criteria.
44
- Updated @splitsoftware/splitio-commons package to version 1.12.1 that includes flag sets support for "consumer" and "partial consumer" modes, and other improvements.

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
@@ -64,7 +64,7 @@
6464
"bugs": "https://github.com/splitio/javascript-browser-client/issues",
6565
"homepage": "https://github.com/splitio/javascript-browser-client#readme",
6666
"dependencies": {
67-
"@splitsoftware/splitio-commons": "1.12.1-rc.6",
67+
"@splitsoftware/splitio-commons": "1.12.1-rc.7",
6868
"@types/google.analytics": "0.0.40",
6969
"unfetch": "^4.2.0"
7070
},

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export default function (fetchMock, assert) {
254254
t.plan(12 * 2 + 5);
255255

256256
fetchMock.get(testUrls.sdk + '/splitChanges?since=25', function () {
257-
t.equal(localStorage.getItem('readyFromCache_3.SPLITIO.split.always_on'), alwaysOnSplitInverted, 'splits must not be cleaned from cache');
257+
t.equal(localStorage.getItem('readyFromCache_3.SPLITIO.split.always_on'), alwaysOnSplitInverted, 'feature flags must not be cleaned from cache');
258258
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.
259259
});
260260
fetchMock.get(testUrls.sdk + '/splitChanges?since=1457552620999', { status: 200, body: splitChangesMock2 });
@@ -368,11 +368,11 @@ export default function (fetchMock, assert) {
368368
events: 'https://events.baseurl/readyFromCacheWithData4'
369369
};
370370
localStorage.clear();
371-
t.plan(9 * 2 + 5);
372371

373372
fetchMock.get(testUrls.sdk + '/splitChanges?since=-1', function () {
374373
t.equal(localStorage.getItem('some_user_item'), 'user_item', 'user items at localStorage must not be changed');
375-
t.equal(localStorage.length, 1, 'split cache data must be cleaned from localStorage');
374+
t.equal(localStorage.getItem('readyFromCache_4.SPLITIO.hash'), expectedHashNullFilter, 'storage hash must not be changed');
375+
t.equal(localStorage.length, 2, 'feature flags cache data must be cleaned from localStorage');
376376
return { status: 200, body: splitChangesMock1 };
377377
});
378378
fetchMock.get(testUrls.sdk + '/splitChanges?since=1457552620999', { status: 200, body: splitChangesMock2 });
@@ -457,6 +457,8 @@ export default function (fetchMock, assert) {
457457
t.equal(localStorage.getItem('some_user_item'), 'user_item', 'user items at localStorage must not be changed');
458458
t.equal(localStorage.getItem('readyFromCache_4.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
459459
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');
460+
461+
t.end();
460462
});
461463
});
462464
t.true(Date.now() - startTime >= 1000, 'It should emit SDK_READY after syncing with the cloud.');
@@ -517,8 +519,8 @@ export default function (fetchMock, assert) {
517519
client.destroy().then(() => {
518520
t.equal(localStorage.getItem('some_user_item'), 'user_item', 'user items at localStorage must not be changed');
519521
t.equal(localStorage.getItem('readyFromCache_5.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
520-
t.equal(localStorage.getItem('readyFromCache_5.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'split declarations must be cached');
521-
t.equal(localStorage.getItem('readyFromCache_5.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'split declarations must be cached');
522+
t.equal(localStorage.getItem('readyFromCache_5.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'feature flag declarations must be cached');
523+
t.equal(localStorage.getItem('readyFromCache_5.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'feature flag declarations must be cached');
522524
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');
523525
t.equal(localStorage.getItem('readyFromCache_5.SPLITIO.splits.filterQuery'), null);
524526
t.end();
@@ -561,8 +563,8 @@ export default function (fetchMock, assert) {
561563

562564
client.destroy().then(() => {
563565
t.equal(localStorage.getItem('readyFromCache_5B.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
564-
t.equal(localStorage.getItem('readyFromCache_5B.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'split declarations must be cached');
565-
t.equal(localStorage.getItem('readyFromCache_5B.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'split declarations must be cached');
566+
t.equal(localStorage.getItem('readyFromCache_5B.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'feature flag declarations must be cached');
567+
t.equal(localStorage.getItem('readyFromCache_5B.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'feature flag declarations must be cached');
566568
t.equal(localStorage.getItem('readyFromCache_5B.SPLITIO.hash'), expectedHashWithFilter, 'Storage hash must correspond to the split filter query and SDK key');
567569
t.end();
568570
});
@@ -612,8 +614,8 @@ export default function (fetchMock, assert) {
612614
client.destroy().then(() => {
613615
t.equal(localStorage.getItem('some_user_item'), 'user_item', 'user items at localStorage must not be changed');
614616
t.equal(localStorage.getItem('readyFromCache_6.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
615-
t.equal(localStorage.getItem('readyFromCache_6.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'split declarations must be cached');
616-
t.equal(localStorage.getItem('readyFromCache_6.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'split declarations must be cached');
617+
t.equal(localStorage.getItem('readyFromCache_6.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'feature flag declarations must be cached');
618+
t.equal(localStorage.getItem('readyFromCache_6.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'feature flag declarations must be cached');
617619
t.equal(localStorage.getItem('readyFromCache_6.SPLITIO.hash'), expectedHash, 'Storage hash must correspond to the split filter query and SDK key');
618620
t.end();
619621
});
@@ -664,8 +666,8 @@ export default function (fetchMock, assert) {
664666
client.destroy().then(() => {
665667
t.equal(localStorage.getItem('some_user_item'), 'user_item', 'user items at localStorage must not be changed');
666668
t.equal(localStorage.getItem('readyFromCache_7.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
667-
t.equal(localStorage.getItem('readyFromCache_7.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'split declarations must be cached');
668-
t.equal(localStorage.getItem('readyFromCache_7.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'split declarations must be cached');
669+
t.equal(localStorage.getItem('readyFromCache_7.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'feature flag declarations must be cached');
670+
t.equal(localStorage.getItem('readyFromCache_7.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'feature flag declarations must be cached');
669671
t.equal(localStorage.getItem('readyFromCache_7.SPLITIO.hash'), expectedHash, 'Storage hash must correspond to the split filter query and SDK key');
670672
t.end();
671673
});
@@ -716,7 +718,7 @@ export default function (fetchMock, assert) {
716718
const manager = splitio.manager();
717719

718720
client.once(client.Event.SDK_READY_FROM_CACHE, () => {
719-
t.fail('It should not emit SDK_READY_FROM_CACHE because all splits were removed from cache since the filter query changed.');
721+
t.fail('It should not emit SDK_READY_FROM_CACHE because all feature flags were removed from cache since the filter query changed.');
720722
t.end();
721723
});
722724

@@ -726,9 +728,9 @@ export default function (fetchMock, assert) {
726728
client.destroy().then(() => {
727729
t.equal(localStorage.getItem('some_user_item'), 'user_item', 'user items at localStorage must not be changed');
728730
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
729-
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'split declarations must be cached');
730-
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'split declarations must be cached');
731-
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.split.p3__split'), JSON.stringify(splitDeclarations.p3__split), 'split declarations must be cached');
731+
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.split.p1__split'), JSON.stringify(splitDeclarations.p1__split), 'feature flag declarations must be cached');
732+
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'feature flag declarations must be cached');
733+
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.split.p3__split'), JSON.stringify(splitDeclarations.p3__split), 'feature flag declarations must be cached');
732734
t.equal(localStorage.getItem('readyFromCache_8.SPLITIO.hash'), expectedHashNullFilter, 'Storage hash must correspond to the split filter query and SDK key');
733735
t.end();
734736
});
@@ -770,7 +772,7 @@ export default function (fetchMock, assert) {
770772
const manager = splitio.manager();
771773

772774
client.once(client.Event.SDK_READY_FROM_CACHE, () => {
773-
t.fail('It should not emit SDK_READY_FROM_CACHE because all splits were removed from cache since the filter query changed.');
775+
t.fail('It should not emit SDK_READY_FROM_CACHE because all feature flags were removed from cache since the filter query changed.');
774776
t.end();
775777
});
776778

@@ -780,8 +782,8 @@ export default function (fetchMock, assert) {
780782
client.destroy().then(() => {
781783
t.equal(localStorage.getItem('some_user_item'), 'user_item', 'user items at localStorage must not be changed');
782784
t.equal(localStorage.getItem('readyFromCache_9.SPLITIO.splits.till'), '1457552620999', 'splits.till must correspond to the till of the last successfully fetched Splits');
783-
t.equal(localStorage.getItem('readyFromCache_9.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'split declarations must be cached');
784-
t.equal(localStorage.getItem('readyFromCache_9.SPLITIO.split.p3__split'), JSON.stringify(splitDeclarations.p3__split), 'split declarations must be cached');
785+
t.equal(localStorage.getItem('readyFromCache_9.SPLITIO.split.p2__split'), JSON.stringify(splitDeclarations.p2__split), 'feature flag declarations must be cached');
786+
t.equal(localStorage.getItem('readyFromCache_9.SPLITIO.split.p3__split'), JSON.stringify(splitDeclarations.p3__split), 'feature flag declarations must be cached');
785787
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');
786788
t.end();
787789
});

0 commit comments

Comments
 (0)