Skip to content

Commit

Permalink
[BUGFIX release] Prevent warnings for unknown feature flags.
Browse files Browse the repository at this point in the history
Only warn when features are enabled that we know about. This prevents a
warning when users enable Ember Data features when running stable
versions of Ember with canary versions of Ember Data.

(cherry picked from commit e41a857)
  • Loading branch information
rwjblue committed Apr 11, 2016
1 parent 2972281 commit a61e6a9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
16 changes: 10 additions & 6 deletions packages/ember-debug/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
debug,
setDebugFunction
} from 'ember-metal/debug';
import isEnabled, { FEATURES } from 'ember-metal/features';
import isEnabled, { FEATURES, KNOWN_FEATURES } from 'ember-metal/features';
import EmberError from 'ember-metal/error';
import Logger from 'ember-metal/logger';
import environment from 'ember-metal/environment';
Expand Down Expand Up @@ -174,14 +174,18 @@ setDebugFunction('warn', _warn);
@method _warnIfUsingStrippedFeatureFlags
@return {void}
*/
export function _warnIfUsingStrippedFeatureFlags(FEATURES, featuresWereStripped) {
export function _warnIfUsingStrippedFeatureFlags(FEATURES, knownFeatures, featuresWereStripped) {
if (featuresWereStripped) {
warn('Ember.ENV.ENABLE_OPTIONAL_FEATURES is only available in canary builds.', !Ember.ENV.ENABLE_OPTIONAL_FEATURES, { id: 'ember-debug.feature-flag-with-features-stripped' });

for (var key in FEATURES) {
if (FEATURES.hasOwnProperty(key) && key !== 'isEnabled') {
warn('FEATURE["' + key + '"] is set as enabled, but FEATURE flags are only available in canary builds.', !FEATURES[key], { id: 'ember-debug.feature-flag-with-features-stripped' });
let keys = Object.keys(FEATURES);
for (let i = 0; i < keys.length; i++) {
let key = keys[i];
if (key === 'isEnabled' || !(key in knownFeatures)) {
continue;
}

warn('FEATURE["' + key + '"] is set as enabled, but FEATURE flags are only available in canary builds.', !FEATURES[key], { id: 'ember-debug.feature-flag-with-features-stripped' });
}
}
}
Expand All @@ -196,7 +200,7 @@ if (!Ember.testing) {
}

delete FEATURES['features-stripped-test'];
_warnIfUsingStrippedFeatureFlags(Ember.ENV.FEATURES, featuresWereStripped);
_warnIfUsingStrippedFeatureFlags(Ember.ENV.FEATURES, KNOWN_FEATURES, featuresWereStripped);

// Inform the developer about the Ember Inspector if not installed.
var isFirefox = environment.isFirefox;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import Ember from 'ember-metal/core';
import { getDebugFunction, setDebugFunction } from 'ember-metal/debug';
import { _warnIfUsingStrippedFeatureFlags } from 'ember-debug';

var oldWarn, oldRunInDebug, origEnvFeatures, origEnableOptional;
var oldWarn, oldRunInDebug, origEnvFeatures, origEnableOptional, features, knownFeatures;

function confirmWarns(expectedMsg) {
var featuresWereStripped = true;
var FEATURES = Ember.ENV.FEATURES;

setDebugFunction('warn', function(msg, test) {
if (!test) {
Expand All @@ -19,11 +18,11 @@ function confirmWarns(expectedMsg) {
});

// Should trigger our 1 warning
_warnIfUsingStrippedFeatureFlags(FEATURES, featuresWereStripped);
_warnIfUsingStrippedFeatureFlags(features, knownFeatures, featuresWereStripped);

// Shouldn't trigger any warnings now that we're "in canary"
featuresWereStripped = false;
_warnIfUsingStrippedFeatureFlags(FEATURES, featuresWereStripped);
_warnIfUsingStrippedFeatureFlags(features, knownFeatures, featuresWereStripped);
}

QUnit.module('ember-debug - _warnIfUsingStrippedFeatureFlags', {
Expand All @@ -32,6 +31,12 @@ QUnit.module('ember-debug - _warnIfUsingStrippedFeatureFlags', {
oldRunInDebug = getDebugFunction('runInDebug');
origEnvFeatures = Ember.ENV.FEATURES;
origEnableOptional = Ember.ENV.ENABLE_OPTIONAL_FEATURES;

knownFeatures = {
'fred': null,
'barney': null,
'wilma': null
};
},

teardown() {
Expand All @@ -46,20 +51,31 @@ QUnit.test('Setting Ember.ENV.ENABLE_OPTIONAL_FEATURES truthy in non-canary, deb
expect(1);

Ember.ENV.ENABLE_OPTIONAL_FEATURES = true;
Ember.ENV.FEATURES = {};
features = {};

confirmWarns('Ember.ENV.ENABLE_OPTIONAL_FEATURES is only available in canary builds.');
});

QUnit.test('Enabling a FEATURES flag in non-canary, debug build causes a warning', function() {
QUnit.test('Enabling a known FEATURE flag in non-canary, debug build causes a warning', function() {
expect(1);

Ember.ENV.ENABLE_OPTIONAL_FEATURES = false;
Ember.ENV.FEATURES = {
features = {
'fred': true,
'barney': false,
'wilma': null
};

confirmWarns('FEATURE["fred"] is set as enabled, but FEATURE flags are only available in canary builds.');
});

QUnit.test('Enabling an unknown FEATURE flag in non-canary debug build does not cause a warning', function() {
expect(0);

Ember.ENV.ENABLE_OPTIONAL_FEATURES = false;
features = {
'some-ember-data-feature-flag': true
};

confirmWarns('FEATURE["fred"] is set as enabled, but FEATURE flags are only available in canary builds.');
});
3 changes: 2 additions & 1 deletion packages/ember-metal/lib/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import assign from 'ember-metal/assign';
@since 1.1.0
@public
*/
export var FEATURES = assign(DEFAULT_FEATURES, Ember.ENV.FEATURES); // jshint ignore:line
export const KNOWN_FEATURES = DEFAULT_FEATURES; // jshint ignore:line
export var FEATURES = assign(KNOWN_FEATURES, Ember.ENV.FEATURES);

/**
Determine whether the specified `feature` is enabled. Used by Ember's
Expand Down

0 comments on commit a61e6a9

Please sign in to comment.