Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add defaultTreatment to SplitView #769

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
10.24.0 (October XX, 2023)
- Added `defaultTreatment` property to the `SplitView` object returned by the `split` and `splits` methods of the SDK manager (Related to issue https://github.com/splitio/javascript-commons/issues/225).
- Updated @splitsoftware/splitio-commons package to version 1.10.0 that includes vulnerability fixes, and adds the `defaultTreatment` property to the `SplitView` object.

10.23.1 (September 22, 2023)
- Updated @splitsoftware/splitio-commons package to version 1.9.1. This update removes the handler for 'unload' DOM events, that can prevent browsers from being able to put pages in the back/forward cache for faster back and forward loads (Related to issue https://github.com/splitio/javascript-client/issues/759).

Expand Down
14 changes: 7 additions & 7 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
Expand Up @@ -40,7 +40,7 @@
"node": ">=6"
},
"dependencies": {
"@splitsoftware/splitio-commons": "1.9.1",
"@splitsoftware/splitio-commons": "1.10.0",
"@types/google.analytics": "0.0.40",
"@types/ioredis": "^4.28.0",
"bloom-filters": "^3.0.0",
Expand Down Expand Up @@ -100,7 +100,7 @@
"check:version": "cross-env NODE_ENV=test tape -r ./ts-node.register src/settings/__tests__/defaults.spec.js",
"test-browser": "npm run test-browser-unit && npm run test-browser-e2e",
"test-browser-unit": "cross-env NODE_ENV=test karma start karma/unit.karma.conf.js",
"test-browser-e2e": "npm run test-browser-e2e-online && npm run test-browser-e2e-offline && npm run test-browser-e2e-destroy && npm run test-browser-e2e-errorCatching && npm run test-browser-e2e-push && npm run test-browser-e2e-gaIntegration",
"test-browser-e2e": "npm run test-browser-e2e-online && npm run test-browser-e2e-offline && npm run test-browser-e2e-destroy && npm run test-browser-e2e-errorCatching && npm run test-browser-e2e-push",
"test-browser-e2e-online": "cross-env NODE_ENV=test karma start karma/e2e.online.karma.conf.js",
"test-browser-e2e-offline": "cross-env NODE_ENV=test karma start karma/e2e.offline.karma.conf.js",
"test-browser-e2e-destroy": "cross-env NODE_ENV=test karma start karma/e2e.destroy.karma.conf.js",
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/browserSuites/manager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export default async function (settings, fetchMock, assert) {
'killed': mockSplits.splits[index].killed,
'changeNumber': mockSplits.splits[index].changeNumber,
'treatments': map(mockSplits.splits[index].conditions[0].partitions, partition => partition.treatment),
'configs': mockSplits.splits[index].configurations || {}
'configs': mockSplits.splits[index].configurations || {},
'defaultTreatment': mockSplits.splits[index].defaultTreatment
});

assert.equal(manager.split('non_existent'), null, 'Trying to get a manager.split() of a Split that does not exist returns null.');
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 @@ -31,7 +31,7 @@ function assertGetTreatmentWhenReady(assert, client) {
function assertGetTreatmentControlNotReady(assert, client) {
consoleSpy.log.resetHistory();
assert.equal(client.getTreatment('hierarchical_splits_test'), 'control', 'We should get control if client is not ready.');
assert.true(consoleSpy.log.calledWithExactly('[WARN] splitio => getTreatment: the SDK is not ready, results may be incorrect. Make sure to wait for SDK readiness before using this method.'), 'Telling us that calling getTreatment would return CONTROL since SDK is not ready at this point.');
assert.true(consoleSpy.log.calledWithExactly('[WARN] splitio => getTreatment: the SDK is not ready, results may be incorrect for feature flag hierarchical_splits_test. Make sure to wait for SDK readiness before using this method.'), 'Telling us that calling getTreatment would return CONTROL since SDK is not ready at this point.');
}

function assertGetTreatmentControlNotReadyOnDestroy(assert, client) {
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/nodeSuites/manager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export default async function (settings, fetchMock, assert) {
'killed': mockSplits.splits[index].killed,
'changeNumber': mockSplits.splits[index].changeNumber,
'treatments': map(mockSplits.splits[index].conditions[0].partitions, partition => partition.treatment),
'configs': mockSplits.splits[index].configurations || {}
'configs': mockSplits.splits[index].configurations || {},
'defaultTreatment': mockSplits.splits[index].defaultTreatment
});

assert.equal(manager.split('non_existent'), null, 'Trying to get a manager.split() of a Split that does not exist returns null.');
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/nodeSuites/ready-promise.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function assertGetTreatmentWhenReady(assert, client, key) {
function assertGetTreatmentControlNotReady(assert, client, key) {
consoleSpy.log.resetHistory();
assert.equal(client.getTreatment(key, 'hierarchical_splits_test'), 'control', 'We should get control if client is not ready.');
assert.true(consoleSpy.log.calledWithExactly('[WARN] splitio => getTreatment: the SDK is not ready, results may be incorrect. Make sure to wait for SDK readiness before using this method.'), 'Telling us that calling getTreatment would return CONTROL since SDK is not ready at this point.');
assert.true(consoleSpy.log.calledWithExactly('[WARN] splitio => getTreatment: the SDK is not ready, results may be incorrect for feature flag hierarchical_splits_test. Make sure to wait for SDK readiness before using this method.'), 'Telling us that calling getTreatment would return CONTROL since SDK is not ready at this point.');
}

function assertGetTreatmentControlNotReadyOnDestroy(assert, client, key) {
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/offline/browser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ tape('Browser offline mode', function (assert) {

// Manager tests
const expectedSplitView1 = {
name: 'testing_split', trafficType: 'localhost', killed: false, changeNumber: 0, treatments: ['on'], configs: {}
name: 'testing_split', trafficType: 'localhost', killed: false, changeNumber: 0, treatments: ['on'], configs: {}, defaultTreatment: 'control'
};
const expectedSplitView2 = {
name: 'testing_split_with_config', trafficType: 'localhost', killed: false, changeNumber: 0, treatments: ['off'], configs: { off: '{ "color": "blue" }' }
name: 'testing_split_with_config', trafficType: 'localhost', killed: false, changeNumber: 0, treatments: ['off'], configs: { off: '{ "color": "blue" }' }, defaultTreatment: 'control'
};
assert.deepEqual(manager.names(), ['testing_split', 'testing_split_with_config']);
assert.deepEqual(manager.split('testing_split'), expectedSplitView1);
Expand Down Expand Up @@ -267,7 +267,7 @@ tape('Browser offline mode', function (assert) {

// Manager tests
const expectedSplitView3 = {
name: 'testing_split_with_config', trafficType: 'localhost', killed: false, changeNumber: 0, treatments: ['nope'], configs: {}
name: 'testing_split_with_config', trafficType: 'localhost', killed: false, changeNumber: 0, treatments: ['nope'], configs: {}, defaultTreatment: 'control'
};
assert.deepEqual(manager.names(), ['testing_split', 'testing_split_2', 'testing_split_3', 'testing_split_with_config']);
assert.deepEqual(manager.split('testing_split'), expectedSplitView1);
Expand Down
26 changes: 17 additions & 9 deletions src/__tests__/offline/node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@ function ManagerDotSplitTests(assert) {

const expectedView1 = {
name: 'testing_split', changeNumber: 0, killed: false, trafficType: 'localhost',
treatments: ['on'], configs: {}
treatments: ['on'], configs: {}, defaultTreatment: 'control'
};
const expectedView2 = {
name: 'testing_split2', changeNumber: 0, killed: false, trafficType: 'localhost',
treatments: ['off'], configs: {}
treatments: ['off'], configs: {}, defaultTreatment: 'control'
};
const expectedView3 = {
name: 'testing_split3', changeNumber: 0, killed: false, trafficType: 'localhost',
treatments: ['custom_treatment'], configs: {}
treatments: ['custom_treatment'], configs: {}, defaultTreatment: 'control'
};

assert.deepEqual(manager.split('testing_split'), expectedView1);
Expand Down Expand Up @@ -289,15 +289,17 @@ function ManagerDotYamlTests(mockFileName, assert) {
killed: false,
trafficType: 'localhost',
treatments: ['on'],
configs: {}
configs: {},
defaultTreatment: 'control'
};
const expectedView2 = {
name: 'testing_split_only_wl',
changeNumber: 0,
killed: false,
trafficType: 'localhost',
treatments: ['whitelisted'],
configs: {}
configs: {},
defaultTreatment: 'control'
};
const expectedView3 = {
name: 'testing_split_with_wl',
Expand All @@ -308,13 +310,19 @@ function ManagerDotYamlTests(mockFileName, assert) {
configs: {
not_in_whitelist: '{"color": "green"}',
multi_key_wl: '{"color": "brown"}'
}
},
defaultTreatment: 'control'
};
const expectedView4 = {
name: 'testing_split_off_with_config', changeNumber: 0, killed: false, trafficType: 'localhost',
treatments: ['off'], configs: {
name: 'testing_split_off_with_config',
changeNumber: 0,
killed: false,
trafficType: 'localhost',
treatments: ['off'],
configs: {
off: '{"color": "green"}'
}
},
defaultTreatment: 'control'
};

assert.deepEqual(manager.split('testing_split_on'), expectedView1);
Expand Down
3 changes: 2 additions & 1 deletion ts-tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ splitView = {
changeNumber: 18294,
configs: {
off: '{"dimensions":"{\"height\":20,\"width\":40}"}'
}
},
defaultTreatment: 'off'
};
splitViews = [splitView];

Expand Down
2 changes: 1 addition & 1 deletion ts-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": "Apache-2.0",
"repository": "splitio/javascript-client",
"dependencies": {
"@types/node": "^14.18.52",
"@types/node": "^14.18.63",
"typescript": "^3.7.4"
}
}
7 changes: 6 additions & 1 deletion types/splitio.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,12 @@ declare namespace SplitIO {
*/
configs: {
[treatmentName: string]: string
}
},
/**
* The default treatment of the feature flag.
* @property {string} defaultTreatment
*/
defaultTreatment: string,
};
/**
* A promise that resolves to a feature flag view.
Expand Down
Loading