Skip to content

Commit b1455f4

Browse files
add test coverage
1 parent 0b2ab0c commit b1455f4

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

.github/workflows/ci-cd.yml

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

5959
- name: Store assets
60-
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/fme-12310' || github.ref == 'refs/heads/main') }}
60+
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/development' || github.ref == 'refs/heads/main') }}
6161
uses: actions/upload-artifact@v5
6262
with:
6363
name: assets
@@ -68,7 +68,7 @@ jobs:
6868
name: Upload assets
6969
runs-on: ubuntu-latest
7070
needs: build
71-
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/fme-12310' }}
71+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/development' }}
7272
strategy:
7373
matrix:
7474
environment:

src/__tests__/browserSuites/push-synchronization.spec.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const EXPECTED_DELAY_AND_BACKOFF = 241 + 100;
9191
export function testSynchronization(fetchMock, assert) {
9292
// Force the backoff base of UpdateWorkers to reduce test time
9393
Backoff.__TEST__BASE_MILLIS = 100;
94-
assert.plan(34);
94+
assert.plan(39); // +3 for FLAGS_UPDATE metadata, +2 for SEGMENTS_UPDATE metadata
9595
fetchMock.reset();
9696

9797
let start, splitio, client, otherClient, keylistAddClient, keylistRemoveClient, bitmapTrueClient, sharedClients = [];
@@ -108,7 +108,10 @@ export function testSynchronization(fetchMock, assert) {
108108

109109
setTimeout(() => {
110110
assert.equal(client.getTreatment('whitelist'), 'not_allowed', 'evaluation of initial Split');
111-
client.once(client.Event.SDK_UPDATE, () => {
111+
client.once(client.Event.SDK_UPDATE, (metadata) => {
112+
assert.equal(metadata.type, 'FLAGS_UPDATE', 'SDK_UPDATE for SPLIT_UPDATE should have type FLAGS_UPDATE');
113+
assert.true(Array.isArray(metadata.names), 'metadata.names should be an array');
114+
assert.true(metadata.names.includes('whitelist'), 'metadata.names should include the updated whitelist split');
112115
const lapse = Date.now() - start;
113116
assert.true(nearlyEqual(lapse, MILLIS_FIRST_SPLIT_UPDATE_EVENT), 'SDK_UPDATE due to SPLIT_UPDATE event');
114117
assert.equal(client.getTreatment('whitelist'), 'allowed', 'evaluation of updated Split');
@@ -202,7 +205,9 @@ export function testSynchronization(fetchMock, assert) {
202205

203206
const timestampUnboundEvent = Date.now();
204207

205-
client.once(client.Event.SDK_UPDATE, () => {
208+
client.once(client.Event.SDK_UPDATE, (metadata) => {
209+
assert.equal(metadata.type, 'SEGMENTS_UPDATE', 'SDK_UPDATE for MEMBERSHIPS_LS_UPDATE should have type SEGMENTS_UPDATE');
210+
assert.true(Array.isArray(metadata.names), 'metadata.names should be an array');
206211
assert.true(nearlyEqual(Date.now() - timestampUnboundEvent, EXPECTED_DELAY_AND_BACKOFF), 'SDK_UPDATE after fetching memberships with a delay');
207212
assert.equal(client.getTreatment('in_large_segment'), 'yes', 'evaluation after myLargeSegment fetch');
208213
});

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export default function (fetchMock, assert) {
179179
events: 'https://events.baseurl/readyFromCacheWithData'
180180
};
181181
localStorage.clear();
182-
t.plan(12 * 2 + 3);
182+
t.plan(12 * 2 + 3 + 2); // +2 for SDK_READY and SDK_READY_FROM_CACHE metadata.initialCacheLoad asserts
183183

184184
fetchMock.get(testUrls.sdk + '/splitChanges?s=1.3&since=25&rbSince=-1', () => {
185185
return new Promise(res => { setTimeout(() => res({ status: 200, body: { ff: { ...splitChangesMock1.ff, s: 25 } }, headers: {} }), 200); }); // 400ms is how long it'll take to reply with Splits, no SDK_READY should be emitted before that.
@@ -225,7 +225,8 @@ export default function (fetchMock, assert) {
225225
t.end();
226226
});
227227

228-
client.on(client.Event.SDK_READY_FROM_CACHE, () => {
228+
client.on(client.Event.SDK_READY_FROM_CACHE, (metadata) => {
229+
t.false(metadata.initialCacheLoad, 'SDK_READY_FROM_CACHE from cache should have initialCacheLoad false');
229230
t.true(Date.now() - startTime < 400, 'It should emit SDK_READY_FROM_CACHE on every client if there was data in the cache and we subscribe on time. Should be considerably faster than actual readiness from the cloud.');
230231
t.equal(client.getTreatment('always_on'), 'off', 'It should evaluate treatments with data from cache instead of control due to Input Validation');
231232
});
@@ -238,7 +239,8 @@ export default function (fetchMock, assert) {
238239
t.equal(client3.getTreatment('always_on'), 'off', 'It should evaluate treatments with data from cache instead of control due to Input Validation');
239240
});
240241

241-
client.on(client.Event.SDK_READY, () => {
242+
client.on(client.Event.SDK_READY, (metadata) => {
243+
t.false(metadata.initialCacheLoad, 'SDK_READY when from cache first should have initialCacheLoad false');
242244
t.true(Date.now() - startTime >= 400, 'It should emit SDK_READY too but after syncing with the cloud.');
243245
t.equal(client.getTreatment('always_on'), 'on', 'It should evaluate treatments with updated data after syncing with the cloud.');
244246
});
@@ -474,7 +476,9 @@ export default function (fetchMock, assert) {
474476
t.end();
475477
});
476478

477-
client.once(client.Event.SDK_READY_FROM_CACHE, () => {
479+
client.once(client.Event.SDK_READY_FROM_CACHE, (metadata) => {
480+
t.true(metadata.initialCacheLoad, 'SDK_READY_FROM_CACHE on fresh install should have initialCacheLoad true');
481+
t.equal(metadata.lastUpdateTimestamp, undefined, 'lastUpdateTimestamp should be undefined when initialCacheLoad is true');
478482
t.true(nearlyEqual(Date.now() - startTime, CLIENT_READY_MS), 'It should emit SDK_READY_FROM_CACHE alongside SDK_READY');
479483
});
480484
client2.once(client2.Event.SDK_READY_FROM_CACHE, () => {
@@ -484,7 +488,8 @@ export default function (fetchMock, assert) {
484488
t.true(nearlyEqual(Date.now() - startTime, CLIENT3_READY_MS), 'It should emit SDK_READY_FROM_CACHE alongside SDK_READY');
485489
});
486490

487-
client.on(client.Event.SDK_READY, () => {
491+
client.on(client.Event.SDK_READY, (metadata) => {
492+
t.true(metadata.initialCacheLoad, 'SDK_READY on fresh install should have initialCacheLoad true');
488493
t.true(nearlyEqual(Date.now() - startTime, CLIENT_READY_MS), 'It should emit SDK_READY after syncing with the cloud.');
489494
t.equal(client.getTreatment('always_on'), 'on', 'It should evaluate treatments with updated data after syncing with the cloud.');
490495
});

src/__tests__/nodeSuites/push-synchronization.spec.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const MILLIS_DESTROY = 1700;
9292
* 1.6 secs: RB_SEGMENT_UPDATE IFFU event with ZLib compression
9393
*/
9494
export function testSynchronization(fetchMock, assert) {
95-
assert.plan(53);
95+
assert.plan(56); // +3 for SDK_UPDATE metadata (type, names array, names includes whitelist)
9696
fetchMock.reset();
9797
__setEventSource(EventSourceMock);
9898

@@ -114,7 +114,10 @@ export function testSynchronization(fetchMock, assert) {
114114
}, MILLIS_SSE_OPEN); // open SSE connection after 0.1 seconds
115115
setTimeout(() => {
116116
assert.equal(client.getTreatment(key, 'whitelist'), 'not_allowed', 'evaluation of initial Split');
117-
client.once(client.Event.SDK_UPDATE, () => {
117+
client.once(client.Event.SDK_UPDATE, (metadata) => {
118+
assert.equal(metadata.type, 'FLAGS_UPDATE', 'SDK_UPDATE for SPLIT_UPDATE should have type FLAGS_UPDATE');
119+
assert.true(Array.isArray(metadata.names), 'metadata.names should be an array');
120+
assert.true(metadata.names.includes('whitelist'), 'metadata.names should include the updated whitelist split');
118121
const lapse = Date.now() - start;
119122
assert.true(nearlyEqual(lapse, MILLIS_FIRST_SPLIT_UPDATE_EVENT), 'SDK_UPDATE due to SPLIT_UPDATE event');
120123
assert.equal(client.getTreatment(key, 'whitelist'), 'allowed', 'evaluation of updated Split');

src/__tests__/offline/browser.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ tape('Browser offline mode', function (assert) {
105105
assert.equal(client.getTreatment('testing_split_with_config'), 'off');
106106
readyCount++;
107107
});
108-
client.on(client.Event.SDK_UPDATE, () => {
108+
client.on(client.Event.SDK_UPDATE, (metadata) => {
109+
assert.equal(metadata.type, 'FLAGS_UPDATE', 'SDK_UPDATE for localhost features update should have type FLAGS_UPDATE');
110+
assert.true(Array.isArray(metadata.names), 'metadata.names should be an array');
109111
assert.deepEqual(manager.names().sort(), ['testing_split', 'testing_split_2', 'testing_split_3', 'testing_split_with_config']);
110112
assert.equal(client.getTreatment('testing_split_with_config'), 'nope');
111113
updateCount++;

0 commit comments

Comments
 (0)