From e10f9e36c39e9d4bb25b3e4024e815aca4d7386d Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Tue, 3 Jan 2017 14:55:05 +0100 Subject: [PATCH 1/2] ember-cli-build: Remove "StripTestSelectorsTransform" from registry This will be added automatically be the addon itself --- ember-cli-build.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/ember-cli-build.js b/ember-cli-build.js index bc7ba562..0edfc297 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -1,7 +1,6 @@ /*jshint node:true*/ /* global require, module */ var EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); -var StripTestSelectorsTransform = require('./strip-test-selectors'); module.exports = function(defaults) { var app = new EmberAddon(defaults, { @@ -10,14 +9,5 @@ module.exports = function(defaults) { } }); - // add the StripTestSelectorsTransform to the registry, so the dummy app has - // it added in the HTMLBars build pipeline: all data-test-* attributes are - // therefore stripped - app.registry.add('htmlbars-ast-plugin', { - name: 'strip-test-selectors', - plugin: StripTestSelectorsTransform, - baseDir: function() { return __dirname; } - }); - return app.toTree(); }; From 47d1161179a3621a01c063365950c1e1a66bbc7f Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Tue, 3 Jan 2017 15:06:04 +0100 Subject: [PATCH 2/2] Run tests with and without stripping test selectors --- config/ember-try.js | 1 + ember-cli-build.js | 5 +- package.json | 5 +- tests/dummy/config/environment.js | 4 +- .../strip-data-test-attributes-test.js | 69 +++++++++++-------- 5 files changed, 54 insertions(+), 30 deletions(-) diff --git a/config/ember-try.js b/config/ember-try.js index f5a25f4c..88854232 100644 --- a/config/ember-try.js +++ b/config/ember-try.js @@ -1,5 +1,6 @@ /*jshint node:true*/ module.exports = { + command: 'npm run test:both', useVersionCompatibility: true, scenarios: [ { diff --git a/ember-cli-build.js b/ember-cli-build.js index 0edfc297..decad7e2 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -3,9 +3,12 @@ var EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); module.exports = function(defaults) { + var stripTestSelectors = process.env['STRIP_TEST_SELECTORS']; + var environments = stripTestSelectors ? ['test'] : ['production']; + var app = new EmberAddon(defaults, { 'ember-test-selectors': { - environments: ['test'] + environments: environments } }); diff --git a/package.json b/package.json index 3c37b08c..85ee2b33 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,10 @@ "build": "ember build", "lint": "eslint config test-support tests *.js", "start": "ember server", - "test": "ember try:each" + "test": "ember try:each", + "test:both": "npm run test:keep && npm run test:strip", + "test:keep": "ember test", + "test:strip": "STRIP_TEST_SELECTORS=true ember test" }, "dependencies": { "ember-cli-babel": "^5.1.7", diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js index 7ab9db81..49bc0ec6 100644 --- a/tests/dummy/config/environment.js +++ b/tests/dummy/config/environment.js @@ -20,7 +20,9 @@ module.exports = function(environment) { APP: { // Here you can pass flags/options to your application instance // when it is created - } + }, + + stripTestSelectors: process.env['STRIP_TEST_SELECTORS'] }; if (environment === 'development') { diff --git a/tests/integration/strip-data-test-attributes-test.js b/tests/integration/strip-data-test-attributes-test.js index 001d97bc..4762a845 100644 --- a/tests/integration/strip-data-test-attributes-test.js +++ b/tests/integration/strip-data-test-attributes-test.js @@ -1,43 +1,58 @@ import { moduleForComponent, test } from "ember-qunit"; import hbs from "htmlbars-inline-precompile"; +import config from 'dummy/config/environment'; + moduleForComponent('data-test', 'StripTestSelectorsTransform plugin', { integration: true }); -test('it strips data-test-* attributes', function(assert) { - this.render(hbs``); +if (config.stripTestSelectors) { - assert.equal(this.$('span').length, 1, 'the span is present'); - assert.equal(this.$('span[data-test-id="my-id"]').length, 0, 'data-test-id is stripped'); -}); + test('it strips data-test-* attributes', function (assert) { + this.render(hbs``); -test('it works with multiple data-test-* attributes', function(assert) { - this.render(hbs``); + assert.equal(this.$('span').length, 1, 'the span is present'); + assert.equal(this.$('span[data-test-id="my-id"]').length, 0, 'data-test-id is stripped'); + }); - assert.equal(this.$('span').length, 1, 'the span is present'); - assert.equal(this.$('span[data-test-first]').length, 0, 'data-test-first is stripped'); - assert.equal(this.$('span[data-test-second="second-id"]').length, 0, 'data-test-second is stripped'); -}); + test('it works with multiple data-test-* attributes', function (assert) { + this.render(hbs``); -test('it leaves other data attributes untouched, when a data-test-* attribute is present as well', function(assert) { - this.render(hbs``); + assert.equal(this.$('span').length, 1, 'the span is present'); + assert.equal(this.$('span[data-test-first]').length, 0, 'data-test-first is stripped'); + assert.equal(this.$('span[data-test-second="second-id"]').length, 0, 'data-test-second is stripped'); + }); - assert.equal(this.$('span').length, 1, 'the span is present'); - assert.equal(this.$('span[data-id="my-id"]').length, 1, 'data-id is not stripped'); - assert.equal(this.$('span[data-test-id="my-test-id"]').length, 0, 'data-test-id is stripped'); -}); + test('it leaves other data attributes untouched, when a data-test-* attribute is present as well', function (assert) { + this.render(hbs``); -test('it leaves data-test attributes untouched', function(assert) { - this.render(hbs``); + assert.equal(this.$('span').length, 1, 'the span is present'); + assert.equal(this.$('span[data-id="my-id"]').length, 1, 'data-id is not stripped'); + assert.equal(this.$('span[data-test-id="my-test-id"]').length, 0, 'data-test-id is stripped'); + }); - assert.equal(this.$('span').length, 1, 'the span is present'); - assert.equal(this.$('span[data-test="my-id"]').length, 1, 'data-test-id is not stripped'); -}); + test('it leaves data-test attributes untouched', function (assert) { + this.render(hbs``); -test('it leaves other data attributes untouched', function(assert) { - this.render(hbs``); + assert.equal(this.$('span').length, 1, 'the span is present'); + assert.equal(this.$('span[data-test="my-id"]').length, 1, 'data-test-id is not stripped'); + }); - assert.equal(this.$('span').length, 1, 'the span is present'); - assert.equal(this.$('span[data-id="my-id"]').length, 1, 'data-id is not stripped'); -}); + test('it leaves other data attributes untouched', function (assert) { + this.render(hbs``); + + assert.equal(this.$('span').length, 1, 'the span is present'); + assert.equal(this.$('span[data-id="my-id"]').length, 1, 'data-id is not stripped'); + }); + +} else { + + test('it does not strip data-test-* attributes', function (assert) { + this.render(hbs``); + + assert.equal(this.$('span').length, 1, 'the span is present'); + assert.equal(this.$('span[data-test-id="my-id"]').length, 1, 'data-test-id is not stripped'); + }); + +}