From 5fad97e5790f9b843a86f6f38b8e28cc96161215 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Wed, 11 Jan 2017 15:18:01 +0100 Subject: [PATCH 1/4] Add "babel-core" and "mocha" dev dependencies --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index d9fb5506..80123d48 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "ember-cli-babel": "^5.1.7" }, "devDependencies": { + "babel-core": "^5.8.38", "broccoli-asset-rev": "^2.4.5", "broccoli-stew": "^1.4.0", "ember-ajax": "^2.4.1", @@ -45,7 +46,8 @@ "ember-load-initializers": "^0.6.3", "ember-resolver": "^2.0.3", "eslint": "^3.12.2", - "loader.js": "^4.0.10" + "loader.js": "^4.0.10", + "mocha": "^3.2.0" }, "engines": { "node": ">= 0.12.0" From ee9dfd0f021e876f74f6f299ef1da318096b5e7f Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Wed, 11 Jan 2017 16:06:48 +0100 Subject: [PATCH 2/4] Add "strip-data-test-properties" Babel 5 plugin --- node-tests/.eslintignore | 1 + node-tests/.eslintrc.js | 5 ++++ node-tests/fixtures/default/expected.js | 17 +++++++++++++ node-tests/fixtures/default/fixture.js | 10 ++++++++ .../strip-data-test-properties-plugin-test.js | 24 +++++++++++++++++++ strip-data-test-properties-plugin.js | 23 ++++++++++++++++++ 6 files changed, 80 insertions(+) create mode 100644 node-tests/.eslintignore create mode 100644 node-tests/.eslintrc.js create mode 100644 node-tests/fixtures/default/expected.js create mode 100644 node-tests/fixtures/default/fixture.js create mode 100644 node-tests/strip-data-test-properties-plugin-test.js create mode 100644 strip-data-test-properties-plugin.js diff --git a/node-tests/.eslintignore b/node-tests/.eslintignore new file mode 100644 index 00000000..116caa12 --- /dev/null +++ b/node-tests/.eslintignore @@ -0,0 +1 @@ +fixtures diff --git a/node-tests/.eslintrc.js b/node-tests/.eslintrc.js new file mode 100644 index 00000000..8b0756b2 --- /dev/null +++ b/node-tests/.eslintrc.js @@ -0,0 +1,5 @@ +module.exports = { + env: { + mocha: true + }, +}; diff --git a/node-tests/fixtures/default/expected.js b/node-tests/fixtures/default/expected.js new file mode 100644 index 00000000..b566bc44 --- /dev/null +++ b/node-tests/fixtures/default/expected.js @@ -0,0 +1,17 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +var _ember = require('ember'); + +var _ember2 = _interopRequireDefault(_ember); + +exports['default'] = _ember2['default'].Component.extend({ + foo: 'foo', + 'data-test': 'test' +}); +module.exports = exports['default']; diff --git a/node-tests/fixtures/default/fixture.js b/node-tests/fixtures/default/fixture.js new file mode 100644 index 00000000..2dbfbc59 --- /dev/null +++ b/node-tests/fixtures/default/fixture.js @@ -0,0 +1,10 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ + foo: 'foo', + 'data-test': 'test', + 'data-test-foo': 'foo', + 'data-test-foobar': Ember.computed('data-test-foo', function() { + return `${this.get('data-test-foo')}bar` + }), +}); diff --git a/node-tests/strip-data-test-properties-plugin-test.js b/node-tests/strip-data-test-properties-plugin-test.js new file mode 100644 index 00000000..20eac368 --- /dev/null +++ b/node-tests/strip-data-test-properties-plugin-test.js @@ -0,0 +1,24 @@ +var fs = require('fs'); +var assert = require('assert'); + +var babel = require('babel-core'); +var StripDataTestPropertiesPlugin = require('../strip-data-test-properties-plugin'); + +function testFixture(name) { + it('fixture: ' + name, function() { + var fixturePath = __dirname + '/fixtures/' + name + '/fixture.js'; + var expectedPath = __dirname + '/fixtures/' + name + '/expected.js'; + + var expected = fs.readFileSync(expectedPath).toString(); + var result = babel.transformFileSync(fixturePath, { + plugins: [StripDataTestPropertiesPlugin], + }); + + assert.strictEqual(result.code.trim(), expected.trim()); + }); +} + +describe('StripDataTestProperties plugin', function() { + testFixture('default'); +}); + diff --git a/strip-data-test-properties-plugin.js b/strip-data-test-properties-plugin.js new file mode 100644 index 00000000..ceb2a91e --- /dev/null +++ b/strip-data-test-properties-plugin.js @@ -0,0 +1,23 @@ +var TEST_SELECTOR_PREFIX = /data-test-.*/; + +function StripDataTestPropertiesPlugin(babel) { + return new babel.Plugin('ember-test-selectors', { + visitor: { + Property: function(node) { + if (TEST_SELECTOR_PREFIX.test(node.key.value)) { + this.dangerouslyRemove(); + } + }, + }, + }); +} + +StripDataTestPropertiesPlugin.baseDir = function() { + return __dirname; +}; + +StripDataTestPropertiesPlugin.cacheKey = function() { + return 'ember-test-selectors.strip-data-test-properties'; +}; + +module.exports = StripDataTestPropertiesPlugin; From 322af609dd86b0d07ef63599680b903a01f6c99a Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Wed, 11 Jan 2017 16:07:05 +0100 Subject: [PATCH 3/4] Add Babel plugin to host apps automatically --- index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/index.js b/index.js index da4535ad..532fbc73 100644 --- a/index.js +++ b/index.js @@ -39,6 +39,22 @@ module.exports = { } }, + included: function(app) { + this._super.included.apply(this, arguments); + + // add the StripDataTestPropertiesPlugin to the list of plugins used by + // the `ember-cli-babel` addon + if (this._stripTestSelectors && !this._registeredWithBabel) { + app.options = app.options || {}; + app.options.babel = app.options.babel || {}; + app.options.babel.plugins = app.options.babel.plugins || []; + + app.options.babel.plugins.push(require('./strip-data-test-properties-plugin')); + + this._registeredWithBabel = true; + } + }, + treeForAddon: function() { // remove our "addon" folder from the build if we're stripping test selectors if (!this._stripTestSelectors) { From 25c58c3e2ff49a158846e059bb2dc9d201d68290 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Wed, 11 Jan 2017 16:40:44 +0100 Subject: [PATCH 4/4] Add "test:node" script and run automatically on CI --- .travis.yml | 1 + package.json | 1 + 2 files changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 3fdd557a..7f5f5599 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,7 @@ script: # Usually, it's ok to finish the test scenario without reverting # to the addon's original dependency state, skipping "cleanup". - npm run test:all -- --skip-cleanup + - npm run test:node - npm run lint notifications: diff --git a/package.json b/package.json index 80123d48..788dde81 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "test": "npm run test:keep && npm run test:strip", "test:all": "ember try:each", "test:keep": "ember test", + "test:node": "mocha node-tests", "test:strip": "STRIP_TEST_SELECTORS=true ember test" }, "dependencies": {