└── clients.js /clients.js: -------------------------------------------------------------------------------- 1 | /* This Source Code Form is subject to the terms of the Mozilla Public 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 | 5 | describe('client', function () { 6 | describe('facebook style', function () { 7 | // https://github.com/facebook/planout 8 | 9 | describe('get', function () { 10 | it('returns a variant', function () { 11 | var experiment = new MyExperiment('user_id'); 12 | var value = experiment.get('feature_name'); 13 | }); 14 | }); 15 | }); 16 | 17 | 18 | describe('etsy style', function () { 19 | // https://github.com/etsy/feature 20 | 21 | describe('isEnabled', function () { 22 | it('checks if a feature is enabled', function () { 23 | if (experiment.isEnabled('feature_name')) { 24 | // use feature here. 25 | } 26 | }); 27 | }); 28 | 29 | describe('variant', function () { 30 | it('gets a variant for a feature, must be wrapped in isEnabled', function () { 31 | if (experiment.isEnabled('feature_name')) { 32 | var value = experiment.variant('feature_name'); 33 | // use value here. 34 | } 35 | }); 36 | }); 37 | }); 38 | 39 | 40 | describe('sixpack style', function () { 41 | // https://github.com/seatgeek/sixpack-js 42 | 43 | describe('participate', function () { 44 | it('gets a variant', function () { 45 | experiment.participate('feature_name', ['option1', 'option2'], function (err, res) { 46 | if (err) throw err; 47 | 48 | var value = res.alternative.name; 49 | // use value here. 50 | }); 51 | }); 52 | }); 53 | }); 54 | 55 | 56 | describe('proctor style', function () { 57 | // http://indeedeng.github.io/proctor/docs/quick-start/ 58 | 59 | describe('get', function () { 60 | it('gets a variant', function () { 61 | // lots of setup before this. 62 | var value = experiment.get('feature_name'); 63 | }); 64 | }); 65 | }); 66 | 67 | 68 | describe('redfin style', function () { 69 | // http://blog.redfin.com/devblog/2014/02/a-b-testing-build-or-buy.html 70 | // unable to find a link to their library 71 | }); 72 | 73 | 74 | describe('waffle style', function () { 75 | // http://waffle.readthedocs.org/en/latest/usage.html#wafflejs-view 76 | 77 | /** 78 | * From http://waffle.readthedocs.org/en/latest/types.html: 79 | * 80 | * A Flag is tied to a request, while Switches and Samples are 81 | * not. Consequently, Flags are much more complicated, while Switches are 82 | * just a named boolean in the database, and Samples are just a percentage 83 | * stored in the database. 84 | */ 85 | 86 | describe('flag_is_active', function () { 87 | it('returns a boolean', function () { 88 | if (experiment.flag_is_active(request, 'feature_name')) { 89 | // flag is active 90 | } else { 91 | // flag is inactive 92 | } 93 | }); 94 | }); 95 | 96 | describe('switch_is_active', function () { 97 | it('returns a boolean', function () { 98 | if (experiment.switch_is_active('feature_name')) { 99 | // switch is active 100 | } else { 101 | // switch is inactive 102 | } 103 | }); 104 | }); 105 | 106 | describe('sample_is_active', function () { 107 | it('returns a boolean', function () { 108 | if (experiment.sample_is_active('feature_name')) { 109 | // sample is active 110 | } else { 111 | // sample is inactive 112 | } 113 | }); 114 | }); 115 | }); 116 | 117 | 118 | describe('optimizely style', function () { 119 | // http://developers.optimizely.com/javascript/ 120 | 121 | describe('what a mess', function () { 122 | }); 123 | }); 124 | 125 | 126 | describe('vanity style', function () { 127 | // http://vanity.labnotes.org/ab_testing.html 128 | 129 | describe('ab_test', function () { 130 | it('can return a boolean', function () { 131 | if (experiments.ab_test('feature_name')) { 132 | // feature is active 133 | } 134 | }); 135 | 136 | it('can return one of several options', function () { 137 | // options setup externally 138 | 139 | var value = experiments.ab_test('feature_name'); 140 | }); 141 | }); 142 | }); 143 | 144 | 145 | describe('cohorts style', function () { 146 | // https://github.com/jamesyu/cohorts/ 147 | 148 | describe('Cohorts.Test', function () { 149 | var test = new Cohorts.Test({ 150 | name: 'feature_name', 151 | sample: 1, // include all visitors in the test 152 | cohorts: { 153 | option1: { 154 | onChosen: function () { 155 | // do something like show a DOM element. 156 | } 157 | }, 158 | option2: { 159 | onChosen: function () { 160 | // do something like show another DOM element. 161 | } 162 | } 163 | } 164 | }); 165 | }); 166 | 167 | describe('inChorhort', function () { 168 | it('returns a boolean - based on Cohorts.Test setup above', function () { 169 | var isInCohort = test.inCohort('option1'); 170 | }); 171 | }); 172 | 173 | describe('getCohort', function () { 174 | it('returns a cohort name - based on Cohorts.Test setup above', function () { 175 | var cohortName = test.getChorhort(); 176 | // cohortName is either `option1` or `option2` 177 | }); 178 | }); 179 | }); 180 | 181 | 182 | describe('google style', function () { 183 | // https://developers.google.com/analytics/devguides/collection/analyticsjs/experiments 184 | 185 | describe('chooseVariation', function () { 186 | it('chooses a variation for the user', function () { 187 | // experiment ID is set up when loading the client. 188 | 189 | var value = experiments.chooseVariation(); 190 | }); 191 | }); 192 | 193 | describe('getChosenVariation', function () { 194 | it('gets a previously chosen variation for the user', function () { 195 | var value = experiments.chooseVariation('experiment_id'); 196 | }); 197 | }); 198 | }); 199 | 200 | }); 201 | 202 | 203 | --------------------------------------------------------------------------------