Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce "strip" and deprecate "environments" option #42

Merged
merged 4 commits into from
Jan 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
});

Expand Down
39 changes: 29 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,38 @@
module.exports = {
name: 'test-selectors',

setupPreprocessorRegistry: function(type, registry) {
var appOptions = registry.app.options || {};
_assignOptions: function(app) {
var ui = app.project.ui;

var appOptions = 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 (addonOptions.environments) {
ui.writeDeprecateLine('The "environments" option in "ember-test-selectors" has been replaced ' +
'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);
} else if ('strip' in addonOptions) {
this._stripTestSelectors = addonOptions.strip;
} else {
this._stripTestSelectors = app.tests;
}
},

setupPreprocessorRegistry: function(type, registry) {
if (type === 'parent') {
this._assignOptions(registry.app);

if (this._stripTestSelectors) {
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; }
});
}
}
}
};