Skip to content

Commit

Permalink
Merge pull request #338 from Turbo87/preproreg
Browse files Browse the repository at this point in the history
Use `setupPreprocessorRegistry()` hook to register HTMLBars AST plugin
  • Loading branch information
Turbo87 authored Mar 13, 2019
2 parents cdba20e + 8d4ee86 commit 59df04e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 41 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ More information on why that is useful are available on our
[![ember-test-selectors](https://cloud.githubusercontent.com/assets/2922250/25236119/0cc8e13a-25b5-11e7-8a5b-f29589384833.png)
](https://embermap.com/video/ember-test-selectors)


Compatibility
------------------------------------------------------------------------------

- Ember CLI 2.14 or above


Installation
------------------------------------------------------------------------------

Expand Down
65 changes: 24 additions & 41 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,34 @@ module.exports = {
}
},

_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; },
cacheKey() { return 'strip-test-selectors'; },
});
} 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; },
cacheKey() { return 'transform-test-selector-params-to-hash-pairs'; },
});
setupPreprocessorRegistry(type, registry) {
if (type === 'parent') {
this._assignOptions(this.app);

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

registry.add('htmlbars-ast-plugin', {
name: 'strip-test-selectors',
plugin: StripTestSelectorsTransform,
baseDir() { return __dirname; },
cacheKey() { return 'strip-test-selectors'; },
});
} 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; },
cacheKey() { return 'transform-test-selector-params-to-hash-pairs'; },
});
}
}
},

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 All @@ -83,7 +79,7 @@ module.exports = {
}

if (!this._stripTestSelectors) {
host.import('vendor/ember-test-selectors/patch-component.js');
this.app.import('vendor/ember-test-selectors/patch-component.js');
}
},

Expand All @@ -103,17 +99,4 @@ 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 59df04e

Please sign in to comment.