From e6c7ef6b8b41af2f9fde3df7320f029703f0769a Mon Sep 17 00:00:00 2001 From: Emmanuel Zamora Date: Wed, 18 Oct 2023 14:43:22 -0300 Subject: [PATCH] Integration tests improvements --- .../browserSuites/fetch-specific-splits.spec.js | 6 ++++-- src/__tests__/browserSuites/flag-sets.spec.js | 2 -- .../browserSuites/push-flag-sets.spec.js | 10 ---------- src/__tests__/browserSuites/telemetry.spec.js | 16 +--------------- .../nodeSuites/fetch-specific-splits.spec.js | 7 +++++-- src/__tests__/nodeSuites/flag-sets.spec.js | 4 ---- src/__tests__/nodeSuites/push-flag-sets.spec.js | 11 ----------- src/__tests__/online/browser.spec.js | 5 +++-- src/__tests__/online/node.spec.js | 3 ++- 9 files changed, 15 insertions(+), 49 deletions(-) diff --git a/src/__tests__/browserSuites/fetch-specific-splits.spec.js b/src/__tests__/browserSuites/fetch-specific-splits.spec.js index a15f68b42..fd0534746 100644 --- a/src/__tests__/browserSuites/fetch-specific-splits.spec.js +++ b/src/__tests__/browserSuites/fetch-specific-splits.spec.js @@ -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 }; @@ -46,7 +46,9 @@ export default function fetchSpecificSplits(fetchMock, assert) { } } +} +export function fetchSpecificSplitsForFlagSets(fetchMock, assert) { // Flag sets assert.test(async (t) => { diff --git a/src/__tests__/browserSuites/flag-sets.spec.js b/src/__tests__/browserSuites/flag-sets.spec.js index a821943aa..37673d617 100644 --- a/src/__tests__/browserSuites/flag-sets.spec.js +++ b/src/__tests__/browserSuites/flag-sets.spec.js @@ -131,7 +131,6 @@ export default function flagSets(fetchMock, t) { t.test(async (assert) => { fetchMock.reset(); - assert.plan(8); let factory, client = []; @@ -168,7 +167,6 @@ export default function flagSets(fetchMock, t) { t.test(async (assert) => { fetchMock.reset(); - assert.plan(8); let factory, client = []; diff --git a/src/__tests__/browserSuites/push-flag-sets.spec.js b/src/__tests__/browserSuites/push-flag-sets.spec.js index d2d7b2a6f..bc97cbb5a 100644 --- a/src/__tests__/browserSuites/push-flag-sets.spec.js +++ b/src/__tests__/browserSuites/push-flag-sets.spec.js @@ -61,7 +61,6 @@ export function testFlagSets(fetchMock, t) { t.test(async (assert) => { - assert.plan(3); let splitio, client, manager = []; setMockListener((eventSourceInstance) => { @@ -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); @@ -88,7 +86,6 @@ export function testFlagSets(fetchMock, t) { t.test(async (assert) => { - assert.plan(5); let splitio, client, manager = []; setMockListener((eventSourceInstance) => { @@ -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); @@ -132,7 +128,6 @@ export function testFlagSets(fetchMock, t) { t.test(async (assert) => { - assert.plan(6); let splitio, client, manager = []; setMockListener((eventSourceInstance) => { @@ -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); @@ -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'); @@ -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); @@ -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'); @@ -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); diff --git a/src/__tests__/browserSuites/telemetry.spec.js b/src/__tests__/browserSuites/telemetry.spec.js index 5d0c8f576..13eefa03b 100644 --- a/src/__tests__/browserSuites/telemetry.spec.js +++ b/src/__tests__/browserSuites/telemetry.spec.js @@ -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); @@ -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'); } diff --git a/src/__tests__/nodeSuites/fetch-specific-splits.spec.js b/src/__tests__/nodeSuites/fetch-specific-splits.spec.js index 6470b0a32..6c6849108 100644 --- a/src/__tests__/nodeSuites/fetch-specific-splits.spec.js +++ b/src/__tests__/nodeSuites/fetch-specific-splits.spec.js @@ -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 }; @@ -43,6 +43,9 @@ export default function fetchSpecificSplits(fetchMock, assert) { } } +} + +export function fetchSpecificSplitsForFlagSets(fetchMock, assert) { // Flag sets assert.test(async (t) => { diff --git a/src/__tests__/nodeSuites/flag-sets.spec.js b/src/__tests__/nodeSuites/flag-sets.spec.js index e43f6be76..c0c9d0b2e 100644 --- a/src/__tests__/nodeSuites/flag-sets.spec.js +++ b/src/__tests__/nodeSuites/flag-sets.spec.js @@ -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 @@ -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 = []; @@ -138,7 +136,6 @@ export default function flagSets(fetchMock, t) { t.test(async (assert) => { fetchMock.reset(); - assert.plan(8); let factory, client = []; @@ -176,7 +173,6 @@ export default function flagSets(fetchMock, t) { t.test(async (assert) => { fetchMock.reset(); - assert.plan(8); let factory, client = []; diff --git a/src/__tests__/nodeSuites/push-flag-sets.spec.js b/src/__tests__/nodeSuites/push-flag-sets.spec.js index d504a5084..75b828ca9 100644 --- a/src/__tests__/nodeSuites/push-flag-sets.spec.js +++ b/src/__tests__/nodeSuites/push-flag-sets.spec.js @@ -64,7 +64,6 @@ export function testFlagSets(fetchMock, t) { t.test(async (assert) => { - assert.plan(3); let splitio, client, manager = []; setMockListener((eventSourceInstance) => { @@ -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); @@ -91,7 +89,6 @@ export function testFlagSets(fetchMock, t) { t.test(async (assert) => { - assert.plan(5); let splitio, client, manager = []; setMockListener((eventSourceInstance) => { @@ -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); @@ -135,7 +131,6 @@ export function testFlagSets(fetchMock, t) { t.test(async (assert) => { - assert.plan(6); let splitio, client, manager = []; setMockListener((eventSourceInstance) => { @@ -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); @@ -187,8 +181,6 @@ export function testFlagSets(fetchMock, t) { t.test(async (assert) => { - assert.plan(5); - let splitio, client, manager = []; setMockListener((eventSourceInstance) => { @@ -196,7 +188,6 @@ export function testFlagSets(fetchMock, t) { 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 }}; }); @@ -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'); @@ -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); diff --git a/src/__tests__/online/browser.spec.js b/src/__tests__/online/browser.spec.js index 00218fb53..b873d31c8 100644 --- a/src/__tests__/online/browser.spec.js +++ b/src/__tests__/online/browser.spec.js @@ -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'; @@ -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(); diff --git a/src/__tests__/online/node.spec.js b/src/__tests__/online/node.spec.js index 9cb9eb873..f5a71b07d 100644 --- a/src/__tests__/online/node.spec.js +++ b/src/__tests__/online/node.spec.js @@ -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'; @@ -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));