@featurevisor/core 3.1.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/lib/datasource/datasource.d.ts +1 -1
  2. package/lib/datasource/datasource.js +4 -14
  3. package/lib/datasource/datasource.js.map +1 -1
  4. package/lib/datasource/requiredFeatures.d.ts +7 -0
  5. package/lib/datasource/requiredFeatures.js +38 -0
  6. package/lib/datasource/requiredFeatures.js.map +1 -0
  7. package/lib/linter/checkCircularDependency.d.ts +1 -1
  8. package/lib/linter/checkCircularDependency.js +3 -22
  9. package/lib/linter/checkCircularDependency.js.map +1 -1
  10. package/lib/linter/conditionSchema.js +27 -3
  11. package/lib/linter/conditionSchema.js.map +1 -1
  12. package/lib/linter/testSchema.d.ts +4 -0
  13. package/lib/linter/testSchema.js +46 -4
  14. package/lib/linter/testSchema.js.map +1 -1
  15. package/lib/promoter/index.js +62 -1
  16. package/lib/promoter/index.js.map +1 -1
  17. package/lib/tester/testFeature.js +17 -16
  18. package/lib/tester/testFeature.js.map +1 -1
  19. package/package.json +10 -7
  20. package/CHANGELOG.md +0 -2246
  21. package/coverage/clover.xml +0 -5456
  22. package/coverage/coverage-final.json +0 -64
  23. package/coverage/lcov-report/base.css +0 -224
  24. package/coverage/lcov-report/block-navigation.js +0 -87
  25. package/coverage/lcov-report/favicon.png +0 -0
  26. package/coverage/lcov-report/index.html +0 -371
  27. package/coverage/lcov-report/prettify.css +0 -1
  28. package/coverage/lcov-report/prettify.js +0 -2
  29. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  30. package/coverage/lcov-report/sorter.js +0 -210
  31. package/coverage/lcov-report/src/assess-distribution/index.html +0 -116
  32. package/coverage/lcov-report/src/assess-distribution/index.ts.html +0 -754
  33. package/coverage/lcov-report/src/benchmark/index.html +0 -116
  34. package/coverage/lcov-report/src/benchmark/index.ts.html +0 -793
  35. package/coverage/lcov-report/src/builder/allocator.ts.html +0 -220
  36. package/coverage/lcov-report/src/builder/applyContextToConditions.ts.html +0 -502
  37. package/coverage/lcov-report/src/builder/applyContextToDatafile.ts.html +0 -772
  38. package/coverage/lcov-report/src/builder/applyContextToSegments.ts.html +0 -580
  39. package/coverage/lcov-report/src/builder/buildDatafile.ts.html +0 -2053
  40. package/coverage/lcov-report/src/builder/buildProject.ts.html +0 -1117
  41. package/coverage/lcov-report/src/builder/buildRuntimeDatafiles.ts.html +0 -256
  42. package/coverage/lcov-report/src/builder/getFeatureRanges.ts.html +0 -268
  43. package/coverage/lcov-report/src/builder/hashes.ts.html +0 -412
  44. package/coverage/lcov-report/src/builder/index.html +0 -311
  45. package/coverage/lcov-report/src/builder/index.ts.html +0 -91
  46. package/coverage/lcov-report/src/builder/mutateVariables.ts.html +0 -421
  47. package/coverage/lcov-report/src/builder/mutator.ts.html +0 -796
  48. package/coverage/lcov-report/src/builder/revision.ts.html +0 -151
  49. package/coverage/lcov-report/src/builder/traffic.ts.html +0 -661
  50. package/coverage/lcov-report/src/cli/cli.ts.html +0 -400
  51. package/coverage/lcov-report/src/cli/index.html +0 -131
  52. package/coverage/lcov-report/src/cli/plugins.ts.html +0 -214
  53. package/coverage/lcov-report/src/config/index.html +0 -131
  54. package/coverage/lcov-report/src/config/index.ts.html +0 -88
  55. package/coverage/lcov-report/src/config/projectConfig.ts.html +0 -925
  56. package/coverage/lcov-report/src/datasource/adapter.ts.html +0 -253
  57. package/coverage/lcov-report/src/datasource/datasource.ts.html +0 -1000
  58. package/coverage/lcov-report/src/datasource/filesystemAdapter.ts.html +0 -1576
  59. package/coverage/lcov-report/src/datasource/index.html +0 -161
  60. package/coverage/lcov-report/src/datasource/index.ts.html +0 -94
  61. package/coverage/lcov-report/src/evaluate/index.html +0 -116
  62. package/coverage/lcov-report/src/evaluate/index.ts.html +0 -814
  63. package/coverage/lcov-report/src/find-duplicate-segments/findDuplicateSegments.ts.html +0 -313
  64. package/coverage/lcov-report/src/find-duplicate-segments/index.html +0 -131
  65. package/coverage/lcov-report/src/find-duplicate-segments/index.ts.html +0 -307
  66. package/coverage/lcov-report/src/find-usage/index.html +0 -116
  67. package/coverage/lcov-report/src/find-usage/index.ts.html +0 -1780
  68. package/coverage/lcov-report/src/generate-code/index.html +0 -131
  69. package/coverage/lcov-report/src/generate-code/index.ts.html +0 -403
  70. package/coverage/lcov-report/src/generate-code/typescript.ts.html +0 -1909
  71. package/coverage/lcov-report/src/index.html +0 -131
  72. package/coverage/lcov-report/src/info/index.html +0 -116
  73. package/coverage/lcov-report/src/info/index.ts.html +0 -472
  74. package/coverage/lcov-report/src/init/index.html +0 -116
  75. package/coverage/lcov-report/src/init/index.ts.html +0 -280
  76. package/coverage/lcov-report/src/linter/attributeSchema.ts.html +0 -1963
  77. package/coverage/lcov-report/src/linter/checkCircularDependency.ts.html +0 -220
  78. package/coverage/lcov-report/src/linter/checkPercentageExceedingSlot.ts.html +0 -268
  79. package/coverage/lcov-report/src/linter/conditionSchema.ts.html +0 -2224
  80. package/coverage/lcov-report/src/linter/featureSchema.ts.html +0 -5851
  81. package/coverage/lcov-report/src/linter/groupSchema.ts.html +0 -226
  82. package/coverage/lcov-report/src/linter/index.html +0 -326
  83. package/coverage/lcov-report/src/linter/index.ts.html +0 -88
  84. package/coverage/lcov-report/src/linter/lintProject.ts.html +0 -2704
  85. package/coverage/lcov-report/src/linter/mutationNotation.ts.html +0 -1411
  86. package/coverage/lcov-report/src/linter/printError.ts.html +0 -289
  87. package/coverage/lcov-report/src/linter/schema.ts.html +0 -1558
  88. package/coverage/lcov-report/src/linter/segmentSchema.ts.html +0 -139
  89. package/coverage/lcov-report/src/linter/targetSchema.ts.html +0 -223
  90. package/coverage/lcov-report/src/linter/testSchema.ts.html +0 -529
  91. package/coverage/lcov-report/src/linter/zodHelpers.ts.html +0 -133
  92. package/coverage/lcov-report/src/list/index.html +0 -131
  93. package/coverage/lcov-report/src/list/index.ts.html +0 -2065
  94. package/coverage/lcov-report/src/list/matrix.ts.html +0 -721
  95. package/coverage/lcov-report/src/promoter/index.html +0 -116
  96. package/coverage/lcov-report/src/promoter/index.ts.html +0 -3883
  97. package/coverage/lcov-report/src/sets.ts.html +0 -313
  98. package/coverage/lcov-report/src/targeting.ts.html +0 -403
  99. package/coverage/lcov-report/src/tester/cliFormat.ts.html +0 -133
  100. package/coverage/lcov-report/src/tester/helpers.ts.html +0 -313
  101. package/coverage/lcov-report/src/tester/index.html +0 -206
  102. package/coverage/lcov-report/src/tester/prettyDuration.ts.html +0 -187
  103. package/coverage/lcov-report/src/tester/printTestResult.ts.html +0 -337
  104. package/coverage/lcov-report/src/tester/testFeature.ts.html +0 -1186
  105. package/coverage/lcov-report/src/tester/testProject.ts.html +0 -1018
  106. package/coverage/lcov-report/src/tester/testSegment.ts.html +0 -316
  107. package/coverage/lcov-report/src/utils/extractKeys.ts.html +0 -493
  108. package/coverage/lcov-report/src/utils/git.ts.html +0 -559
  109. package/coverage/lcov-report/src/utils/index.html +0 -161
  110. package/coverage/lcov-report/src/utils/index.ts.html +0 -94
  111. package/coverage/lcov-report/src/utils/pretty.ts.html +0 -121
  112. package/coverage/lcov.info +0 -11615
  113. package/jest.config.js +0 -22
  114. package/json-schema/README.md +0 -5
  115. package/json-schema/attribute.json +0 -40
  116. package/json-schema/feature.json +0 -394
  117. package/json-schema/segment.json +0 -137
  118. package/src/assess-distribution/index.ts +0 -223
  119. package/src/benchmark/index.ts +0 -236
  120. package/src/builder/allocator.spec.ts +0 -105
  121. package/src/builder/allocator.ts +0 -45
  122. package/src/builder/applyContextToConditions.spec.ts +0 -2677
  123. package/src/builder/applyContextToConditions.ts +0 -139
  124. package/src/builder/applyContextToDatafile.spec.ts +0 -2626
  125. package/src/builder/applyContextToDatafile.ts +0 -229
  126. package/src/builder/applyContextToSegments.spec.ts +0 -1593
  127. package/src/builder/applyContextToSegments.ts +0 -165
  128. package/src/builder/buildDatafile.spec.ts +0 -445
  129. package/src/builder/buildDatafile.ts +0 -656
  130. package/src/builder/buildProject.ts +0 -344
  131. package/src/builder/buildRuntimeDatafiles.ts +0 -57
  132. package/src/builder/getFeatureRanges.ts +0 -61
  133. package/src/builder/hashes.ts +0 -109
  134. package/src/builder/index.ts +0 -2
  135. package/src/builder/mutateVariables.spec.ts +0 -1179
  136. package/src/builder/mutateVariables.ts +0 -112
  137. package/src/builder/mutator.spec.ts +0 -413
  138. package/src/builder/mutator.ts +0 -237
  139. package/src/builder/revision.spec.ts +0 -22
  140. package/src/builder/revision.ts +0 -22
  141. package/src/builder/traffic.spec.ts +0 -946
  142. package/src/builder/traffic.ts +0 -192
  143. package/src/cli/cli.ts +0 -105
  144. package/src/cli/index.ts +0 -2
  145. package/src/cli/plugins.ts +0 -43
  146. package/src/config/index.ts +0 -1
  147. package/src/config/projectConfig.spec.ts +0 -194
  148. package/src/config/projectConfig.ts +0 -280
  149. package/src/datasource/adapter.ts +0 -56
  150. package/src/datasource/datasource.ts +0 -305
  151. package/src/datasource/filesystemAdapter.spec.ts +0 -212
  152. package/src/datasource/filesystemAdapter.ts +0 -497
  153. package/src/datasource/index.ts +0 -3
  154. package/src/dependencies.ts +0 -13
  155. package/src/evaluate/index.ts +0 -243
  156. package/src/find-duplicate-segments/findDuplicateSegments.ts +0 -76
  157. package/src/find-duplicate-segments/index.ts +0 -74
  158. package/src/find-usage/index.ts +0 -565
  159. package/src/generate-code/index.ts +0 -106
  160. package/src/generate-code/typescript.spec.ts +0 -214
  161. package/src/generate-code/typescript.ts +0 -608
  162. package/src/index.ts +0 -20
  163. package/src/info/index.ts +0 -129
  164. package/src/init/index.ts +0 -65
  165. package/src/linter/attributeSchema.spec.ts +0 -342
  166. package/src/linter/attributeSchema.ts +0 -626
  167. package/src/linter/checkCircularDependency.ts +0 -45
  168. package/src/linter/checkPercentageExceedingSlot.ts +0 -61
  169. package/src/linter/conditionSchema.spec.ts +0 -510
  170. package/src/linter/conditionSchema.ts +0 -713
  171. package/src/linter/featureSchema.spec.ts +0 -1985
  172. package/src/linter/featureSchema.ts +0 -1922
  173. package/src/linter/groupSchema.ts +0 -47
  174. package/src/linter/index.ts +0 -1
  175. package/src/linter/lintProject.spec.ts +0 -336
  176. package/src/linter/lintProject.ts +0 -873
  177. package/src/linter/mutationNotation.spec.ts +0 -704
  178. package/src/linter/mutationNotation.ts +0 -442
  179. package/src/linter/printError.ts +0 -68
  180. package/src/linter/schema.spec.ts +0 -690
  181. package/src/linter/schema.ts +0 -491
  182. package/src/linter/segmentSchema.spec.ts +0 -358
  183. package/src/linter/segmentSchema.ts +0 -18
  184. package/src/linter/targetSchema.spec.ts +0 -159
  185. package/src/linter/targetSchema.ts +0 -46
  186. package/src/linter/testSchema.spec.ts +0 -258
  187. package/src/linter/testSchema.ts +0 -148
  188. package/src/linter/zodHelpers.ts +0 -16
  189. package/src/list/index.spec.ts +0 -135
  190. package/src/list/index.ts +0 -660
  191. package/src/list/matrix.spec.ts +0 -49
  192. package/src/list/matrix.ts +0 -212
  193. package/src/promoter/index.spec.ts +0 -617
  194. package/src/promoter/index.ts +0 -1266
  195. package/src/sets.ts +0 -76
  196. package/src/targeting.spec.ts +0 -74
  197. package/src/targeting.ts +0 -106
  198. package/src/tester/cliFormat.ts +0 -16
  199. package/src/tester/helpers.spec.ts +0 -149
  200. package/src/tester/helpers.ts +0 -76
  201. package/src/tester/index.ts +0 -2
  202. package/src/tester/prettyDuration.ts +0 -34
  203. package/src/tester/printTestResult.ts +0 -84
  204. package/src/tester/testFeature.ts +0 -367
  205. package/src/tester/testProject.spec.ts +0 -50
  206. package/src/tester/testProject.ts +0 -311
  207. package/src/tester/testSegment.ts +0 -77
  208. package/src/utils/extractKeys.ts +0 -136
  209. package/src/utils/git.ts +0 -158
  210. package/src/utils/index.ts +0 -3
  211. package/src/utils/pretty.ts +0 -12
  212. package/tsconfig.cjs.json +0 -13
  213. package/tsconfig.typecheck.json +0 -9
@@ -1,946 +0,0 @@
1
- import { getTraffic } from "./traffic";
2
-
3
- describe("core: Traffic", function () {
4
- it("should be a function", function () {
5
- expect(typeof getTraffic).toEqual("function");
6
- });
7
-
8
- it("should allocate traffic for 100-0 weight on two variations", function () {
9
- const result = getTraffic(
10
- // parsed variations from YAML
11
- [
12
- {
13
- value: "on",
14
- weight: 100,
15
- },
16
- {
17
- value: "off",
18
- weight: 0,
19
- },
20
- ],
21
-
22
- // parsed rollouts from YAML
23
- [
24
- {
25
- key: "1",
26
- segments: "*",
27
- percentage: 80,
28
- },
29
- ],
30
-
31
- // existing feature from previous release
32
- undefined,
33
- );
34
-
35
- expect(result).toEqual([
36
- {
37
- key: "1",
38
- segments: "*",
39
- percentage: 80000,
40
- allocation: [
41
- {
42
- variation: "on",
43
- range: [0, 80000],
44
- },
45
- ],
46
- },
47
- ]);
48
- });
49
-
50
- it("should allocate traffic for 0-100 weight on two variations", function () {
51
- const result = getTraffic(
52
- // parsed variations from YAML
53
- [
54
- {
55
- value: "control",
56
- weight: 0,
57
- },
58
- {
59
- value: "treatment",
60
- weight: 100,
61
- },
62
- ],
63
-
64
- // parsed rollouts from YAML
65
- [
66
- {
67
- key: "1",
68
- segments: "*",
69
- percentage: 80,
70
- },
71
- ],
72
-
73
- // existing feature from previous release
74
- undefined,
75
- );
76
-
77
- expect(result).toEqual([
78
- {
79
- key: "1",
80
- segments: "*",
81
- percentage: 80000,
82
- allocation: [
83
- // should be filtered out automatically
84
- // {
85
- // variation: "control",
86
- // range: [0, 0],
87
- // },
88
-
89
- {
90
- variation: "treatment",
91
- range: [0, 80000],
92
- },
93
- ],
94
- },
95
- ]);
96
- });
97
-
98
- it("should allocate traffic for 0-100 weight on two variations, with rule percentage going from 80% to 100%", function () {
99
- const result = getTraffic(
100
- // parsed variations from YAML
101
- [
102
- {
103
- value: "control",
104
- weight: 0,
105
- },
106
- {
107
- value: "treatment",
108
- weight: 100,
109
- },
110
- ],
111
-
112
- // parsed rollouts from YAML
113
- [
114
- {
115
- key: "1",
116
- segments: "*",
117
- percentage: 100,
118
- },
119
- ],
120
-
121
- // existing feature from previous release
122
- {
123
- variations: [
124
- {
125
- value: "control",
126
- weight: 0,
127
- },
128
- {
129
- value: "treatment",
130
- weight: 80,
131
- },
132
- ],
133
- traffic: [
134
- {
135
- key: "1",
136
- percentage: 80000,
137
- allocation: [
138
- {
139
- variation: "treatment",
140
- range: [0, 80000],
141
- },
142
- ],
143
- },
144
- ],
145
- },
146
- );
147
-
148
- expect(result).toEqual([
149
- {
150
- key: "1",
151
- segments: "*",
152
- percentage: 100000,
153
- allocation: [
154
- // should be filtered out automatically
155
- // {
156
- // variation: "control",
157
- // range: [0, 0],
158
- // },
159
-
160
- {
161
- variation: "treatment",
162
- range: [0, 100000],
163
- },
164
- ],
165
- },
166
- ]);
167
- });
168
-
169
- it("should allocate traffic for 0-100 weight on two variations, with rule percentage going from 100% to 80%", function () {
170
- const result = getTraffic(
171
- // parsed variations from YAML
172
- [
173
- {
174
- value: "control",
175
- weight: 0,
176
- },
177
- {
178
- value: "treatment",
179
- weight: 100,
180
- },
181
- ],
182
-
183
- // parsed rollouts from YAML
184
- [
185
- {
186
- key: "1",
187
- segments: "*",
188
- percentage: 80,
189
- },
190
- ],
191
-
192
- // existing feature from previous release
193
- {
194
- variations: [
195
- {
196
- value: "control",
197
- weight: 0,
198
- },
199
- {
200
- value: "treatment",
201
- weight: 80,
202
- },
203
- ],
204
- traffic: [
205
- {
206
- key: "1",
207
- percentage: 100000,
208
- allocation: [
209
- {
210
- variation: "treatment",
211
- range: [0, 100000],
212
- },
213
- ],
214
- },
215
- ],
216
- },
217
- );
218
-
219
- expect(result).toEqual([
220
- {
221
- key: "1",
222
- segments: "*",
223
- percentage: 80000,
224
- allocation: [
225
- // should be filtered out automatically
226
- // {
227
- // variation: "control",
228
- // range: [0, 0],
229
- // },
230
-
231
- {
232
- variation: "treatment",
233
- range: [0, 80000],
234
- },
235
- ],
236
- },
237
- ]);
238
- });
239
-
240
- it("should allocate traffic for existing variations state of 0-100 weights", function () {
241
- const result = getTraffic(
242
- // parsed variations from YAML
243
- [
244
- {
245
- value: "control",
246
- weight: 50,
247
- },
248
- {
249
- value: "treatment",
250
- weight: 50,
251
- },
252
- ],
253
-
254
- // parsed rollouts from YAML
255
- [
256
- {
257
- key: "1",
258
- segments: "*",
259
- percentage: 80,
260
- },
261
- ],
262
-
263
- // existing feature from previous release
264
- {
265
- variations: [
266
- {
267
- value: "control",
268
- weight: 0,
269
- },
270
- {
271
- value: "treatment",
272
- weight: 80,
273
- },
274
- ],
275
- traffic: [
276
- {
277
- key: "1",
278
- percentage: 80000,
279
- allocation: [
280
- {
281
- variation: "treatment",
282
- range: [0, 80000],
283
- },
284
- ],
285
- },
286
- ],
287
- },
288
- );
289
-
290
- expect(result).toEqual([
291
- {
292
- key: "1",
293
- segments: "*",
294
- percentage: 80000,
295
- allocation: [
296
- {
297
- variation: "control",
298
- range: [0, 40000],
299
- },
300
- {
301
- variation: "treatment",
302
- range: [40000, 80000],
303
- },
304
- ],
305
- },
306
- ]);
307
- });
308
-
309
- it("should allocate traffic for 50-50 weight on two variations", function () {
310
- const result = getTraffic(
311
- // parsed variations from YAML
312
- [
313
- {
314
- value: "on",
315
- weight: 50,
316
- },
317
- {
318
- value: "off",
319
- weight: 50,
320
- },
321
- ],
322
-
323
- // parsed rollouts from YAML
324
- [
325
- {
326
- key: "1",
327
- segments: "*",
328
- percentage: 80,
329
- },
330
- ],
331
-
332
- // existing feature from previous release
333
- undefined,
334
- );
335
-
336
- expect(result).toEqual([
337
- {
338
- key: "1",
339
- segments: "*",
340
- percentage: 80000,
341
- allocation: [
342
- {
343
- variation: "on",
344
- range: [0, 40000],
345
- },
346
- {
347
- variation: "off",
348
- range: [40000, 80000],
349
- },
350
- ],
351
- },
352
- ]);
353
- });
354
-
355
- it("should allocate traffic for weight with two decimal places among three variations", function () {
356
- const result = getTraffic(
357
- // parsed variations from YAML
358
- [
359
- {
360
- value: "yes",
361
- weight: 33.33,
362
- },
363
- {
364
- value: "no",
365
- weight: 33.33,
366
- },
367
- {
368
- value: "maybe",
369
- weight: 33.34,
370
- },
371
- ],
372
-
373
- // parsed rollouts from YAML
374
- [
375
- {
376
- key: "1",
377
- segments: "*",
378
- percentage: 100,
379
- },
380
- ],
381
-
382
- // existing feature from previous release
383
- undefined,
384
- );
385
-
386
- expect(result).toEqual([
387
- {
388
- key: "1",
389
- segments: "*",
390
- percentage: 100000,
391
- allocation: [
392
- {
393
- variation: "yes",
394
- range: [0, 33330],
395
- },
396
- {
397
- variation: "no",
398
- range: [33330, 66660],
399
- },
400
- {
401
- variation: "maybe",
402
- range: [66660, 100000],
403
- },
404
- ],
405
- },
406
- ]);
407
- });
408
-
409
- it("should allocate against previous known allocation, increasing from 80% to 90%, with same variations and weight", function () {
410
- const result = getTraffic(
411
- // parsed variations from YAML
412
- [
413
- {
414
- value: "on",
415
- weight: 50,
416
- },
417
- {
418
- value: "off",
419
- weight: 50,
420
- },
421
- ],
422
-
423
- // parsed rollouts from YAML
424
- [
425
- {
426
- key: "1",
427
- segments: "*",
428
- percentage: 90,
429
- },
430
- ],
431
-
432
- // existing feature from previous release
433
- {
434
- variations: [
435
- {
436
- value: "on",
437
- weight: 50,
438
- },
439
- {
440
- value: "off",
441
- weight: 50,
442
- },
443
- ],
444
- traffic: [
445
- {
446
- key: "1",
447
- percentage: 80000,
448
- allocation: [
449
- {
450
- variation: "on",
451
- range: [0, 40000],
452
- },
453
- {
454
- variation: "off",
455
- range: [40000, 80000],
456
- },
457
- ],
458
- },
459
- ],
460
- },
461
- );
462
-
463
- expect(result).toEqual([
464
- {
465
- key: "1",
466
- segments: "*",
467
- percentage: 90000,
468
- allocation: [
469
- // existing
470
- {
471
- variation: "on",
472
- range: [0, 40000],
473
- },
474
- {
475
- variation: "off",
476
- range: [40000, 80000],
477
- },
478
-
479
- // new
480
- {
481
- variation: "on",
482
- range: [80000, 85000],
483
- },
484
- {
485
- variation: "off",
486
- range: [85000, 90000],
487
- },
488
- ],
489
- },
490
- ]);
491
- });
492
-
493
- it("should allocate against previous known allocation, decreasing from 80% to 70%, with same variations and weight", function () {
494
- const result = getTraffic(
495
- // parsed variations from YAML
496
- [
497
- {
498
- value: "on",
499
- weight: 50,
500
- },
501
- {
502
- value: "off",
503
- weight: 50,
504
- },
505
- ],
506
-
507
- // parsed rollouts from YAML
508
- [
509
- {
510
- key: "1",
511
- segments: "*",
512
- percentage: 70,
513
- },
514
- ],
515
-
516
- // existing feature from previous release
517
- {
518
- variations: [
519
- {
520
- value: "on",
521
- weight: 50,
522
- },
523
- {
524
- value: "off",
525
- weight: 50,
526
- },
527
- ],
528
- traffic: [
529
- {
530
- key: "1",
531
- percentage: 80000,
532
- allocation: [
533
- {
534
- variation: "on",
535
- range: [0, 40000],
536
- },
537
- {
538
- variation: "off",
539
- range: [40000, 80000],
540
- },
541
- ],
542
- },
543
- ],
544
- },
545
- );
546
-
547
- expect(result).toEqual([
548
- {
549
- key: "1",
550
- segments: "*",
551
- percentage: 70000,
552
- allocation: [
553
- {
554
- variation: "on",
555
- range: [0, 35000],
556
- },
557
- {
558
- variation: "off",
559
- range: [35000, 70000],
560
- },
561
- ],
562
- },
563
- ]);
564
- });
565
-
566
- it("should allocate against previous known allocation, increasing from 80% to 90%, with new added variation", function () {
567
- const result = getTraffic(
568
- // parsed variations from YAML
569
- [
570
- {
571
- value: "a",
572
- weight: 33.33,
573
- },
574
- {
575
- value: "b",
576
- weight: 33.33,
577
- },
578
- {
579
- value: "c",
580
- weight: 33.34,
581
- },
582
- ],
583
-
584
- // parsed rollouts from YAML
585
- [
586
- {
587
- key: "1",
588
- segments: "*",
589
- percentage: 90,
590
- },
591
- ],
592
-
593
- // existing feature from previous release
594
- {
595
- variations: [
596
- {
597
- value: "a",
598
- weight: 50,
599
- },
600
- {
601
- value: "b",
602
- weight: 50,
603
- },
604
- ],
605
- traffic: [
606
- {
607
- key: "1",
608
- percentage: 80000,
609
- allocation: [
610
- {
611
- variation: "a",
612
- range: [0, 40000],
613
- },
614
- {
615
- variation: "b",
616
- range: [40000, 80000],
617
- },
618
- ],
619
- },
620
- ],
621
- },
622
- );
623
-
624
- expect(result).toEqual([
625
- {
626
- key: "1",
627
- segments: "*",
628
- percentage: 90000,
629
- allocation: [
630
- {
631
- variation: "a",
632
- range: [0, 29997],
633
- },
634
- {
635
- variation: "b",
636
- range: [29997, 59994],
637
- },
638
- {
639
- variation: "c",
640
- range: [59994, 90000],
641
- },
642
- ],
643
- },
644
- ]);
645
- });
646
-
647
- it("should allocate against previous known allocation, increasing from 80% to 100%, with new added variation, totalling 4 variations", function () {
648
- const result = getTraffic(
649
- // parsed variations from YAML
650
- [
651
- {
652
- value: "a",
653
- weight: 25,
654
- },
655
- {
656
- value: "b",
657
- weight: 25,
658
- },
659
- {
660
- value: "c",
661
- weight: 25,
662
- },
663
- {
664
- value: "d",
665
- weight: 25,
666
- },
667
- ],
668
-
669
- // parsed rollouts from YAML
670
- [
671
- {
672
- key: "1",
673
- segments: "*",
674
- percentage: 100,
675
- },
676
- ],
677
-
678
- // existing feature from previous release
679
- {
680
- variations: [
681
- {
682
- value: "a",
683
- weight: 50,
684
- },
685
- {
686
- value: "b",
687
- weight: 50,
688
- },
689
- ],
690
- traffic: [
691
- {
692
- key: "1",
693
- percentage: 80000,
694
- allocation: [
695
- {
696
- variation: "a",
697
- range: [0, 40000],
698
- },
699
- {
700
- variation: "b",
701
- range: [40000, 80000],
702
- },
703
- ],
704
- },
705
- ],
706
- },
707
- );
708
-
709
- expect(result).toEqual([
710
- {
711
- key: "1",
712
- segments: "*",
713
- percentage: 100000,
714
- allocation: [
715
- {
716
- variation: "a",
717
- range: [0, 25000],
718
- },
719
- {
720
- variation: "b",
721
- range: [25000, 50000],
722
- },
723
- {
724
- variation: "c",
725
- range: [50000, 75000],
726
- },
727
- {
728
- variation: "d",
729
- range: [75000, 100000],
730
- },
731
- ],
732
- },
733
- ]);
734
- });
735
-
736
- it("should allocate against previous known allocation, staying at same 100%, removing variations from 4 to 2", function () {
737
- const result = getTraffic(
738
- // parsed variations from YAML
739
- [
740
- {
741
- value: "a",
742
- weight: 50,
743
- },
744
- {
745
- value: "b",
746
- weight: 50,
747
- },
748
- ],
749
-
750
- // parsed rollouts from YAML
751
- [
752
- {
753
- key: "1",
754
- segments: "*",
755
- percentage: 100,
756
- },
757
- ],
758
-
759
- // existing feature from previous release
760
- {
761
- variations: [
762
- {
763
- value: "a",
764
- weight: 25,
765
- },
766
- {
767
- value: "b",
768
- weight: 25,
769
- },
770
- {
771
- value: "c",
772
- weight: 25,
773
- },
774
- {
775
- value: "d",
776
- weight: 25,
777
- },
778
- ],
779
- traffic: [
780
- {
781
- key: "1",
782
- percentage: 100000,
783
- allocation: [
784
- {
785
- variation: "a",
786
- range: [0, 25000],
787
- },
788
- {
789
- variation: "b",
790
- range: [25000, 50000],
791
- },
792
- {
793
- variation: "c",
794
- range: [50000, 75000],
795
- },
796
- {
797
- variation: "d",
798
- range: [75000, 100000],
799
- },
800
- ],
801
- },
802
- ],
803
- },
804
- );
805
-
806
- expect(result).toEqual([
807
- {
808
- key: "1",
809
- segments: "*",
810
- percentage: 100000,
811
- allocation: [
812
- {
813
- variation: "a",
814
- range: [0, 50000],
815
- },
816
- {
817
- variation: "b",
818
- range: [50000, 100000],
819
- },
820
- ],
821
- },
822
- ]);
823
- });
824
-
825
- it("should allocate against previous known allocation, decreasing from 100% to 80%, removing variations from 4 to 2", function () {
826
- const result = getTraffic(
827
- // parsed variations from YAML
828
- [
829
- {
830
- value: "a",
831
- weight: 50,
832
- },
833
- {
834
- value: "b",
835
- weight: 50,
836
- },
837
- ],
838
-
839
- // parsed rollouts from YAML
840
- [
841
- {
842
- key: "1",
843
- segments: "*",
844
- percentage: 80,
845
- },
846
- ],
847
-
848
- // existing feature from previous release
849
- {
850
- variations: [
851
- {
852
- value: "a",
853
- weight: 25,
854
- },
855
- {
856
- value: "b",
857
- weight: 25,
858
- },
859
- {
860
- value: "c",
861
- weight: 25,
862
- },
863
- {
864
- value: "d",
865
- weight: 25,
866
- },
867
- ],
868
- traffic: [
869
- {
870
- key: "1",
871
- percentage: 100000,
872
- allocation: [
873
- {
874
- variation: "a",
875
- range: [0, 25000],
876
- },
877
- {
878
- variation: "b",
879
- range: [25000, 50000],
880
- },
881
- {
882
- variation: "c",
883
- range: [50000, 75000],
884
- },
885
- {
886
- variation: "d",
887
- range: [75000, 100000],
888
- },
889
- ],
890
- },
891
- ],
892
- },
893
- );
894
-
895
- expect(result).toEqual([
896
- {
897
- key: "1",
898
- segments: "*",
899
- percentage: 80000,
900
- allocation: [
901
- {
902
- variation: "a",
903
- range: [0, 40000],
904
- },
905
- {
906
- variation: "b",
907
- range: [40000, 80000],
908
- },
909
- ],
910
- },
911
- ]);
912
- });
913
-
914
- it("should include variableOverrides from parsed rule in traffic", function () {
915
- const variableOverrides = {
916
- config: [
917
- {
918
- segments: "mobile",
919
- value: {
920
- "layout.width": 900,
921
- },
922
- },
923
- ],
924
- };
925
-
926
- const result = getTraffic(
927
- [
928
- {
929
- value: "control",
930
- weight: 100,
931
- },
932
- ],
933
- [
934
- {
935
- key: "1",
936
- segments: "*",
937
- percentage: 100,
938
- variableOverrides,
939
- },
940
- ],
941
- undefined,
942
- );
943
-
944
- expect(result[0].variableOverrides).toEqual(variableOverrides);
945
- });
946
- });