Skip to content

Commit d40d081

Browse files
add ts-tests, update commons to 2.7.9-rc.3
1 parent c1bdce1 commit d40d081

File tree

4 files changed

+100
-60
lines changed

4 files changed

+100
-60
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"node": ">=14.0.0"
3939
},
4040
"dependencies": {
41-
"@splitsoftware/splitio-commons": "2.7.9-rc.2",
41+
"@splitsoftware/splitio-commons": "2.7.9-rc.3",
4242
"bloom-filters": "^3.0.4",
4343
"ioredis": "^4.28.0",
4444
"js-yaml": "^3.13.1",

src/__tests__/nodeSuites/evaluations-fallback.spec.js

Lines changed: 70 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default async function (fetchMock, assert) {
2323
const splitio = SplitFactory(baseConfig);
2424
const client = splitio.client();
2525

26-
await client.ready();
26+
await client.whenReady();
2727

2828
t.equal(client.getTreatment('emi@harness.io', 'non_existent_flag'), 'control', 'The evaluation will return `control` if the flag does not exist and no fallbackTreatment is defined');
2929
t.equal(client.getTreatment('emma@harness.io', 'non_existent_flag_2'), 'control', 'The evaluation will return `control` if the flag does not exist and no fallbackTreatment is defined');
@@ -35,14 +35,16 @@ export default async function (fetchMock, assert) {
3535

3636
assert.test('FallbackTreatment / Split factory with global fallbackTreatment defined', async t => {
3737

38-
const config = Object.assign({}, baseConfig);
39-
config.fallbackTreatments = {
40-
global: 'FALLBACK_TREATMENT'
38+
const config = {
39+
...baseConfig,
40+
fallbackTreatments: {
41+
global: 'FALLBACK_TREATMENT'
42+
}
4143
};
4244
const splitio = SplitFactory(config);
4345
const client = splitio.client();
4446

45-
await client.ready();
47+
await client.whenReady();
4648

4749

4850
t.equal(client.getTreatment('emi@harness.io', 'non_existent_flag'), 'FALLBACK_TREATMENT', 'The evaluation will return `FALLBACK_TREATMENT` if the flag does not exist and no fallbackTreatment is defined');
@@ -55,16 +57,18 @@ export default async function (fetchMock, assert) {
5557

5658
assert.test('FallbackTreatment / Split factory with specific fallbackTreatment defined', async t => {
5759

58-
const config = Object.assign({}, baseConfig);
59-
config.fallbackTreatments = {
60-
byFlag: {
61-
'non_existent_flag': 'FALLBACK_TREATMENT',
60+
const config = {
61+
...baseConfig,
62+
fallbackTreatments: {
63+
byFlag: {
64+
'non_existent_flag': 'FALLBACK_TREATMENT',
65+
}
6266
}
6367
};
6468
const splitio = SplitFactory(config);
6569
const client = splitio.client();
6670

67-
await client.ready();
71+
await client.whenReady();
6872

6973
t.equal(client.getTreatment('emi@harness.io', 'non_existent_flag'), 'FALLBACK_TREATMENT', 'The evaluation will return `FALLBACK_TREATMENT` if the flag does not exist and no fallbackTreatment is defined');
7074
t.equal(client.getTreatment('emi@harness.io', 'non_existent_flag_2'), 'control', 'The evaluation will return `control` if the flag does not exist and no fallbackTreatment is defined');
@@ -80,17 +84,19 @@ export default async function (fetchMock, assert) {
8084

8185
assert.test('FallbackTreatment / flag override beats global fallbackTreatment', async t => {
8286

83-
const config = Object.assign({}, baseConfig);
84-
config.fallbackTreatments = {
85-
global: 'OFF_FALLBACK',
86-
byFlag: {
87-
'my_flag': 'ON_FALLBACK',
87+
const config = {
88+
...baseConfig,
89+
fallbackTreatments: {
90+
global: 'OFF_FALLBACK',
91+
byFlag: {
92+
'my_flag': 'ON_FALLBACK',
93+
}
8894
}
8995
};
9096
const splitio = SplitFactory(config);
9197
const client = splitio.client();
9298

93-
await client.ready();
99+
await client.whenReady();
94100

95101
t.equal(client.getTreatment('emi@harness.io', 'my_flag'), 'ON_FALLBACK', 'The evaluation will return `ON_FALLBACK` if the flag does not exist and no fallbackTreatment is defined');
96102
t.equal(client.getTreatment('emi@harness.io', 'non_existent_flag_2'), 'OFF_FALLBACK', 'The evaluation will return `OFF_FALLBACK` if the flag does not exist and no fallbackTreatment is defined');
@@ -105,14 +111,16 @@ export default async function (fetchMock, assert) {
105111

106112
assert.test('FallbackTreatment / override applies only when original is control', async t => {
107113

108-
const config = Object.assign({}, baseConfig);
109-
config.fallbackTreatments = {
110-
global: 'OFF_FALLBACK'
114+
const config = {
115+
...baseConfig,
116+
fallbackTreatments: {
117+
global: 'OFF_FALLBACK'
118+
}
111119
};
112120
const splitio = SplitFactory(config);
113121
const client = splitio.client();
114122

115-
await client.ready();
123+
await client.whenReady();
116124

117125
t.equal(client.getTreatment('emma@harness.io', 'user_account_in_whitelist'), 'off', 'The evaluation will return the treatment defined in the flag if it exists');
118126
t.equal(client.getTreatment('emma@harness.io', 'non_existent_flag'), 'OFF_FALLBACK', 'The evaluation will return `OFF_FALLBACK` if the flag does not exist and no fallbackTreatment is defined');
@@ -124,13 +132,15 @@ export default async function (fetchMock, assert) {
124132

125133
assert.test('FallbackTreatment / Impressions correctness with fallback when client is not ready', async t => {
126134

127-
const config = Object.assign({}, baseConfig);
128-
config.urls = {
129-
events: 'https://events.fallbacktreatment/api'
130-
};
131-
config.fallbackTreatments = {
132-
byFlag: {
133-
'any_flag': 'OFF_FALLBACK'
135+
const config = {
136+
...baseConfig,
137+
urls: {
138+
events: 'https://events.fallbacktreatment/api'
139+
},
140+
fallbackTreatments: {
141+
byFlag: {
142+
'any_flag': 'OFF_FALLBACK'
143+
}
134144
}
135145
};
136146
const splitio = SplitFactory(config);
@@ -139,7 +149,7 @@ export default async function (fetchMock, assert) {
139149
t.equal(client.getTreatment('emi@harness.io', 'any_flag'), 'OFF_FALLBACK', 'The evaluation will return the fallbackTreatment if the client is not ready yet');
140150
t.equal(client.getTreatment('emma@harness.io', 'user_account_in_whitelist'), 'control', 'The evaluation will return the fallbackTreatment if the client is not ready yet');
141151

142-
await client.ready();
152+
await client.whenReady();
143153

144154
fetchMock.postOnce(config.urls.events + '/testImpressions/bulk', (_, opts) => {
145155

@@ -164,17 +174,19 @@ export default async function (fetchMock, assert) {
164174

165175
assert.test('FallbackTreatment / Fallback dynamic config propagation', async t => {
166176

167-
const config = Object.assign({}, baseConfig);
168-
config.fallbackTreatments = {
169-
global: { treatment: 'OFF_FALLBACK', config: '{"global": true}' },
170-
byFlag: {
171-
'my_flag': { treatment: 'ON_FALLBACK', config: '{"flag": true}' }
177+
const config = {
178+
...baseConfig,
179+
fallbackTreatments: {
180+
global: { treatment: 'OFF_FALLBACK', config: '{"global": true}' },
181+
byFlag: {
182+
'my_flag': { treatment: 'ON_FALLBACK', config: '{"flag": true}' }
183+
}
172184
}
173185
};
174186
const splitio = SplitFactory(config);
175187
const client = splitio.client();
176188

177-
await client.ready();
189+
await client.whenReady();
178190

179191
t.deepEqual(client.getTreatmentWithConfig('emma@harness.io', 'my_flag'), { treatment: 'ON_FALLBACK', config: '{"flag": true}' }, 'The evaluation will propagate the config along with the treatment from the fallbackTreatment');
180192
t.deepEqual(client.getTreatmentWithConfig('emma@harness.io', 'non_existent_flag'), { treatment: 'OFF_FALLBACK', config: '{"global": true}' }, 'The evaluation will propagate the config along with the treatment from the fallbackTreatment');
@@ -186,22 +198,24 @@ export default async function (fetchMock, assert) {
186198

187199
assert.test('FallbackTreatment / Evaluations non existing flags with fallback do not generate impressions', async t => {
188200

189-
const config = Object.assign({}, baseConfig);
190-
config.urls = {
191-
events: 'https://events.fallbacktreatment/api'
192-
};
193-
config.fallbackTreatments = {
194-
global: { treatment: 'OFF_FALLBACK', config: '{"global": true}' },
195-
byFlag: {
196-
'my_flag': { treatment: 'ON_FALLBACK', config: '{"flag": true}' }
197-
}
201+
const config = {
202+
...baseConfig,
203+
urls: {
204+
events: 'https://events.fallbacktreatment/api'
205+
},
206+
fallbackTreatments: {
207+
global: { treatment: 'OFF_FALLBACK', config: '{"global": true}' },
208+
byFlag: {
209+
'my_flag': { treatment: 'ON_FALLBACK', config: '{"flag": true}' }
210+
}
211+
},
212+
impressionListener: listener
198213
};
199-
config.impressionListener = listener;
200214

201215
const splitio = SplitFactory(config);
202216
const client = splitio.client();
203217

204-
await client.ready();
218+
await client.whenReady();
205219

206220
t.deepEqual(client.getTreatmentWithConfig('emma@harness.io', 'my_flag'), { treatment: 'ON_FALLBACK', config: '{"flag": true}' }, 'The evaluation will propagate the config along with the treatment from the fallbackTreatment');
207221
t.deepEqual(client.getTreatmentWithConfig('emma@harness.io', 'non_existent_flag'), { treatment: 'OFF_FALLBACK', config: '{"global": true}' }, 'The evaluation will propagate the config along with the treatment from the fallbackTreatment');
@@ -234,16 +248,21 @@ export default async function (fetchMock, assert) {
234248

235249
assert.test('FallbackTreatment / LocalhostMode', async t => {
236250

237-
const config = Object.assign({}, baseConfig);
238-
config.core.authorizationKey = 'localhost';
239-
config.fallbackTreatments = {
240-
global: 'OFF_FALLBACK'
251+
const config = {
252+
...baseConfig,
253+
core: {
254+
...baseConfig.core,
255+
authorizationKey: 'localhost'
256+
},
257+
fallbackTreatments: {
258+
global: 'OFF_FALLBACK'
259+
},
260+
features: path.join(__dirname, '../offline/split.yaml')
241261
};
242-
config.features = path.join(__dirname, '../offline/split.yaml');
243262
const splitio = SplitFactory(config);
244263
const client = splitio.client();
245264

246-
await client.ready();
265+
await client.whenReady();
247266

248267
t.deepEqual(client.getTreatment('emma@harness.io', 'testing_split_on'), 'on', 'The evaluation should return the treatment defined in localhost mode');
249268
t.deepEqual(client.getTreatment('emma@harness.io', 'non_existent_flag'), 'OFF_FALLBACK', 'The evaluation will return `OFF_FALLBACK` if the flag does not exist');

ts-tests/index.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,14 @@ let fullBrowserSettings: SplitIO.IBrowserSettings = {
598598
getHeaderOverrides(context) { return { ...context.headers, 'header': 'value' } },
599599
}
600600
},
601-
userConsent: 'GRANTED'
601+
userConsent: 'GRANTED',
602+
fallbackTreatments: {
603+
global: { treatment: 'global-treatment', config: '{"global": true}' },
604+
byFlag: {
605+
'my_flag': { treatment: 'flag-treatment', config: '{"flag": true}' },
606+
'my_other_flag': 'other-flag-treatment'
607+
}
608+
}
602609
};
603610
fullBrowserSettings.storage.type = 'MEMORY';
604611
fullBrowserSettings.userConsent = 'DECLINED';
@@ -658,6 +665,13 @@ let fullNodeSettings: SplitIO.INodeSettings = {
658665
getHeaderOverrides(context) { return { ...context.headers, 'header': 'value' } },
659666
agent: new (require('https')).Agent(),
660667
}
668+
},
669+
fallbackTreatments: {
670+
global: { treatment: 'global-treatment', config: '{"global": true}' },
671+
byFlag: {
672+
'my_flag': { treatment: 'flag-treatment', config: '{"flag": true}' },
673+
'my_other_flag': 'other-flag-treatment'
674+
}
661675
}
662676
};
663677
fullNodeSettings.storage.type = 'MEMORY';
@@ -706,6 +720,13 @@ let fullAsyncSettings: SplitIO.INodeAsyncSettings = {
706720
sync: {
707721
splitFilters: splitFilters,
708722
impressionsMode: 'DEBUG',
723+
},
724+
fallbackTreatments: {
725+
global: 'global-treatment',
726+
byFlag: {
727+
'my_flag': { treatment: 'flag-treatment', config: '{"flag": true}' },
728+
'my_other_flag': 'other-flag-treatment'
729+
}
709730
}
710731
};
711732

0 commit comments

Comments
 (0)