Skip to content

Commit

Permalink
Disable forced test selector stripping in addon templates (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 authored and marcoow committed May 30, 2017
1 parent 6632cda commit 98607ab
Showing 1 changed file with 37 additions and 20 deletions.
57 changes: 37 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,36 @@ module.exports = {
}
},

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

if (this._stripTestSelectors) {
let StripTestSelectorsTransform = require('./strip-test-selectors');

registry.add('htmlbars-ast-plugin', {
name: 'strip-test-selectors',
plugin: StripTestSelectorsTransform,
baseDir() { return __dirname; }
});
} else {
let TransformTestSelectorParamsToHashPairs = require('./transform-test-selector-params-to-hash-pairs');
_setupPreprocessorRegistry(registry) {
if (this._stripTestSelectors) {
let StripTestSelectorsTransform = require('./strip-test-selectors');

registry.add('htmlbars-ast-plugin', {
name: 'strip-test-selectors',
plugin: StripTestSelectorsTransform,
baseDir() { return __dirname; }
});
} else {
let TransformTestSelectorParamsToHashPairs = require('./transform-test-selector-params-to-hash-pairs');

registry.add('htmlbars-ast-plugin', {
name: 'transform-test-selector-params-to-hash-pairs',
plugin: TransformTestSelectorParamsToHashPairs,
baseDir() { return __dirname; }
});
}
registry.add('htmlbars-ast-plugin', {
name: 'transform-test-selector-params-to-hash-pairs',
plugin: TransformTestSelectorParamsToHashPairs,
baseDir() { return __dirname; }
});
}
},

included(app) {
this._super.included.apply(this, arguments);
this._ensureFindHost();

let host = this._findHost();
this._assignOptions(host);

// we can't use the setupPreprocessorRegistry() hook as it is called to
// early and we do not have reliable access to `app.tests` there yet
this._setupPreprocessorRegistry(app.registry);

// add the StripDataTestPropertiesPlugin to the list of plugins used by
// the `ember-cli-babel` addon
Expand Down Expand Up @@ -97,4 +101,17 @@ module.exports = {
}
return tree;
},

_ensureFindHost() {
if (!this._findHost) {
this._findHost = function findHostShim() {
let current = this;
let app;
do {
app = current.app || app;
} while (current.parent.parent && (current = current.parent));
return app;
};
}
},
};

0 comments on commit 98607ab

Please sign in to comment.