From 084cd66618f29d7c3d0810dedd0429a7a5fbed81 Mon Sep 17 00:00:00 2001 From: Emmanuel Zamora Date: Mon, 29 Sep 2025 18:40:20 -0300 Subject: [PATCH 1/3] [FME-9858] Events mapping --- eslint.config.mts | 7 +- src/__tests__/integration/debug.test.js | 2 +- src/__tests__/integration/e2e-events.test.js | 141 +++++++++++++++++++ src/__tests__/integration/e2e.test.js | 28 ++-- src/__tests__/integration/mock.test.js | 6 +- src/__tests__/integration/working.test.js | 6 +- src/__tests__/provider.spec.js | 2 +- src/__tests__/webSuites/client.spec.js | 2 +- src/lib/js-split-provider.ts | 66 +++++---- 9 files changed, 210 insertions(+), 50 deletions(-) create mode 100644 src/__tests__/integration/e2e-events.test.js diff --git a/eslint.config.mts b/eslint.config.mts index ec99b89..fee5760 100644 --- a/eslint.config.mts +++ b/eslint.config.mts @@ -9,7 +9,10 @@ export default defineConfig([ files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], plugins: { js }, extends: ["js/recommended"], - languageOptions: { globals: globals.browser } + languageOptions: { globals: globals.browser }, + rules: { + semi: ["error", "always"], + } }, { files: ['**/*.{test,spec}.{js,ts,jsx,tsx}', '**/__tests__/**/*.{js,ts,jsx,tsx}'], @@ -24,4 +27,4 @@ export default defineConfig([ }, }, tseslint.configs.recommended, -]); +]); \ No newline at end of file diff --git a/src/__tests__/integration/debug.test.js b/src/__tests__/integration/debug.test.js index 6d8b96b..0bd6e5a 100644 --- a/src/__tests__/integration/debug.test.js +++ b/src/__tests__/integration/debug.test.js @@ -19,7 +19,7 @@ describe('OpenFeature Split Provider - Debug Tests', () => { 'int_feature': '32', 'obj_feature': '{"key": "value"}' } - }) + }); splitClient =splitFactory.client(); // Add direct Split client test to verify it works as expected diff --git a/src/__tests__/integration/e2e-events.test.js b/src/__tests__/integration/e2e-events.test.js new file mode 100644 index 0000000..fc26181 --- /dev/null +++ b/src/__tests__/integration/e2e-events.test.js @@ -0,0 +1,141 @@ +import { OpenFeature, ProviderEvents } from '@openfeature/web-sdk'; +import { SplitFactory, InLocalStorage } from '@splitsoftware/splitio-browserjs'; +import fetchMock from 'jest-fetch-mock'; + +import { OpenFeatureSplitProvider } from '../../lib/js-split-provider'; + +import splitChangesMock1 from '../mocks/splitchanges.since.-1.json'; +import membershipsEmmanuel from '../mocks/memberships.emmanuel@split.io.json'; + +// This is an end-to-end integration test that uses real clients (no mocks) +describe('OpenFeature Split Provider - E2E Integration Tests', () => { + const baseConfig = { + core: { + authorizationKey: 'key', + key: 'emmanuel@split.io' + }, + scheduler: { + featuresRefreshRate: 3000, + segmentsRefreshRate: 3000, + impressionsRefreshRate: 3000 + }, + startup: { + requestTimeoutBeforeReady: 10, + eventsFirstPushWindow: 3000 + }, + urls: { + sdk: 'https://sdk.baseurl/readinessSuite1', + events: 'https://events.baseurl/readinessSuite1' + }, + streamingEnabled: false, + }; + + // Set up before all tests + beforeAll(async () => { + fetchMock.enableMocks(); + fetchMock.mockIf(() => true, async req => { + if (req.url.includes('/splitChanges')) return { status: 200, body: JSON.stringify(splitChangesMock1) }; + if (req.url.includes('/memberships/emmanuel')) return { status: 200, body: JSON.stringify(membershipsEmmanuel) }; + if (req.url.includes('/testImpressions')) return { status: 200 }; + }); + + }); + + // Clean up after tests + afterEach(async () => { + await OpenFeature.clearProviders(); + await OpenFeature.clearHandlers(); + await OpenFeature.close(); + }); + + describe('Readiness events', () => { + + test('should emit Stale event when split sdk is ready from cache', async () => { + const config = { + ...baseConfig, + storage: InLocalStorage({ + prefix: 'readyFromCache_1' + }), + }; + + const splitFactory = SplitFactory(config); + const client = OpenFeature.getClient('readyFromCache'); + await new Promise((resolve, reject) => { + client.addHandler(ProviderEvents.Stale, () => { + const splitClient = splitFactory.client(); + // should have emitted ready from cache + try { + expect(splitClient.__getStatus().isReadyFromCache).toBe(true); + resolve(); + } catch { + reject('should be ready'); + } + }); + + const provider = new OpenFeatureSplitProvider(splitFactory); + OpenFeature.setProvider(provider); + }); + }); + + test('should emit Ready event when split sdk is ready', async () => { + const splitFactory = SplitFactory(baseConfig); + const provider = new OpenFeatureSplitProvider(splitFactory); + OpenFeature.setProvider(provider); + const client = OpenFeature.getClient(); + await new Promise((resolve, reject) => { + client.addHandler(ProviderEvents.Stale, () => { + reject('should not emit stale'); + }); + client.addHandler(ProviderEvents.Ready, () => { + const splitClient = splitFactory.client(); + try { + // should have emitted ready + expect(splitClient.__getStatus().isReady).toBe(true); + resolve(); + } catch { + reject('should be ready'); + } + }); + }); + }); + + test('should emit Error event when split sdk timed out', async () => { + // disable fetch mocks to force time out + fetchMock.disableMocks(); + + const config = { + ...baseConfig, + startup: { + readyTimeout: 1, + requestTimeoutBeforeReady: 1, + retriesOnFailureBeforeReady: 1 + }, + }; + const splitFactory = SplitFactory(config); + const client = OpenFeature.getClient('timedOut'); + + await new Promise((resolve, reject) => { + client.addHandler(ProviderEvents.Stale, () => { + reject('should not emit stale'); + }); + client.addHandler(ProviderEvents.Ready, () => { + reject('should not emit ready'); + }); + client.addHandler(ProviderEvents.Error, () => { + const splitClient = splitFactory.client(); + // should have emitted ready from cache + const clientStatus = splitClient.__getStatus(); + try { + expect(clientStatus.hasTimedout && !clientStatus.isReady).toBe(true); + resolve(); + } catch { + reject('should time out'); + } + }); + + const provider = new OpenFeatureSplitProvider(splitFactory); + OpenFeature.setProvider(provider); + }); + }); + }); +}); diff --git a/src/__tests__/integration/e2e.test.js b/src/__tests__/integration/e2e.test.js index 27e286d..d6b096d 100644 --- a/src/__tests__/integration/e2e.test.js +++ b/src/__tests__/integration/e2e.test.js @@ -5,9 +5,9 @@ import fetchMock from 'jest-fetch-mock'; import { OpenFeatureSplitProvider } from '../../lib/js-split-provider'; import splitChangesMock1 from '../mocks/splitchanges.since.-1.json'; -import membershipsEmmanuel from '../mocks/memberships.emmanuel@split.io.json' -import membershipsEmiliano from '../mocks/memberships.emiliano@split.io.json' -import membershipsNicolas from '../mocks/memberships.nicolas@split.io.json' +import membershipsEmmanuel from '../mocks/memberships.emmanuel@split.io.json'; +import membershipsEmiliano from '../mocks/memberships.emiliano@split.io.json'; +import membershipsNicolas from '../mocks/memberships.nicolas@split.io.json'; // This is an end-to-end integration test that uses real clients (no mocks) describe('OpenFeature Split Provider - E2E Integration Tests', () => { @@ -17,11 +17,11 @@ describe('OpenFeature Split Provider - E2E Integration Tests', () => { beforeAll(async () => { fetchMock.enableMocks(); fetchMock.mockIf(() => true, async req => { - if (req.url.includes('/splitChanges')) return { status: 200, body: JSON.stringify(splitChangesMock1) } - if (req.url.includes('/memberships/emmanuel')) return { status: 200, body: JSON.stringify(membershipsEmmanuel) } - if (req.url.includes('/memberships/emiliano')) return { status: 200, body: JSON.stringify(membershipsEmiliano) } - if (req.url.includes('/memberships/nicolas')) return { status: 200, body: JSON.stringify(membershipsNicolas) } - if (req.url.includes('/testImpressions')) return { status: 200 } + if (req.url.includes('/splitChanges')) return { status: 200, body: JSON.stringify(splitChangesMock1) }; + if (req.url.includes('/memberships/emmanuel')) return { status: 200, body: JSON.stringify(membershipsEmmanuel) }; + if (req.url.includes('/memberships/emiliano')) return { status: 200, body: JSON.stringify(membershipsEmiliano) }; + if (req.url.includes('/memberships/nicolas')) return { status: 200, body: JSON.stringify(membershipsNicolas) }; + if (req.url.includes('/testImpressions')) return { status: 200 }; }); const config = { @@ -33,30 +33,30 @@ describe('OpenFeature Split Provider - E2E Integration Tests', () => { sdk: 'https://sdk.baseurl/readinessSuite1', events: 'https://events.baseurl/readinessSuite1' } - } + }; const splitFactory = SplitFactory(config); const provider = new OpenFeatureSplitProvider(splitFactory); await OpenFeature.setProviderAndWait(provider); client = OpenFeature.getClient('integration-test'); - }) + }); // Clean up after all tests afterAll(async () => { - await OpenFeature.close() + await OpenFeature.close(); }); describe('Readiness events', () => { test('should emit openfeature client ready', async () => { await new Promise((resolve) => { client.addHandler(ProviderEvents.Ready, (eventDetails) => { - expect(eventDetails).toEqual({ clientName: 'integration-test', domain: 'integration-test', providerName: 'split' }) + expect(eventDetails).toEqual({ clientName: 'integration-test', domain: 'integration-test', providerName: 'split' }); resolve(); }); }); - }) - }) + }); + }); describe('Boolean evaluations', () => { diff --git a/src/__tests__/integration/mock.test.js b/src/__tests__/integration/mock.test.js index 0bb4a65..bb240e3 100644 --- a/src/__tests__/integration/mock.test.js +++ b/src/__tests__/integration/mock.test.js @@ -38,12 +38,12 @@ describe('OpenFeature Split Provider - Mock Integration Tests', () => { const mockSplitFactory = { client: () => mockSplitClient, destroy: () => {} - } + }; provider = new OpenFeatureSplitProvider(mockSplitFactory); // Register with OpenFeature OpenFeature.setProviderAndWait(provider); - OpenFeature.setContext({ targetingKey: 'user1' }) + OpenFeature.setContext({ targetingKey: 'user1' }); // Get the client client = OpenFeature.getClient('mock-test'); @@ -84,7 +84,7 @@ describe('OpenFeature Split Provider - Mock Integration Tests', () => { expect(details.value).toBe(true); expect(details.variant).toBe('on'); expect(details.flagKey).toBe('my_feature'); - expect(details.flagMetadata.config).toBe('{"desc": "this is a test"}') + expect(details.flagMetadata.config).toBe('{"desc": "this is a test"}'); expect(details.reason).toBe('TARGETING_MATCH'); }); diff --git a/src/__tests__/integration/working.test.js b/src/__tests__/integration/working.test.js index 313f161..b093edf 100644 --- a/src/__tests__/integration/working.test.js +++ b/src/__tests__/integration/working.test.js @@ -26,13 +26,13 @@ describe('OpenFeature Split Provider - Working Integration Test', () => { authorizationKey: 'localhost' }, features: localFeatures - }) + }); splitClient = splitFactory.client(); provider = new OpenFeatureSplitProvider(splitFactory); OpenFeature.setProvider(provider); - await OpenFeature.setContext({targetingKey: 'user1'}) + await OpenFeature.setContext({targetingKey: 'user1'}); client = OpenFeature.getClient('test'); }); @@ -53,7 +53,7 @@ describe('OpenFeature Split Provider - Working Integration Test', () => { // Test the boolean value evaluation const result = await client.getBooleanDetails('my_feature', false); expect(result.value).toBe(true); - expect(result.flagMetadata.config).toBe('{"desc": "this is a test"}') + expect(result.flagMetadata.config).toBe('{"desc": "this is a test"}'); }); // Add a test for string treatment diff --git a/src/__tests__/provider.spec.js b/src/__tests__/provider.spec.js index db6c4ce..9c92c49 100644 --- a/src/__tests__/provider.spec.js +++ b/src/__tests__/provider.spec.js @@ -58,7 +58,7 @@ describe('OpenFeatureSplitProvider Unit Tests', () => { expect(result.value).toBe(true); expect(result.variant).toBe('on'); - expect(result.flagMetadata.config).toBe('{"desc": "this is a test"}') + expect(result.flagMetadata.config).toBe('{"desc": "this is a test"}'); expect(mockSplitClient.getTreatmentWithConfig).toHaveBeenCalledWith( 'boolean-flag', {} diff --git a/src/__tests__/webSuites/client.spec.js b/src/__tests__/webSuites/client.spec.js index 9b98648..0e272ed 100644 --- a/src/__tests__/webSuites/client.spec.js +++ b/src/__tests__/webSuites/client.spec.js @@ -18,7 +18,7 @@ const mockFeatures = { treatment: '{"key": "value"}' } }; -let mockSplitClient +let mockSplitClient; // Mock SplitIO SDK - Web version jest.mock('@splitsoftware/splitio-browserjs', () => { diff --git a/src/lib/js-split-provider.ts b/src/lib/js-split-provider.ts index 5f01d02..8df52c0 100644 --- a/src/lib/js-split-provider.ts +++ b/src/lib/js-split-provider.ts @@ -31,7 +31,7 @@ export class OpenFeatureSplitProvider implements Provider { private client: SplitIO.IBrowserClient; private factory: SplitIO.IBrowserSDK; private trafficType: string; - public readonly events = new OpenFeatureEventEmitter(); + public events = new OpenFeatureEventEmitter(); onContextChange(oldContext: EvaluationContext, newContext: EvaluationContext): Promise { const { targetingKey: oldTargetingKey } = oldContext; @@ -43,10 +43,11 @@ export class OpenFeatureSplitProvider implements Provider { return new Promise((resolve, reject) => { const emitContextChange = () => { - this.events.emit(ProviderEvents.Ready); + this.events.emit(ProviderEvents.ConfigurationChanged); resolve(); - } - this.readinessHandler(emitContextChange, reject); + }; + + this.eventsHandler(emitContextChange, reject); }); } return Promise.resolve(); @@ -55,13 +56,19 @@ export class OpenFeatureSplitProvider implements Provider { constructor(splitFactory: SplitIO.IBrowserSDK) { // Asume 'user' as default traffic type' this.trafficType = 'user'; - this.factory = splitFactory + this.factory = splitFactory; this.client = splitFactory.client(); - this.client.on(this.client.Event.SDK_UPDATE, () => { - this.events.emit(ProviderEvents.ConfigurationChanged) - }); + } - this.readinessHandler(); + async initialize(): Promise { + + await new Promise ((resolve, reject) => { + try { + this.eventsHandler(resolve, reject); + } catch { + reject(); + } + }); } resolveBooleanEvaluation( @@ -140,7 +147,7 @@ export class OpenFeatureSplitProvider implements Provider { flagKey, consumer.attributes ); - const {treatment: value, config} = treatment + const {treatment: value, config} = treatment; if (value === CONTROL_TREATMENT) { throw new FlagNotFoundError(CONTROL_VALUE_ERROR_MESSAGE); @@ -230,27 +237,36 @@ export class OpenFeatureSplitProvider implements Provider { } } - private readinessHandler(onSdkReady?: () => any, onSdkTimedOut?: () => any): void { - onSdkReady = onSdkReady ? onSdkReady : () => { - console.log(`${this.metadata.name} provider initialized`); - this.events.emit(ProviderEvents.Ready) - }; + private async eventsHandler(onSdkReady: (params?: any) => void, onSdkTimedOut: () => void): Promise { - onSdkTimedOut = onSdkTimedOut ? onSdkTimedOut : () => { - console.log(`${this.metadata.name} provider couldn't initialize`); - this.events.emit(ProviderEvents.Error); + const onSdkReadyFromCache = () => { + console.log(`${this.metadata.name} provider initialized`); + this.events.emit(ProviderEvents.Stale, { + message: `Split ready from cache`, + }); }; const clientStatus = (this.client as any).__getStatus(); if (clientStatus.isReady) { onSdkReady(); - return; - } - if (clientStatus.hasTimedout || clientStatus.isTimedOut) { - onSdkTimedOut(); - return; + } else { + + if (clientStatus.isReadyFromCache) { + onSdkReadyFromCache(); + } else { + this.client.on(this.client.Event.SDK_READY_FROM_CACHE, onSdkReadyFromCache); + } + + if (clientStatus.hasTimedout) { + onSdkTimedOut(); + } else { + this.client.on(this.client.Event.SDK_READY_TIMED_OUT, onSdkTimedOut); + } + this.client.on(this.client.Event.SDK_READY, onSdkReady); } - this.client.on(this.client.Event.SDK_READY, onSdkReady); - this.client.on(this.client.Event.SDK_READY_TIMED_OUT, onSdkTimedOut); + + this.client.on(this.client.Event.SDK_UPDATE, () => { + this.events.emit(ProviderEvents.ConfigurationChanged); + }); } } From 80cc75e447cd23c8e419d1ecdb9bff1f4c962113 Mon Sep 17 00:00:00 2001 From: Emmanuel Zamora Date: Tue, 30 Sep 2025 14:51:46 -0300 Subject: [PATCH 2/3] Add client ready after timeout test --- src/__tests__/integration/e2e-events.test.js | 61 ++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/__tests__/integration/e2e-events.test.js b/src/__tests__/integration/e2e-events.test.js index fc26181..20b1917 100644 --- a/src/__tests__/integration/e2e-events.test.js +++ b/src/__tests__/integration/e2e-events.test.js @@ -6,6 +6,7 @@ import { OpenFeatureSplitProvider } from '../../lib/js-split-provider'; import splitChangesMock1 from '../mocks/splitchanges.since.-1.json'; import membershipsEmmanuel from '../mocks/memberships.emmanuel@split.io.json'; +import membershipsEmiliano from '../mocks/memberships.emiliano@split.io.json'; // This is an end-to-end integration test that uses real clients (no mocks) describe('OpenFeature Split Provider - E2E Integration Tests', () => { @@ -99,6 +100,66 @@ describe('OpenFeature Split Provider - E2E Integration Tests', () => { }); }); + test('should emit ready after timeout', async () => { + fetchMock.mockIf(() => true, async req => { + if (req.url.includes('/splitChanges')) return { status: 200, body: JSON.stringify(splitChangesMock1) }; + if (req.url.includes('/memberships/emmanuel')) return { status: 200, body: JSON.stringify(membershipsEmmanuel) }; + if (req.url.includes('/testImpressions')) return { status: 200 }; + }); + + const config = { + ...baseConfig, + scheduler: { + featuresRefreshRate: 3, + segmentsRefreshRate: 0.25, + }, + startup: { + readyTimeout: 0.2, + requestTimeoutBeforeReady: 0.1, + retriesOnFailureBeforeReady: 10 + }, + }; + const splitFactory = SplitFactory(config); + const client = OpenFeature.getClient(); + + await new Promise((resolve, reject) => { + + client.addHandler(ProviderEvents.Stale, () => { + reject('should not emit stale'); + }); + + client.addHandler(ProviderEvents.Ready, () => { + + // initialize a new client and make it time out + OpenFeature.setContext({targetingKey: 'emiliano@split.io'}); + client.addHandler(ProviderEvents.Error, () => { + + // new client timed out, when ready should emit Configuration Changed event + client.addHandler(ProviderEvents.ConfigurationChanged, async () => { + const details = await client.getStringDetails('developers', 'default'); + expect(details.value).toBe('on'); + expect(details.flagKey).toBe('developers'); + expect(details.reason).toBe('TARGETING_MATCH'); + expect(details.variant).toBe('on'); + expect(details.flagMetadata.config).toBe('{"color":"blue"}'); + resolve(); + }); + + // add timed out client membership to get it ready + fetchMock.mockIf(() => true, async req => { + if (req.url.includes('/splitChanges')) return { status: 200, body: JSON.stringify(splitChangesMock1) }; + if (req.url.includes('/memberships/emmanuel')) return { status: 200, body: JSON.stringify(membershipsEmmanuel) }; + if (req.url.includes('/memberships/emiliano')) return { status: 200, body: JSON.stringify(membershipsEmiliano) }; + if (req.url.includes('/testImpressions')) return { status: 200 }; + }); + }); + }); + + const provider = new OpenFeatureSplitProvider(splitFactory); + OpenFeature.setProvider(provider); + }); + }); + test('should emit Error event when split sdk timed out', async () => { // disable fetch mocks to force time out fetchMock.disableMocks(); From 9c63a9593162a140453b841c7a65a4759aa096c6 Mon Sep 17 00:00:00 2001 From: Emmanuel Zamora Date: Tue, 30 Sep 2025 15:17:04 -0300 Subject: [PATCH 3/3] Remove console log and clean files --- scripts/sdk.unit.testing.setup | 341 --------------------------------- scripts/ts-tests.sh | 28 --- src/lib/js-split-provider.ts | 1 - 3 files changed, 370 deletions(-) delete mode 100755 scripts/sdk.unit.testing.setup delete mode 100755 scripts/ts-tests.sh diff --git a/scripts/sdk.unit.testing.setup b/scripts/sdk.unit.testing.setup deleted file mode 100755 index a70f3e3..0000000 --- a/scripts/sdk.unit.testing.setup +++ /dev/null @@ -1,341 +0,0 @@ -#!/usr/bin/env node - -'use strict'; - -const exec = require('child_process').execSync; - -// SETUP THE ENVIRONMENT HERE! -const orgId = 'e9dd7c90-0110-11e6-8aff-cea8d6f43ae4'; // Google -const environment = 'eab73ac0-0110-11e6-8aff-cea8d6f43ae4'; // production -const TOKEN = 'ZDA1Y2JmNjAtMzI0My00ZmMwLWIxODUtMWIzYWY5ZTE0M2M3'; // woow -const SDK_TOKEN = 'lu78o1osahssej3bevbnqkkvfr1ahjoj706v'; // production -// SETUP THE ENVIRONMENT HERE! - -function createTestCurl(spec) { - return `curl 'https://api.split.io/internal/api/tests' -H 'Authorization: Bearer ${TOKEN}' -H 'Content-Type: application/json' --data-binary '${JSON.stringify(spec)}'`; -} - -//------------------------------------------------------------------------------ - -const user_attr_eq_10 = { - name: 'user_attr_eq_ten', - description: 'user.attr = 10', - definition: 'if user.attr = 10 then split 100:on', - treatments: [ - { name: 'on', - includes: [], - description: null }, - { name: 'off', - includes: [], - description: null } - ], - environment, - orgId -}; - -const user_attr_eq_number_10 = { - name: 'user_attr_eq_number_ten', - description: 'user.attr = number 10', - definition: 'if user.attr = number 10 then split 100:on', - treatments: [ - { name: 'on', - includes: [], - description: null }, - { name: 'off', - includes: [], - description: null } - ], - environment, - orgId -}; - -// new Date(1458240947021) -// Thu Mar 17 2016 15:55:47 GMT-0300 (ART) -const user_attr_eq_datetime_1458240947021 = { - name: 'user_attr_eq_datetime_1458240947021', - description: 'user.attr = datetime 1458240947021', - definition: 'if user.attr = datetime 1458240947021 then split 100:on', - treatments: [ - { name: 'on', - includes: [], - description: null }, - { name: 'off', - includes: [], - description: null } - ], - environment, - orgId -}; - -//------------------------------------------------------------------------------ - -const user_attr_gte_10 = { - name: 'user_attr_gte_10', - description: 'user.attr >= 10', - definition: 'if user.attr >= 10 then split 100:on', - treatments: [ - { name: 'on', - includes: [], - description: null }, - { name: 'off', - includes: [], - description: null } - ], - environment, - orgId -}; - -const user_attr_gte_number_10 = { - name: 'user_attr_gte_number_10', - description: 'user.attr >= number 10', - definition: 'if user.attr >= number 10 then split 100:on', - treatments: [ - { name: 'on', - includes: [], - description: null }, - { name: 'off', - includes: [], - description: null } - ], - environment, - orgId -}; - -const user_attr_gte_datetime_1458240947021 = { - name: 'user_attr_gte_datetime_1458240947021', - description: 'user.attr >= datetime 1458240947021', - definition: 'if user.attr >= datetime 1458240947021 then split 100:on', - treatments: [ - { name: 'on', - includes: [], - description: null }, - { name: 'off', - includes: [], - description: null } - ], - environment, - orgId -}; - -//------------------------------------------------------------------------------ - -const user_attr_lte_10 = { - name: 'user_attr_lte_10', - description: 'user.attr <= 10', - definition: 'if user.attr <= 10 then split 100:on', - treatments: [ - { name: 'on', - includes: [], - description: null }, - { name: 'off', - includes: [], - description: null } - ], - environment, - orgId -}; - -const user_attr_lte_number_10 = { - name: 'user_attr_lte_number_10', - description: 'user.attr <= number 10', - definition: 'if user.attr <= number 10 then split 100:on', - treatments: [ - { name: 'on', - includes: [], - description: null }, - { name: 'off', - includes: [], - description: null } - ], - environment, - orgId -}; - -const user_attr_lte_datetime_1458240947021 = { - name: 'user_attr_lte_datetime_1458240947021', - description: 'user.attr <= datetime 1458240947021', - definition: 'if user.attr <= datetime 1458240947021 then split 100:on', - treatments: [ - { name: 'on', - includes: [], - description: null }, - { name: 'off', - includes: [], - description: null } - ], - environment, - orgId -}; - -//------------------------------------------------------------------------------ - -const user_attr_btw_10_and_20 = { - name: 'user_attr_btw_10_and_20', - description: 'user.attr between 10 and 20', - definition: 'if user.attr is between 10 and 20 then split 100:on', - treatments: [ - { name: 'on', - includes: [], - description: null }, - { name: 'off', - includes: [], - description: null } - ], - environment, - orgId -}; - -const user_attr_btw_number_10_and_20 = { - name: 'user_attr_btw_number_10_and_20', - description: 'user.attr between number 10 and 20', - definition: 'if user.attr is between number 10 and 20 then split 100:on', - treatments: [ - { name: 'on', - includes: [], - description: null }, - { name: 'off', - includes: [], - description: null } - ], - environment, - orgId -}; - - -// new Date(1458240947021) -// Thu Mar 17 2016 15:55:47 GMT-0300 (ART) -// new Date(1458246884077) -// Thu Mar 17 2016 17:34:44 GMT-0300 (ART) -const user_attr_btw_datetime_1458240947021_and_1458246884077 = { - name: 'user_attr_btw_datetime_1458240947021_and_1458246884077', - description: 'user.attr between datetime 1458240947021 and 1458246884077', - definition: 'if user.attr is between datetime 1458240947021 and 1458246884077 then split 100:on', - treatments: [ - { name: 'on', - includes: [], - description: null }, - { name: 'off', - includes: [], - description: null } - ], - environment, - orgId -}; - -//------------------------------------------------------------------------------ - -const user_account_in_segment_all = { - name: 'user_account_in_segment_all', - description: 'user.account in segment all', - definition: 'if user.account is in segment all then split 100:on', - treatments: [ - { name: 'on', - includes: [], - description: null }, - { name: 'off', - includes: [], - description: null } - ], - environment, - orgId -}; - -const user_account_in_segment_employees = { - name: 'user_account_in_segment_employees', - description: 'user.account in segment employees', - definition: 'if user.account is in segment employees then split 100:on', - treatments: [ - { name: 'on', - includes: [], - description: null }, - { name: 'off', - includes: [], - description: null } - ], - environment, - orgId -}; - -const user_account_in_whitelist = { - name: 'user_account_in_whitelist', - description: 'user.account in whitelist', - definition: 'if user.account is in list ["key_1@split.io", "key_2@split.io", "key_3@split.io", "key_4@split.io", "key_5@split.io"] then split 100:on', - treatments: [ - { name: 'on', - includes: [], - description: null }, - { name: 'off', - includes: [], - description: null } - ], - environment, - orgId -}; - -//------------------------------------------------------------------------------ - -const user_between_dates_or_admin = { - name: 'user_between_dates_or_admin', - description: 'user between dates or is in admin segment', - definition: ` - if user.time is between datetime 1458240947021 and 1458246884077 then split 100:on - else if user is in segment admin then 100:on - `, - treatments: [ - { name: 'on', - includes: [], - description: null }, - { name: 'off', - includes: [], - description: null } - ], - environment, - orgId -}; - -//------------------------------------------------------------------------------ - -const user_attr_gte_10_and_user_attr2_is_not_foo = { - name: 'user_attr_gte_10_and_user_attr2_is_not_foo', - description: 'user.attr >= 10 and user.attr2 not foo', - definition: ` - if user.attr >= 10 and user.attr2 is not in list ["foo"] then split 100%:on - `, - treatments: [ - { name: 'on', - includes: [], - description: null }, - { name: 'off', - includes: [], - description: null } - ], - environment, - orgId -}; - -//------------------------------------------------------------------------------ - -// Loop over each item in the array an hit the backend -[ - user_attr_eq_10, - user_attr_eq_number_10, - user_attr_eq_datetime_1458240947021, - user_attr_gte_10, - user_attr_gte_number_10, - user_attr_gte_datetime_1458240947021, - user_attr_lte_10, - user_attr_lte_number_10, - user_attr_lte_datetime_1458240947021, - user_attr_btw_10_and_20, - user_attr_btw_number_10_and_20, - user_attr_btw_datetime_1458240947021_and_1458246884077, - user_account_in_segment_all, - user_account_in_segment_employees, - user_account_in_whitelist, - user_between_dates_or_admin, - user_attr_gte_10_and_user_attr2_is_not_foo -].forEach(function (body) { - let cmd = createTestCurl(body); - console.log(cmd); - exec(cmd); -}); diff --git a/scripts/ts-tests.sh b/scripts/ts-tests.sh deleted file mode 100755 index 2263e92..0000000 --- a/scripts/ts-tests.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -cd ts-tests ## Go to typescript tests folder -echo "Installing dependencies for TypeScript declarations testing..." -npm install ## Install dependencies -npm install @types/node@6.0.31 ## Install type definitions for Node.js v6.x (the oldest supported version) -echo "Dependencies installed, linking the package." -npm link @splitsoftware/splitio ## Link to the cloned code -echo "Running tsc compiler." -./node_modules/.bin/tsc ## Run typescript compiler. No need for flags as we have a tsconfig.json file - -echo "Testing again with the latest @types/node version..." -npm install @types/node@14 ## Install latest type definitions for Node.js -echo "Dependencies installed, linking the package." -npm link @splitsoftware/splitio ## Link to the cloned code -echo "Running tsc compiler." -./node_modules/.bin/tsc ## Run typescript compiler. No need for flags as we have a tsconfig.json file - -if [ $? -eq 0 ] -then - echo "✅ Successfully compiled TS tests." - npm unlink @splitsoftware/splitio - exit 0 -else - echo "☠️ Error compiling TS tests." - npm unlink @splitsoftware/splitio - exit 1 -fi diff --git a/src/lib/js-split-provider.ts b/src/lib/js-split-provider.ts index 8df52c0..ec6d761 100644 --- a/src/lib/js-split-provider.ts +++ b/src/lib/js-split-provider.ts @@ -240,7 +240,6 @@ export class OpenFeatureSplitProvider implements Provider { private async eventsHandler(onSdkReady: (params?: any) => void, onSdkTimedOut: () => void): Promise { const onSdkReadyFromCache = () => { - console.log(`${this.metadata.name} provider initialized`); this.events.emit(ProviderEvents.Stale, { message: `Split ready from cache`, });