2020-09-30 17:10:09 -04:00
|
|
|
import { merge } from 'lodash';
|
|
|
|
|
2021-11-10 13:12:35 -05:00
|
|
|
// This helper is for specs that use `gitlab/experimentation` module
|
2020-09-30 17:10:09 -04:00
|
|
|
export function withGonExperiment(experimentKey, value = true) {
|
|
|
|
let origGon;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
origGon = window.gon;
|
|
|
|
window.gon = merge({}, window.gon || {}, { experiments: { [experimentKey]: value } });
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
window.gon = origGon;
|
|
|
|
});
|
|
|
|
}
|
2021-04-02 14:09:20 -04:00
|
|
|
|
2021-11-10 13:12:35 -05:00
|
|
|
// The following helper is for specs that use `gitlab-experiment` utilities,
|
|
|
|
// which have a different schema that gets pushed to the frontend compared to
|
|
|
|
// the `Experimentation` Module.
|
|
|
|
//
|
|
|
|
// Usage: stubExperiments({ experiment_feature_flag_name: 'variant_name', ... })
|
|
|
|
export function stubExperiments(experiments = {}) {
|
|
|
|
// Deprecated
|
|
|
|
window.gon = window.gon || {};
|
|
|
|
window.gon.experiment = window.gon.experiment || {};
|
|
|
|
// Preferred
|
|
|
|
window.gl = window.gl || {};
|
2021-12-17 19:14:00 -05:00
|
|
|
window.gl.experiments = window.gl.experiments || {};
|
2021-04-02 14:09:20 -04:00
|
|
|
|
2021-11-10 13:12:35 -05:00
|
|
|
Object.entries(experiments).forEach(([name, variant]) => {
|
|
|
|
const experimentData = { experiment: name, variant };
|
|
|
|
|
|
|
|
// Deprecated
|
|
|
|
window.gon.experiment[name] = experimentData;
|
|
|
|
// Preferred
|
|
|
|
window.gl.experiments[name] = experimentData;
|
2021-04-02 14:09:20 -04:00
|
|
|
});
|
|
|
|
}
|