Skip to content

Commit

Permalink
Update ts-test. Add tests for lazy init
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilianoSanchez committed Oct 18, 2024
1 parent d58d8e3 commit 9dce402
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
10.29.0 (September XX, 2024)
10.29.0 (October XX, 2024)
- Added `factory.destroy()` method, which invokes the `destroy` method on all SDK clients created by the factory.
- Updated @splitsoftware/splitio-commons package to version 1.18.0 that includes minor updates:
- Added support for targeting rules based on large segments for browsers.
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@splitsoftware/splitio",
"version": "10.28.1-rc.2",
"version": "10.28.1-rc.4",
"description": "Split SDK",
"files": [
"README.md",
Expand Down Expand Up @@ -40,7 +40,7 @@
"node": ">=6"
},
"dependencies": {
"@splitsoftware/splitio-commons": "1.17.1-rc.1",
"@splitsoftware/splitio-commons": "1.17.1-rc.3",
"@types/google.analytics": "0.0.40",
"@types/ioredis": "^4.28.0",
"bloom-filters": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/browserSuites/ready-promise.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ export default function readyPromiseAssertions(fetchMock, assert) {
});
}, 0);
});
}, fromSecondsToMillis(0.2));
}, fromSecondsToMillis(0.25));

}, 'Validate that warning messages are properly sent');

Expand Down
89 changes: 89 additions & 0 deletions src/__tests__/nodeSuites/lazy-init.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { SplitFactory as SplitFactorySS } from '../../factory/node';
import { SplitFactory as SplitFactoryCS } from '../../factory/browser';

// Tests should finish without dangling timers or requests
export default function (settings, fetchMock, t) {

t.test('Server-side', async (assert) => {
let splitio;

for (let i = 0; i < 100; i++) {
splitio = SplitFactorySS({
core: {
authorizationKey: 'fake-token-' + i,
},
urls: {
sdk: 'https://not-called/api',
events: 'https://not-called/api',
auth: 'https://not-called/api',
}
}, (modules) => {
modules.lazyInit = true;
});

const manager = splitio.manager();
assert.deepEqual(manager.names(), [], 'We should not have done any request yet');

const client = splitio.client();
assert.equal(client.getTreatment('user-1', 'split_test'), 'control', 'We should get control');
assert.equal(client.track('user-1', 'user', 'my_event'), true, 'We should track the event');
}

fetchMock.getOnce('https://not-called/api/splitChanges?s=1.1&since=-1', { status: 200, body: { splits: [], since: -1, till: 1457552620999 } });
fetchMock.getOnce('https://not-called/api/splitChanges?s=1.1&since=1457552620999', { status: 200, body: { splits: [], since: 1457552620999, till: 1457552620999 } });
fetchMock.postOnce('https://not-called/api/testImpressions/bulk', 200);
fetchMock.postOnce('https://not-called/api/events/bulk', 200);

splitio.init();
await splitio.client().ready();
assert.true(splitio.client().__getStatus().isReady, 'Split SDK is ready');
await splitio.destroy();

assert.end();
});

t.test('Client-side', async (assert) => {
let splitio;

for (let i = 0; i < 100; i++) {
splitio = SplitFactoryCS({
core: {
authorizationKey: 'fake-token-' + i,
key: 'user-' + i,
},
urls: {
sdk: 'https://not-called/api',
events: 'https://not-called/api',
auth: 'https://not-called/api',
}
}, (modules) => {
modules.lazyInit = true;
});

const manager = splitio.manager();
assert.deepEqual(manager.names(), [], 'We should not have done any request yet');

const client = splitio.client();
assert.equal(client.getTreatment('split_test'), 'control', 'We should get control');
assert.equal(client.track('user', 'my_event'), true, 'We should track the event');

const otherClient = splitio.client('other-user');
assert.equal(otherClient.getTreatment('split_test'), 'control', 'We should get control');
assert.equal(otherClient.track('user', 'my_event'), true, 'We should track the event');
}

fetchMock.getOnce('https://not-called/api/splitChanges?s=1.2&since=-1', { status: 200, body: { splits: [], since: -1, till: 1457552620999 } });
fetchMock.getOnce('https://not-called/api/splitChanges?s=1.2&since=1457552620999', { status: 200, body: { splits: [], since: 1457552620999, till: 1457552620999 } });
fetchMock.getOnce('https://not-called/api/memberships/user-99', { status: 200, body: {} });
fetchMock.getOnce('https://not-called/api/memberships/other-user', { status: 200, body: {} });
fetchMock.postOnce('https://not-called/api/testImpressions/bulk', 200);
fetchMock.postOnce('https://not-called/api/events/bulk', 200);

splitio.init();
await splitio.client().ready();
assert.true(splitio.client().__getStatus().isReady, 'Split SDK is ready');
await splitio.destroy();

assert.end();
});
}
9 changes: 6 additions & 3 deletions src/__tests__/online/node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import fetchMock from '../testUtils/nodeFetchMock';
import { url } from '../testUtils';
import { settingsFactory } from '../../settings/node';

import splitChangesMock1 from '../mocks/splitchanges.since.-1.json';
import splitChangesMock2 from '../mocks/splitchanges.since.1457552620999.json';

import evaluationsSuite from '../nodeSuites/evaluations.spec';
import evaluationsSemverSuite from '../nodeSuites/evaluations-semver.spec';
import eventsSuite from '../nodeSuites/events.spec';
Expand All @@ -18,10 +21,8 @@ import ipAddressesSettingDebug from '../nodeSuites/ip-addresses-setting.debug.sp
import readinessSuite from '../nodeSuites/readiness.spec';
import readyPromiseSuite from '../nodeSuites/ready-promise.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';
import flagSets from '../nodeSuites/flag-sets.spec';
import lazyInitSuite from '../nodeSuites/lazy-init.spec';

const config = {
core: {
Expand Down Expand Up @@ -94,5 +95,7 @@ tape('## Node JS - E2E CI Tests ##', async function (assert) {
/* Validate flag sets */
assert.test('E2E / Flag sets', flagSets.bind(null, fetchMock));

assert.test('E2E / SplitFactory with lazy init', lazyInitSuite.bind(null, settings, fetchMock));

assert.end();
});
2 changes: 1 addition & 1 deletion src/settings/defaults/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const packageVersion = '10.28.1-rc.2';
export const packageVersion = '10.28.1-rc.4';
2 changes: 1 addition & 1 deletion ts-tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ browserSettings = {
}
};
// With sync settings should return ISDK, if settings have async storage it should return IAsyncSDK
SDK = SplitFactory(browserSettings);
SDK = SplitFactory(nodeSettings);
AsyncSDK = SplitFactory(asyncSettings);
BrowserSDK = SplitFactory(browserSettings);
Expand Down Expand Up @@ -196,6 +195,7 @@ SDK.settings.features = { 'split_x': 'on' }; // Browser
// Client and Manager
client = SDK.client();
manager = SDK.manager();
manager = BrowserSDK.manager();
// Today async clients are only possible on Node. Shared client creation not available here.
asyncClient = AsyncSDK.client();
asyncManager = AsyncSDK.manager();
Expand Down
6 changes: 6 additions & 0 deletions types/splitio.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,12 @@ declare namespace SplitIO {
* @returns {IBrowserClient} The client instance.
*/
client(key: SplitKey, trafficType?: string): IBrowserClient
/**
* Returns a manager instance of the SDK to explore available information.
* @function manager
* @returns {IManager} The manager instance.
*/
manager(): IManager,
/**
* User consent API.
* @property UserConsent
Expand Down

0 comments on commit 9dce402

Please sign in to comment.