From b6de886d0813e203526c1a81415105cadb6dce43 Mon Sep 17 00:00:00 2001 From: Chris Garrett <cgarrett@linkedin.com> Date: Wed, 23 Oct 2019 09:42:26 -0700 Subject: [PATCH] [FEATURE] Adds isFeatureExplicitlySet API This API lets us check if a feature is explicitly set (e.g. given a value in the config) --- index.js | 4 ++++ tests/optional-features-test.js | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/index.js b/index.js index 6ea5521..09d5a71 100644 --- a/index.js +++ b/index.js @@ -62,6 +62,10 @@ module.exports = { return value !== undefined ? value : FEATURES[name].default; }, + isFeatureExplicitlySet(name) { + return this._features[name] !== undefined; + }, + config() { let EmberENV = {}; let features = this._features; diff --git a/tests/optional-features-test.js b/tests/optional-features-test.js index 8adfd2f..9cd6219 100644 --- a/tests/optional-features-test.js +++ b/tests/optional-features-test.js @@ -127,6 +127,15 @@ QUnit.module('@ember/optional-features', hooks => { assert.strictEqual(addon.isFeatureEnabled('template-only-glimmer-components'), false, 'Expecting default value'); }); + QUnit.test('it can query the features with `isFeatureExplicitlySet`', assert => { + let addon = buildAddon({ + 'application-template-wrapper': false + }); + + assert.strictEqual(addon.isFeatureExplicitlySet('application-template-wrapper'), true, 'Expecting value to exist'); + assert.strictEqual(addon.isFeatureExplicitlySet('template-only-glimmer-components'), false, 'Expecting to not exist'); + }); + QUnit.test('it allows the config to be a overridden with an ENV variable', assert => { process.env.EMBER_OPTIONAL_FEATURES = `{ "application-template-wrapper": false }`;