Skip to main content

Desktop Feature API testing

In order to make testing easier we created some helpers that can be accessed by including

const { ExperimentFakes } = ChromeUtils.import(  "resource://testing-common/NimbusTestUtils.jsm",);

Testing your feature integrating with Nimbus#

You need to provide a feature configuration and await enrollment

let doEnrollmentCleanup = await ExperimentFakes.enrollWithFeatureConfig({  featureId: "<YOUR FEATURE>",  // You can add values for each variable you added to the manifest  value: {    enabled: true,  },});
// Now you can assume the feature is enabled so you can// test and that it's doing the right thing
// Assert.ok(It works!)
// Finishing upawait doExperimentCleanup();

Testing with a live Nimbus recipe#

If you already published an experiment through Nimbus then you will want to test enrollment in the browser.

  1. Flip the following pref to true in the browser you want to enroll (in about:config)


  1. You need to copy paste the following URL and fill in the required details.

For experiments that are already live:


For experiments that are in "preview" mode:


Testing with Desktop Rollouts#

For writing tests you usually want to have the following modules imported:

const { ExperimentAPI, NimbusFeatures } = ChromeUtils.import(  "resource://nimbus/ExperimentAPI.jsm",);const { ExperimentFakes } = ChromeUtils.import(  "resource://testing-common/NimbusTestUtils.jsm",);

Next this is how you would set up your feature to test integration with Desktop Rollouts:

// Ensure everything has finished initializingawait ExperimentAPI.ready();// The actual setupconst doCleanup = await ExperimentFakes.enrollWithRollout({  // Reference your feature id already defined in the FeatureManifest.yaml  featureId: "<YOUR FEATURE ID>",  value: {    variables: { enabled: true },  },});
// Now your feature integration is ready for testing
// NimbusFeature.<YOUR FEATURE>.getVariable("enabled")// NimbusFeature.<YOUR FEATURE>.getAllVariables()
await doCleanup(); // to remove the rollout

Testing with gTest#

Otherwise for a gTest or other requirements you can set a pref nimbus.syncdatastore.<feature name>.<variable name> with the appropriate type you defined in the FeatureManifest.

⚠️ This variable naming convention is an implementation detail and might change in the future.

#include "mozilla/browser/NimbusFeatures.h"
# Set a preference as described above based on what you want the test to do
// GetInt will return the appropriate value you setNimbusFeatures::GetInt("aboutwelcome"_ns, "skipFocus"_ns, false);
// On update will call your callback function when the pref value changesNimbusFeatures::OnUpdate("aboutwelcome"_ns, "skipFocus"_ns,  [](const char*, void*){}, void*);


Examples of platform consumers: