Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ember-feature-flags

kategengler17.9kMIT8.0.0TypeScript support: definitely-typed

Feature flags/toggles for Ember apps

ember-addon, feature-flag, feature-toggle, features-switch

readme

ember-feature-flags Build Status Ember Observer Score

An ember-cli addon to provide feature flags.

Versions

Tested against ember-source v4.12, v5.8, v5.12, v6.2, canary and beta.

For support for earlier ember-source use `ember-feature-flags@6.1.0`.

Installation

ember install ember-feature-flags

Usage

This addon provides a service named features available for injection into your routes, controllers, components, etc.

For example you may check if a feature is enabled:

import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
export default class BillingPlansController extends Controller {
  @service features;
  get plans() {
    if (this.features.isEnabled('newBillingPlans')) {
      // Return new plans
    } else {
      // Return old plans
    }
  }
}

Check whether a feature is enabled in a template by using the feature-flag template helper:

// templates/components/homepage-link.hbs
{{#if (feature-flag 'newHomepage')}}
  {{link-to "new.homepage"}}
{{else}}
  {{link-to "old.homepage"}}
{{/if}}

Features can be toggled at runtime, and are bound:

  this.features.enable('newHomepage');
  this.features.disable('newHomepage');

Features can be set in bulk, resetting all existing features:

this.features.setup({
  "new-billing-plans": true,
  "new-homepage": false
})

You may want to set the flags based on the result of a fetch:

// routes/application.js
@service features;
beforeModel() {
   return fetch('/my-flag/api').then((data) => {
     features.setup(data.json());
  });
}

NOTE: setup methods reset previously setup flags and their state.

You can get list of known feature flags via flags computed property:

this.features.setup({
  "new-billing-plans": true,
  "new-homepage": false
});

this.features.flags // ['newBillingPlans', 'newHomepage']

Configuration

config.featureFlags

You can configure a set of initial feature flags in your app's config/environment.js file. This is an easy way to change settings for a given environment. For example:

// config/environment.js
module.exports = function(environment) {
  var ENV = {
    featureFlags: {
      'show-spinners': true,
      'download-cats': false
    }
  };

  if (environment === 'production') {
    ENV.featureFlags['download-cats'] = true;
  }

  return ENV;
};

ENV.LOG_FEATURE_FLAG_MISS

Will log when a feature flag is queried and found to be off, useful to prevent cursing at the app, wondering why your feature is not working.

Test Helpers

enableFeature / disableFeature

Turns on or off a feature for the test in which it is called. Requires ember-cli-qunit >= 4.1.0 and the newer style of tests that use setupTest, setupRenderingTest, setupApplicationTest.

Example:

import { enableFeature, disableFeature } from 'ember-feature-flags/test-support';

module('Acceptance | Awesome page', function(hooks) {
  setupApplicationTest(hooks);

  test('it displays the expected welcome message', async function (assert) {
    enableFeature('new-welcome-message');

    await visit('/');

    assert.dom('h1.welcome-message').hasText('Welcome to the new website!');

    disableFeature('new-welcome-message');

    await settled();

    assert.dom('h1.welcome-message').hasText('This is our old website, upgrade coming soon');
  });
});

Integration Tests

If you use this.features.isEnabled() in components under integration test, you will need to inject a stub service in your tests. Using ember-qunit 0.4.16 or later, here's how to do this:

let featuresService = Service.extend({
  isEnabled() {
    return false;
  }
});

moduleForComponent('my-component', 'Integration | Component | my component', {
  integration: true,
  beforeEach() {
    this.register('service:features', featuresService);
    getOwner(this).inject('component', 'features', 'service:features');
  }
});

Note: for Ember before 2.3.0, you'll need to use ember-getowner-polyfill.

Development

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.

changelog

CHANGELOG

Release (2025-02-22)

ember-feature-flags 8.0.0 (major)

:boom: Breaking Change

  • ember-feature-flags
    • #133 Remove normalization of feature flags. Previously feature flags were converted to camelcase internally. (@kategengler)

Committers: 1

Release (2025-02-22)

ember-feature-flags 7.0.0 (major)

:boom: Breaking Change

  • ember-feature-flags
    • #131 Upgrade and modernize ember-feature-flags (@kategengler)
      • Remove deprecated withFeature test helper ... enableFeature is the modern helper
      • Remove deprecated proxy behavior of the Features service. features.myFlag and features.get('myFlag') are no longer available. Use features.isEnabled('myFlag') or the feature-flag template helper
      • Update the features service to use tracked instead of the old Ember reactivity system. Flags are now stored as a TrackedMap
      • Update the minimum Node version to Node 18
      • Support Ember >= 4.12. For older versions use ember-feature-flags@6.1.0

Committers: 1

v6.1.0 (2025-02-11)

:boom: Deprecations

  • #129 Deprecate features that will be removed in 7.0 to facilitate modernization (@kategengler)
    • Deprecate withFeature test helper from old-style Ember tests
    • Deprecate the proxy behavior of the features service. In 7.0, features.myFeature and features.get('myFeature') will no longer work. Use isEnabled and the {{feature-flag}} template helper instead.

:rocket: Enhancement

:memo: Documentation

:house: Internal

Committers: 5

v6.0.0 (2019-10-23)

:boom: Breaking Change

  • #84 Drop support for Node versions < 8

:bug: Bug Fix

  • #83 Fix deprecation warning for computed.volatile

v5.0.0 (2018-02-27)

:boom: Breaking Change :bug: Bug Fix

  • #71 Update new style testing helpers usage to support integration tests. (@SergeAstapov) Breaking Change: No longer pass this.owner into enableFeature, it is now just enableFeature('foo')

:house: Internal

Committers: 2

v4.2.0 (2018-02-02)

:rocket: Enhancement

:house: Internal

Committers: 2

v4.1.0

  • Add feature-flag helper for use in templates (Thanks @SergeAstapov)

v4.0.0

  • Remove default injection of the features service, it must now be explicitly injected where you want to use it. (Thanks @SergeAstapov)
  • Remove configuration option for the name of the default injected features service. (Thanks @SergeAstapov)
  • Move test helper withFeature to addon-test-support, it should now be imported from ember-feature-flags/test/helpers/with-feature (Thanks @SergeAstapov)

v3.0.1

  • Deprecate default injection of the features service, it must now be explicitly injected where you want to use it. (Thanks @SergeAstapov)

v3.0.0

  • features is now a Ember.Service. It is still injected by default, and at the configured name into routes, controllers and components. This may be a breaking change if you were injecting the service elsewhere. The injection is now service:<configured name>.
  • Bugfix: LOG_FEATURE_FLAG_MISS should now work
  • Deprecated features have been removed: features.enabled (which became features.isEnabled), resetFeatureFlags test helper (no longer needed), setting feature flags via APP.FEATURES
  • features.setup will now notifyPropertyChange for the flags set (Thanks @jcope2013)
  • Test helpers are now in the test-support folder that will merge with host app's test directory

v2.0.1

  • Fix deprecations that started with Ember 2.1 (Thanks @Arkham)
  • Upgrade ember-cli
  • Test against Ember 1.12 -> canary

v2.0.0

  • Breaking: Upgraded ember-cli and ember to 1.13 series, tests no longer pass against ember 1.11 and so compatibility is now >=1.12.0. Suspect the addon will still work under 1.11 and that the failures are due to ember-cli interactions.
  • Eliminate deprecations in app and test suite

v1.1.0

  • Upgrade ember-cli

v1.0.0

  • 1.0 because its been used in production for months and we're making changes with nice deprecations
  • resetFeatureFlags is no longer necessary to reset flags between tests; flags are not shared between app instances anymore
  • enabled renamed to isEnabled
  • Flags should now be set via the featureFlags key in the config, rather than APP.FEATURES
  • The service name can now be customized using featureFlagsService config

v0.0.4

  • Upgrade to ember-cli 0.0.2

v0.0.3

  • Breaking change: Remove use of window.Features; flags can now be specified in config or explicitly setup with features.setup
  • Breaking change: Remove handlebars helper - compatibility with htmlbars
  • Feature: Feature flags are now bound in templates with regular if statements, in a camelized form ('new-feature' becomes 'newFeature'). See Readme.
  • Bugfix: Logging now turns off if the config flag is off.

v0.0.1, v0.0.2

  • Initial commit