Methods
clearExperimentOverride(experimentName)static
#
Clears all enrolment overrides for the experiment and reloads the page.
Parameters:
| Name | Type | Description |
|---|---|---|
experimentName |
string |
- Source:
clearExperimentOverrides()static
#
Clears all experiment enrolment overrides for all experiments and reloads the page.
- Source:
getAssignments() → {Object}packagestatic
#
Gets a map of experiment to group for all experiments that the current user is enrolled into.
This method is internal and should only be used by other Test Kitchen components. Currently, this method is only used by [the Client Error Logging instrument in WikimediaEvents][0].
Returns:
- Type
- Object
getExperiment(experimentName) → {Promise.<mw.testKitchen.ExperimentInterface>}static
#
Gets the details of an experiment.
This method returns a promise that will always resolve with an instance of
mw.testKitchen.ExperimentInterface that can:
- Get information about the user's (more precisely, the subject's) enrollment in the experiment
- Send analytics events relating to the experiment
Example
const myAwesomeDialog = require( 'my.awesome.dialog' );
mw.testKitchen.getExperiment( 'my-awesome-non-cache-splitting-experiment' )
.then( ( e ) => {
[
'open',
'default-action',
'primary-action'
].forEach( ( event ) => {
myAwesomeDialog.on( event, () => e.send( event ) );
} );
// Was the current user assigned to the treatment group?
if ( e.isAssignedGroup( 'treatment' ) ) {
myAwesomeDialog.primaryAction.label = 'Awesome!';
}
} );
Parameters:
| Name | Type | Description |
|---|---|---|
experimentName |
string | The experiment name |
Returns:
getExperimentsByPrefix(experimentNamePrefix) → {Promise.<Array.<mw.testKitchen.ExperimentInterface>>}packagestatic
#
Gets the details of all experiments with names that start with the given prefix.
This method should only be used for experiments that repeat, e.g. a data collection activity that lasts three weeks and repeats every week, and therefore usage is expected to be rare. In these cases, this method can be used to minimize the number of code changes in the experiment.
Note well that the details are returned in any order.
Example
// The user is enrolled in the following experiments:
//
// - my-awesome-experiment-1
// - my-awesome-experiment-2
// - my-other-awesome-experiment
// Gets the details of the "my-awesome-experiment-1" and "my-awesome-experiment-2" experiments
mw.testKitchen.getExperimentByPrefix( 'my-awesome-experiment-' );
Parameters:
| Name | Type | Description |
|---|---|---|
experimentNamePrefix |
string |
Returns:
- Source:
- See:
getInstrument(instrumentName) → {mw.testKitchen.InstrumentInterface}static
#
Gets details of an instrument.
This method always returns an instance of mw.testKitchen.InstrumentInterface that can:
- Determine whether the instrument is in-sample
- Send analytics events
Parameters:
| Name | Type | Description |
|---|---|---|
instrumentName |
string |
Returns:
overrideExperimentGroup(experimentName, groupName)static
#
Overrides an experiment enrolment and reloads the page.
Parameters:
| Name | Type | Description |
|---|---|---|
experimentName |
string | The name of the experiment |
groupName |
string | The assigned group that will override the assigned one |
- Source:
useFakeExperiments() → {mw.testKitchen.FakeExperimentsHelper}static
#
Stubs mw.testKitchen.getExperiment, allowing developers to test their experiments.
Example
const tk = mw.testKitchen.useFakeExperiments();
const e = tk.stubExperiment( 'my-awesome-experiment', 'treatment' );
// Run Code Under Test
assert.strictEqual( e.eventCount, 1 );
assert.strictEqual( e.events[ 0 ].action, 'my-awesome-action' );
assert.strictEqual( tk.globalEventCount, 1 );
Returns:
- Source:
mw.testKitchen.getExperiment, allowing developers to test their experiments.
useFakeInstruments() → {mw.testKitchen.FakeInstrumentsHelper}static
#
Stubs mw.testKitchen.getInstrument, allowing developers to test their instruments.
Example
const tk = mw.testKitchen.useFakeInstruments();
const i = tk.stubInstrument( 'my-awesome-instrument' );
// Run Code Under Test
assert.strictEqual( i.eventCount, 1 );
assert.strictEqual( i.events[ 0 ].action, 'my-awesome-action' );
assert.strictEqual( tk.globalEventCount, 1 );
Returns:
- Source:
mw.testKitchen.getInstrument, allowing developers to test their instruments.