debian-mirror-gitlab/spec/frontend/__helpers__/experimentation_helper.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

39 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-01-03 14:25:43 +05:30
import { merge } from 'lodash';
2021-12-11 22:18:48 +05:30
// This helper is for specs that use `gitlab/experimentation` module
2021-01-03 14:25:43 +05:30
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-29 21:17:54 +05:30
2021-12-11 22:18:48 +05:30
// 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 || {};
2022-01-26 12:08:38 +05:30
window.gl.experiments = window.gl.experiments || {};
2021-04-29 21:17:54 +05:30
2021-12-11 22:18:48 +05:30
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-29 21:17:54 +05:30
});
}