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

Add ability to specify envs to strip selectors. #14

Merged
merged 1 commit into from
Apr 6, 2016
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Unreleased

* `environments` configuration option.

# 0.0.2

* Add the `testSelector` test helper that makes generating `data` attribute
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,25 @@ delivered__:
</article>
```

## Configuartion
To modify the default configuration, place a block called `ember-test-selectors`
in your `ember-cli-build.js` file.

### Options

`environments`
Defines the environments in which you want the test selectors to be removed.
By default, selectors are only removed in the `production` environment. You
might also want to remove them in other staging environments for testing.

```javascript
var app = new EmberApp({
'ember-test-selectors': {
environments: ['production', 'staging']
}
});
```

## Test Helpers

`ember-test-selectors` comes with a test helper that can be used in acceptance
Expand Down
16 changes: 11 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
/*jshint node:true*/
var StringTestSelectorsTransform = require('./strip-test-selectors');
var _includes = require('lodash/includes');

module.exports = {
name: 'test-selectors',

included: function() {
if (this.app.env === 'production') {
this.app.registry.add('htmlbars-ast-plugin', {
setupPreprocessorRegistry: function(type, registry) {
var appOptions = registry.app.options || {};
var addonOptions = appOptions['ember-test-selectors'] || {};
var environments = addonOptions.environments || ['production'];

if (_includes(environments, registry.app.env)) {
var StripTestSelectorsTransform = require('./strip-test-selectors');

registry.add('htmlbars-ast-plugin', {
name: 'strip-test-selectors',
plugin: StringTestSelectorsTransform
plugin: StripTestSelectorsTransform
});
}
}
Expand Down