From 4bd7d3aef2c1a2665fdce78ce25f25d16aaaffc1 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 9 Jan 2017 15:21:13 +0100 Subject: [PATCH 1/4] Register "strip-test-selectors" preprocessor only once No need to register it for the addon *and* the parent app --- index.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index ba60eb6b..1215ae10 100644 --- a/index.js +++ b/index.js @@ -5,18 +5,20 @@ module.exports = { name: 'test-selectors', setupPreprocessorRegistry: function(type, registry) { - var appOptions = registry.app.options || {}; - var addonOptions = appOptions['ember-test-selectors'] || {}; - var environments = addonOptions.environments || ['production']; + if (type === 'parent') { + var appOptions = registry.app.options || {}; + var addonOptions = appOptions['ember-test-selectors'] || {}; + var environments = addonOptions.environments || ['production']; - if (environments.indexOf(registry.app.env) !== -1) { - var StripTestSelectorsTransform = require('./strip-test-selectors'); + if (environments.indexOf(registry.app.env) !== -1) { + var StripTestSelectorsTransform = require('./strip-test-selectors'); - registry.add('htmlbars-ast-plugin', { - name: 'strip-test-selectors', - plugin: StripTestSelectorsTransform, - baseDir: function() { return __dirname; } - }); + registry.add('htmlbars-ast-plugin', { + name: 'strip-test-selectors', + plugin: StripTestSelectorsTransform, + baseDir: function() { return __dirname; } + }); + } } } }; From dfa8d844a73d3878386825d3e590a43c6d142516 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 9 Jan 2017 15:22:24 +0100 Subject: [PATCH 2/4] Extract _assignOptions() method --- index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 1215ae10..c2cd7861 100644 --- a/index.js +++ b/index.js @@ -4,13 +4,19 @@ module.exports = { name: 'test-selectors', + _assignOptions: function(app) { + var appOptions = app.options || {}; + var addonOptions = appOptions['ember-test-selectors'] || {}; + var environments = addonOptions.environments || ['production']; + + this._stripTestSelectors = (environments.indexOf(app.env) !== -1); + }, + setupPreprocessorRegistry: function(type, registry) { if (type === 'parent') { - var appOptions = registry.app.options || {}; - var addonOptions = appOptions['ember-test-selectors'] || {}; - var environments = addonOptions.environments || ['production']; + this._assignOptions(registry.app); - if (environments.indexOf(registry.app.env) !== -1) { + if (this._stripTestSelectors) { var StripTestSelectorsTransform = require('./strip-test-selectors'); registry.add('htmlbars-ast-plugin', { From 204f9bc7d1343110c070ea01c11cc3679c23e68f Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 9 Jan 2017 15:30:47 +0100 Subject: [PATCH 3/4] Replace "environments" with "strip" option Actually, we don't replace it, but instead we deprecate the old option and introduce the new option on the side --- ember-cli-build.js | 3 +-- index.js | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ember-cli-build.js b/ember-cli-build.js index 7db201f9..b43e9744 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -3,11 +3,10 @@ var EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); module.exports = function(defaults) { var stripTestSelectors = process.env['STRIP_TEST_SELECTORS']; - var environments = stripTestSelectors ? ['test'] : ['production']; var app = new EmberAddon(defaults, { 'ember-test-selectors': { - environments: environments + strip: Boolean(stripTestSelectors) } }); diff --git a/index.js b/index.js index c2cd7861..28eeb4ba 100644 --- a/index.js +++ b/index.js @@ -5,11 +5,22 @@ module.exports = { name: 'test-selectors', _assignOptions: function(app) { + var ui = app.project.ui; + var appOptions = app.options || {}; var addonOptions = appOptions['ember-test-selectors'] || {}; - var environments = addonOptions.environments || ['production']; - this._stripTestSelectors = (environments.indexOf(app.env) !== -1); + if (addonOptions.environments) { + ui.writeDeprecateLine('The "environments" option in "ember-test-selectors" has been replaced ' + + 'with a "strip" option. Use e.g. "strip: EmberApp.env() === \'production\'" instead to ' + + 'recreate the old behavior.', false); + + this._stripTestSelectors = (addonOptions.environments.indexOf(app.env) !== -1); + } else if ('strip' in addonOptions) { + this._stripTestSelectors = addonOptions.strip; + } else { + this._stripTestSelectors = app.tests; + } }, setupPreprocessorRegistry: function(type, registry) { From 606d5b505c489c579c17f81fb366a16dcac59825 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 9 Jan 2017 16:39:18 +0100 Subject: [PATCH 4/4] Adjust deprecation message wording --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 28eeb4ba..5f78a186 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,7 @@ module.exports = { if (addonOptions.environments) { ui.writeDeprecateLine('The "environments" option in "ember-test-selectors" has been replaced ' + - 'with a "strip" option. Use e.g. "strip: EmberApp.env() === \'production\'" instead to ' + + 'with the "strip" option. Use e.g. "strip: EmberApp.env() === \'production\'" instead to ' + 'recreate the old behavior.', false); this._stripTestSelectors = (addonOptions.environments.indexOf(app.env) !== -1);