Expand all

mw.tk

Methods

clearExperimentOverride(experimentName)static #

Clears all enrolment overrides for the experiment and reloads the page.

Parameters:

Name Type Description
experimentName string
Source:
Clears all enrolment overrides for the experiment and reloads the page.

clearExperimentOverrides()static #

Clears all experiment enrolment overrides for all experiments and reloads the page.

Source:
Clears all experiment enrolment overrides for all experiments and reloads the page.

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
Source:
Gets a map of experiment to group for all experiments that the current user is enrolled into.

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:

  1. Get information about the user's (more precisely, the subject's) enrollment in the experiment
  2. 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:

Type
Promise.<mw.testKitchen.ExperimentInterface>
Source:
Gets the details of an experiment.

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:

Type
Promise.<Array.<mw.testKitchen.ExperimentInterface>>
Source:
See:
Gets the details of all experiments with names that start with the given prefix.

getInstrument(instrumentName) → {mw.testKitchen.InstrumentInterface}static #

Gets details of an instrument.

This method always returns an instance of mw.testKitchen.InstrumentInterface that can:

  1. Determine whether the instrument is in-sample
  2. Send analytics events

Parameters:

Name Type Description
instrumentName string

Returns:

Type
mw.testKitchen.InstrumentInterface
Source:
Gets details of an instrument.

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:
Overrides an experiment enrolment and reloads the page.

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:

Type
mw.testKitchen.FakeExperimentsHelper
Source:
Stubs 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:

Type
mw.testKitchen.FakeInstrumentsHelper
Source:
Stubs mw.testKitchen.getInstrument, allowing developers to test their instruments.