Skip to content

Commit

Permalink
Fix positional to hash params transform for Ember 1.11/1.12 (#155)
Browse files Browse the repository at this point in the history
* Enable HBS transforms for Ember 1.13.0 and below again

* Fix HBS transforms for AST difference in Ember 1.11/1.12

* Extract Ember version checks into separate module

* Reenable most positional param to hash pair tests

* Remove unused `ember-compatibility-helpers` dependency
  • Loading branch information
Turbo87 authored and marcoow committed Nov 9, 2017
1 parent 9c6b092 commit 1f8dea4
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 62 deletions.
10 changes: 3 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,9 @@ module.exports = {
let host = this._findHost();
this._assignOptions(host);

let emberChecker = new VersionChecker(app).forEmber();

if (emberChecker.isAbove('1.13.0')) {
// 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);
}
// 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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"ember-cli-inject-live-reload": "^1.6.1",
"ember-cli-qunit": "^4.0.0",
"ember-cli-shims": "^1.1.0",
"ember-compatibility-helpers": "^0.1.2",
"ember-disable-prototype-extensions": "^1.1.2",
"ember-load-initializers": "^1.0.0",
"ember-resolver": "^4.3.0",
Expand Down
4 changes: 4 additions & 0 deletions strip-test-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ StripTestSelectorsTransform.prototype.transform = function(ast) {
return !isTestSelector(attribute.name);
});
} else if (node.type === 'MustacheStatement' || node.type === 'BlockStatement') {
if ('sexpr' in node) {
node = node.sexpr;
}

node.params = node.params.filter(function(param) {
return !isTestSelector(param.original);
});
Expand Down
37 changes: 17 additions & 20 deletions tests/acceptance/bind-data-test-attributes-in-components-test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { test } from 'qunit';
import { test, skip } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

import config from 'dummy/config/environment';

import { GTE_EMBER_1_13 } from 'ember-compatibility-helpers';
import { hasPositionalParams } from 'dummy/version-checks';

if (!config.stripTestSelectors) {

Expand Down Expand Up @@ -49,25 +48,23 @@ if (!config.stripTestSelectors) {
assert.equal(find('.test6').find('div[data-non-test]').length, 0, 'data-non-test does not exists');
});

if (GTE_EMBER_1_13) {
test('it binds data-test-* attributes with boolean values on components', function(assert) {
assert.equal(find('.test7').find('div[data-test-with-boolean-value]').length, 1, 'data-test-with-boolean-value exists');
});
test('it binds data-test-* attributes with boolean values on components', function(assert) {
assert.equal(find('.test7').find('div[data-test-with-boolean-value]').length, 1, 'data-test-with-boolean-value exists');
});

test('it binds data-test-* attributes without values on components', function(assert) {
assert.equal(find('.test8').find('div[data-test-without-value]').length, 1, 'data-test-without-value exists');
});
test('it binds data-test-* attributes without values on components', function(assert) {
assert.equal(find('.test8').find('div[data-test-without-value]').length, 1, 'data-test-without-value exists');
});

test('it binds data-test-* attributes without values on block components', function(assert) {
assert.equal(find('.test9').find('div[data-test-without-value]').length, 1, 'data-test-without-value exists');
});
test('it binds data-test-* attributes without values on block components', function(assert) {
assert.equal(find('.test9').find('div[data-test-without-value]').length, 1, 'data-test-without-value exists');
});

test('it leaves data-test attribute without value untouched on components', function(assert) {
assert.equal(find('.test10').find('div[data-test]').length, 0, 'data-test does not exists');
});
(hasPositionalParams ? test : skip)('it leaves data-test attribute without value untouched on components', function(assert) {
assert.equal(find('.test10').find('div[data-test]').length, 0, 'data-test does not exists');
});

test('it transforms data-test params to hash pairs on components', function(assert) {
assert.equal(find('.test11').find('div[data-test-something]').length, 1, 'data-test-something exists');
});
}
test('it transforms data-test params to hash pairs on components', function(assert) {
assert.equal(find('.test11').find('div[data-test-something]').length, 1, 'data-test-something exists');
});
}
4 changes: 2 additions & 2 deletions tests/dummy/app/controllers/bind-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Ember from 'ember';
import { GTE_EMBER_1_13 } from 'ember-compatibility-helpers';
import { hasPositionalParams } from 'dummy/version-checks';

const { Controller } = Ember;

export default Controller.extend({
shouldRenderParamTests: GTE_EMBER_1_13
hasPositionalParams,
});
10 changes: 5 additions & 5 deletions tests/dummy/app/templates/bind-test.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

<div class="test7">{{data-test-component data-test-with-boolean-value=true}}</div>

{{#if shouldRenderParamTests}}
<div class="test8">{{data-test-component data-test-without-value}}</div>
<div class="test8">{{data-test-component data-test-without-value}}</div>

<div class="test9">{{#data-test-component data-test-without-value}}foo{{/data-test-component}}</div>
<div class="test9">{{#data-test-component data-test-without-value}}foo{{/data-test-component}}</div>

{{#if hasPositionalParams}}
<div class="test10">{{data-test-component data-test}}</div>

<div class="test11">{{data-test-component data-test-something some-prop="prop"}}</div>
{{/if}}

<div class="test11">{{data-test-component data-test-something some-prop="prop"}}</div>
23 changes: 23 additions & 0 deletions tests/dummy/app/version-checks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Ember from 'ember';

const { VERSION } = Ember;

const EMBERS_WITHOUT_POSITIONAL_PARAMS = [
'1.12',
'1.11',
];

const EMBERS_WITHOUT_RELIABLE_POSITIONAL_PARAMS = [
'2.2',
'2.1',
'2.0',
'1.13',
'1.12',
'1.11',
];

export const hasPositionalParams = !EMBERS_WITHOUT_POSITIONAL_PARAMS
.some(version => VERSION.indexOf(`${version}.`) === 0);

export const hasReliablePositionalParams = !EMBERS_WITHOUT_RELIABLE_POSITIONAL_PARAMS
.some(version => VERSION.indexOf(`${version}.`) === 0);
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
import { moduleForComponent, test, skip } from 'ember-qunit';
import Ember from 'ember';
import hbs from 'htmlbars-inline-precompile';

import config from 'dummy/config/environment';
import { hasReliablePositionalParams } from 'dummy/version-checks';

moduleForComponent('print-test-attributes', 'StripTestSelectorsTransform plugin', {
integration: true
});

const { VERSION } = Ember;

const EMBERS_WITHOUT_RELIABLE_POSITIONAL_PARAMS = [
'2.2',
'2.1',
'2.0',
'1.13',
'1.12',
'1.11',
];

const hasReliablePositionalParams = !EMBERS_WITHOUT_RELIABLE_POSITIONAL_PARAMS
.some(version => VERSION.indexOf(`${version}.`) === 0);

if (config.stripTestSelectors) {

(hasReliablePositionalParams ? test : skip)('it strips data-test-* attributes from components with single positional params', function(assert) {
Expand Down
4 changes: 4 additions & 0 deletions transform-test-selector-params-to-hash-pairs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ TransformTestSelectorParamsToHashPairs.prototype.transform = function(ast) {

walker.visit(ast, function(node) {
if (node.type === 'MustacheStatement' || node.type === 'BlockStatement') {
if ('sexpr' in node) {
node = node.sexpr;
}

let testSelectorParams = [];
let otherParams = [];

Expand Down
12 changes: 0 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1969,14 +1969,6 @@ ember-cli@~2.16.1:
walk-sync "^0.3.0"
yam "0.0.22"

ember-compatibility-helpers@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/ember-compatibility-helpers/-/ember-compatibility-helpers-0.1.2.tgz#8eb1769ad761db273fd40242b1170d9f3841d0f0"
dependencies:
babel-plugin-debug-macros "^0.1.11"
ember-cli-version-checker "^2.0.0"
semver "^5.4.1"

ember-disable-prototype-extensions@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/ember-disable-prototype-extensions/-/ember-disable-prototype-extensions-1.1.2.tgz#261cccaf6bf8fbb1836be7bdfe4278f9ab92b873"
Expand Down Expand Up @@ -4362,10 +4354,6 @@ semver@^5.1.0, semver@^5.1.1, semver@^5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"

semver@^5.4.1:
version "5.4.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e"

[email protected]:
version "0.15.3"
resolved "https://registry.yarnpkg.com/send/-/send-0.15.3.tgz#5013f9f99023df50d1bd9892c19e3defd1d53309"
Expand Down

0 comments on commit 1f8dea4

Please sign in to comment.