Skip to content

Commit

Permalink
Integration tests improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Zamora committed Oct 18, 2023
1 parent 933bcf2 commit 602fc7f
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 49 deletions.
6 changes: 4 additions & 2 deletions src/__tests__/browserSuites/fetch-specific-splits.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const baseConfig = {
streamingEnabled: false,
};

export default function fetchSpecificSplits(fetchMock, assert) {
export function fetchSpecificSplits(fetchMock, assert) {

assert.plan(splitFilters.length+1);
assert.plan(splitFilters.length);

for (let i = 0; i < splitFilters.length; i++) {
const urls = { sdk: 'https://sdkurl' + i };
Expand Down Expand Up @@ -46,7 +46,9 @@ export default function fetchSpecificSplits(fetchMock, assert) {
}

}
}

export function fetchSpecificSplitsForFlagSets(fetchMock, assert) {
// Flag sets
assert.test(async (t) => {

Expand Down
2 changes: 0 additions & 2 deletions src/__tests__/browserSuites/flag-sets.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export default function flagSets(fetchMock, t) {

t.test(async (assert) => {
fetchMock.reset();
assert.plan(8);

let factory, client = [];

Expand Down Expand Up @@ -168,7 +167,6 @@ export default function flagSets(fetchMock, t) {

t.test(async (assert) => {
fetchMock.reset();
assert.plan(8);

let factory, client = [];

Expand Down
10 changes: 0 additions & 10 deletions src/__tests__/browserSuites/push-flag-sets.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export function testFlagSets(fetchMock, t) {

t.test(async (assert) => {

assert.plan(3);
let splitio, client, manager = [];

setMockListener((eventSourceInstance) => {
Expand All @@ -72,7 +71,6 @@ export function testFlagSets(fetchMock, t) {
client.once(client.Event.SDK_UPDATE, async () => {
assert.equal(manager.splits().length, 1, '1 - update is processed and the flag is stored');
await client.destroy();
assert.equal(eventSourceInstance.readyState, EventSourceMock.CLOSED, '1 - streaming is closed after destroy');
assert.end();
});
eventSourceInstance.emitMessage(notification1);
Expand All @@ -88,7 +86,6 @@ export function testFlagSets(fetchMock, t) {

t.test(async (assert) => {

assert.plan(5);
let splitio, client, manager = [];

setMockListener((eventSourceInstance) => {
Expand Down Expand Up @@ -116,7 +113,6 @@ export function testFlagSets(fetchMock, t) {
client.once(client.Event.SDK_UPDATE, async () => {
assert.deepEqual(manager.splits().length, 0, '2 - update is processed and the flag is removed');
await client.destroy();
assert.equal(eventSourceInstance.readyState, EventSourceMock.CLOSED, '2 - streaming is closed after destroy');
assert.end();
});
eventSourceInstance.emitMessage(notification4None);
Expand All @@ -132,7 +128,6 @@ export function testFlagSets(fetchMock, t) {

t.test(async (assert) => {

assert.plan(6);
let splitio, client, manager = [];

setMockListener((eventSourceInstance) => {
Expand Down Expand Up @@ -168,7 +163,6 @@ export function testFlagSets(fetchMock, t) {
client.once(client.Event.SDK_UPDATE, async () => {
assert.deepEqual(manager.splits().length, 0, '3 - update is processed and flag is not added to the storage');
await client.destroy();
assert.equal(eventSourceInstance.readyState, EventSourceMock.CLOSED, '3 - streaming is closed after destroy');
assert.end();
});
eventSourceInstance.emitMessage(notification5);
Expand All @@ -184,7 +178,6 @@ export function testFlagSets(fetchMock, t) {

t.test(async (assert) => {

assert.plan(5);

fetchMock.getOnce(baseUrls.sdk + '/splitChanges?since=2&sets=set_1,set_2', function () {
assert.pass('4 - A fetch is triggered due to the SPLIT_KILL');
Expand All @@ -210,7 +203,6 @@ export function testFlagSets(fetchMock, t) {
client.once(client.Event.SDK_UPDATE, async () => {
assert.equal(manager.split('workm').killed, true, '4 - update is processed and the flag is updated');
await client.destroy();
assert.equal(eventSourceInstance.readyState, EventSourceMock.CLOSED, '4 - streaming is closed after destroy');
assert.end();
});
eventSourceInstance.emitMessage(notificationKill);
Expand All @@ -226,7 +218,6 @@ export function testFlagSets(fetchMock, t) {

t.test(async (assert) => {

assert.plan(4);

fetchMock.getOnce(baseUrls.sdk + '/splitChanges?since=1&sets=set_1,set_2', function () {
assert.pass('5 - A fetch is triggered due to the SPLIT_KILL');
Expand All @@ -245,7 +236,6 @@ export function testFlagSets(fetchMock, t) {
client.once(client.Event.SDK_UPDATE, async () => {
assert.deepEqual(manager.splits(), [], '5 - storage is not modified since flag is not present. ');
await client.destroy();
assert.equal(eventSourceInstance.readyState, EventSourceMock.CLOSED, '5 - streaming is closed after destroy');
assert.end();
});
eventSourceInstance.emitMessage(notificationKill);
Expand Down
16 changes: 1 addition & 15 deletions src/__tests__/browserSuites/telemetry.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,30 +189,16 @@ export default async function telemetryBrowserSuite(fetchMock, t) {

fetchMock.get(baseUrls.sdk + '/mySegments/nicolas%40split.io', { status: 200, body: { 'mySegments': [] } });
fetchMock.getOnce(baseUrls.sdk + '/splitChanges?since=-1&sets=a,c,d', { status: 200, body: { splits: [], since: 1457552620999, till: 1457552620999 } });
fetchMock.postOnce(baseUrls.telemetry + '/v1/metrics/usage', 200);
fetchMock.postOnce(baseUrls.telemetry + '/v1/metrics/config', (url, opts) => {
const data = JSON.parse(opts.body);

assert.true(data.tR > 0, 'timeUntilReady is larger than 0');
assert.equal(data.fsT, 7, 'unique flag sets total should be 7');
assert.equal(data.fsI, 4, 'flagset ignored should be 4');
factory.client().destroy().then(() => {
assert.end();
});

return 200;
});

factory = SplitFactoryForTest({...baseConfig, sync: {splitFilters}});

}, 'SDK with sets configured has sets information in config POST');

t.test(async (assert) => {
assert.plan(8);
let factory;
const splitFilters = [{ type: 'bySet', values: ['a', 'b'] }];

fetchMock.getOnce(baseUrls.sdk + '/splitChanges?since=-1&sets=a,c,d', { status: 200, body: { splits: [], since: 1457552620999, till: 1457552620999 } });
fetchMock.postOnce(baseUrls.telemetry + '/v1/metrics/usage', (url, opts) => {
const data = JSON.parse(opts.body);

Expand All @@ -236,6 +222,6 @@ export default async function telemetryBrowserSuite(fetchMock, t) {
assert.deepEqual(client.getTreatmentsWithConfigByFlagSet('a'),[]);
assert.deepEqual(client.getTreatmentsWithConfigByFlagSets(['a']),[]);

}, 'SDK with sets configured has evaluation by sets telemetry in stats POST');
}, 'SDK with sets configured has sets information in config POST and evaluation by sets telemetry in stats POST');

}
7 changes: 5 additions & 2 deletions src/__tests__/nodeSuites/fetch-specific-splits.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const baseConfig = {
streamingEnabled: false,
};

export default function fetchSpecificSplits(fetchMock, assert) {
export function fetchSpecificSplits(fetchMock, assert) {

assert.plan(splitFilters.length+1);
assert.plan(splitFilters.length);

for (let i = 0; i < splitFilters.length; i++) {
const urls = { sdk: 'https://sdkurl' + i };
Expand Down Expand Up @@ -43,6 +43,9 @@ export default function fetchSpecificSplits(fetchMock, assert) {
}

}
}

export function fetchSpecificSplitsForFlagSets(fetchMock, assert) {

// Flag sets
assert.test(async (t) => {
Expand Down
4 changes: 0 additions & 4 deletions src/__tests__/nodeSuites/flag-sets.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export default function flagSets(fetchMock, t) {
mockSegmentChanges(fetchMock, new RegExp(baseUrls.sdk + '/segmentChanges/*'), ['some_key']);

t.test(async (assert) => {
assert.plan(7);
let factory, manager, client = [];

// Receive split change with 1 split belonging to set_1 & set_2 and one belonging to set_3
Expand Down Expand Up @@ -76,7 +75,6 @@ export default function flagSets(fetchMock, t) {
}, 'Polling - SDK with sets configured updates flags according to sets');

t.test(async (assert) => {
assert.plan(15);

let factory, manager, client = [];

Expand Down Expand Up @@ -138,7 +136,6 @@ export default function flagSets(fetchMock, t) {

t.test(async (assert) => {
fetchMock.reset();
assert.plan(8);

let factory, client = [];

Expand Down Expand Up @@ -176,7 +173,6 @@ export default function flagSets(fetchMock, t) {

t.test(async (assert) => {
fetchMock.reset();
assert.plan(8);

let factory, client = [];

Expand Down
11 changes: 0 additions & 11 deletions src/__tests__/nodeSuites/push-flag-sets.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export function testFlagSets(fetchMock, t) {

t.test(async (assert) => {

assert.plan(3);
let splitio, client, manager = [];

setMockListener((eventSourceInstance) => {
Expand All @@ -75,7 +74,6 @@ export function testFlagSets(fetchMock, t) {
client.once(client.Event.SDK_UPDATE, async () => {
assert.equal(manager.splits().length, 1, '1 - update is processed and the flag is stored');
await client.destroy();
assert.equal(eventSourceInstance.readyState, EventSourceMock.CLOSED, '1 - streaming is closed after destroy');
assert.end();
});
eventSourceInstance.emitMessage(notification1);
Expand All @@ -91,7 +89,6 @@ export function testFlagSets(fetchMock, t) {

t.test(async (assert) => {

assert.plan(5);
let splitio, client, manager = [];

setMockListener((eventSourceInstance) => {
Expand Down Expand Up @@ -119,7 +116,6 @@ export function testFlagSets(fetchMock, t) {
client.once(client.Event.SDK_UPDATE, async () => {
assert.deepEqual(manager.splits().length, 0, '2 - update is processed and the flag is removed');
await client.destroy();
assert.equal(eventSourceInstance.readyState, EventSourceMock.CLOSED, '2 - streaming is closed after destroy');
assert.end();
});
eventSourceInstance.emitMessage(notification4None);
Expand All @@ -135,7 +131,6 @@ export function testFlagSets(fetchMock, t) {

t.test(async (assert) => {

assert.plan(6);
let splitio, client, manager = [];

setMockListener((eventSourceInstance) => {
Expand Down Expand Up @@ -171,7 +166,6 @@ export function testFlagSets(fetchMock, t) {
client.once(client.Event.SDK_UPDATE, async () => {
assert.deepEqual(manager.splits().length, 0, '3 - update is processed and flag is not added to the storage');
await client.destroy();
assert.equal(eventSourceInstance.readyState, EventSourceMock.CLOSED, '3 - streaming is closed after destroy');
assert.end();
});
eventSourceInstance.emitMessage(notification5);
Expand All @@ -187,16 +181,13 @@ export function testFlagSets(fetchMock, t) {

t.test(async (assert) => {

assert.plan(5);

let splitio, client, manager = [];

setMockListener((eventSourceInstance) => {

fetchMock.getOnce(baseUrls.sdk + '/splitChanges?since=2&sets=set_1,set_2', async function () {
assert.pass('4 - A fetch is triggered due to the SPLIT_KILL');
await client.destroy();
assert.equal(eventSourceInstance.readyState, EventSourceMock.CLOSED, '4 - streaming is closed after destroy');
assert.end();
return { status: 200, body: { splits: [], since: 2, till: 3 }};
});
Expand Down Expand Up @@ -231,7 +222,6 @@ export function testFlagSets(fetchMock, t) {
}, 'SDK with sets configured updates flag when a SPLIT_KILL is received');

t.test(async (assert) => {
assert.plan(4);

fetchMock.getOnce(baseUrls.sdk + '/splitChanges?since=1&sets=set_1,set_2', function () {
assert.pass('5 - A fetch is triggered due to the SPLIT_KILL');
Expand All @@ -250,7 +240,6 @@ export function testFlagSets(fetchMock, t) {
client.once(client.Event.SDK_UPDATE, async () => {
assert.deepEqual(manager.splits(), [], '5 - storage is not modified since flag is not present. ');
await client.destroy();
assert.equal(eventSourceInstance.readyState, EventSourceMock.CLOSED, '5 - streaming is closed after destroy');
assert.end();
});
eventSourceInstance.emitMessage(notificationKill);
Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/online/browser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import ignoreIpAddressesSettingSuite from '../browserSuites/ignore-ip-addresses-
import useBeaconApiSuite from '../browserSuites/use-beacon-api.spec';
import useBeaconDebugApiSuite from '../browserSuites/use-beacon-api.debug.spec';
import readyPromiseSuite from '../browserSuites/ready-promise.spec';
import fetchSpecificSplits from '../browserSuites/fetch-specific-splits.spec';
import { fetchSpecificSplits, fetchSpecificSplitsForFlagSets } from '../browserSuites/fetch-specific-splits.spec';
import userConsent from '../browserSuites/user-consent.spec';
import singleSync from '../browserSuites/single-sync.spec';
import flagSets from '../browserSuites/flag-sets.spec';
Expand Down Expand Up @@ -131,10 +131,11 @@ tape('## E2E CI Tests ##', function (assert) {
assert.test('E2E / Ready promise', readyPromiseSuite.bind(null, fetchMock));
/* Validate fetching specific splits */
assert.test('E2E / Fetch specific splits', fetchSpecificSplits.bind(null, fetchMock));
assert.test('E2E / Fetch specific splits for flag sets', fetchSpecificSplitsForFlagSets.bind(null, fetchMock));
/* Validate single sync */
assert.test('E2E / Single sync', singleSync.bind(null, fetchMock));
/* Validate flag sets */
assert.test('E2E / flag sets', flagSets.bind(null, fetchMock));
assert.test('E2E / Flag sets', flagSets.bind(null, fetchMock));

//If we change the mocks, we need to clear localstorage. Cleaning up after testing ensures "fresh data".
localStorage.clear();
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/online/node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import managerSuite from '../nodeSuites/manager.spec';
import ipAddressesSetting from '../nodeSuites/ip-addresses-setting.spec';
import ipAddressesSettingDebug from '../nodeSuites/ip-addresses-setting.debug.spec';
import readyPromiseSuite from '../nodeSuites/ready-promise.spec';
import fetchSpecificSplits from '../nodeSuites/fetch-specific-splits.spec';
import { fetchSpecificSplits, fetchSpecificSplitsForFlagSets } from '../nodeSuites/fetch-specific-splits.spec';

import splitChangesMock1 from '../mocks/splitchanges.since.-1.json';
import splitChangesMock2 from '../mocks/splitchanges.since.1457552620999.json';
Expand Down Expand Up @@ -83,6 +83,7 @@ tape('## Node JS - E2E CI Tests ##', async function (assert) {

/* Validate fetching specific splits */
assert.test('E2E / Fetch specific splits', fetchSpecificSplits.bind(null, fetchMock));
assert.test('E2E / Fetch specific splits for flag sets', fetchSpecificSplitsForFlagSets.bind(null, fetchMock));

/* Validate flag sets */
assert.test('E2E / Flag sets', flagSets.bind(null, fetchMock));
Expand Down

0 comments on commit 602fc7f

Please sign in to comment.