An ember-cli addon to provide feature flags.
ember install ember-feature-flags
This addon injects a property features
(configurable) into your routes, controllers and components.
For example you may check if a feature is enabled:
export default Ember.Controller.extend({
plans: function(){
if (this.features.isEnabled('new-billing-plans')){
// Return new plans
} else {
// Return old plans
}
}.property()
});
Features are also available as properties of features
. They are camelized.
export default Ember.Controller.extend({
plans: function(){
if (this.features.get('newBillingPlans')){
// Return new plans
} else {
// Return old plans
}
}.property('features.newBillingPlans')
});
Check whether a feature is enabled in a template:
Features can be toggled at runtime, and are bound:
features.enable('newHomepage');
features.disable('newHomepage');
Features can be set in bulk:
features.setup({
"new-billing-plans": true,
"new-homepage": false
});
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;
};
The name of the features
injection can be customized with the featureFlagsService
config
option. For example:
// config/environment.js
module.exports = function(environment) {
var ENV = {
featureFlagsService: 'featuresService'
};
return ENV;
};
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.
Turns on a feature for the test in which it is called.
To use, import into your test-helper.js: import '<app-name>/tests/helpers/with-feature'
and add to your
test .jshintrc
, it will now be available in all of your tests.
Example:
import '<app-name>/tests/helpers/with-feature';
test( "links go to the new homepage", function () {
withFeature( 'new-homepage' );
visit('/');
click('a.home');
andThen(function(){
equal(currentRoute(), 'new.homepage', 'Should be on the new homepage');
});
});
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:
const { getOwner } = Ember;
let featuresService = Ember.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.
git clone
this repositorynpm install
bower install
ember server
- Visit your app at http://localhost:4200.
ember test
ember test --server
ember build