Skip to content

Commit

Permalink
Add ability to specify envs to strip selectors.
Browse files Browse the repository at this point in the history
For example, removing the test selectors in a staging or other pre-production environment.
  • Loading branch information
blimmer committed Apr 5, 2016
1 parent 955fad6 commit 3b58999
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
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

0 comments on commit 3b58999

Please sign in to comment.