From 993229bfb0519ac11fbad3aa69217aa9f907dc20 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 27 Mar 2017 11:45:30 -0700 Subject: [PATCH] Port "strip-data-test-properties-plugin" to Babel 6 --- node-tests/fixtures/default/expected6.js | 6 +++++ node-tests/multidep.json | 2 +- .../strip-data-test-properties-plugin-test.js | 18 ++++++++++++- strip-data-test-properties-plugin6.js | 27 +++++++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 node-tests/fixtures/default/expected6.js create mode 100644 strip-data-test-properties-plugin6.js diff --git a/node-tests/fixtures/default/expected6.js b/node-tests/fixtures/default/expected6.js new file mode 100644 index 00000000..06b896fa --- /dev/null +++ b/node-tests/fixtures/default/expected6.js @@ -0,0 +1,6 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ + foo: 'foo', + 'data-test': 'test' +}); diff --git a/node-tests/multidep.json b/node-tests/multidep.json index 0e8d835c..819af88d 100644 --- a/node-tests/multidep.json +++ b/node-tests/multidep.json @@ -1,6 +1,6 @@ { "path": "node-tests/multidep_modules", "versions": { - "babel-core": ["5.8.33"] + "babel-core": ["5.8.33", "6.24.0"] } } diff --git a/node-tests/strip-data-test-properties-plugin-test.js b/node-tests/strip-data-test-properties-plugin-test.js index 5e31af07..295d67ff 100644 --- a/node-tests/strip-data-test-properties-plugin-test.js +++ b/node-tests/strip-data-test-properties-plugin-test.js @@ -3,10 +3,13 @@ var assert = require('assert'); var multidepRequire = require('multidep')('node-tests/multidep.json'); var babel5 = multidepRequire('babel-core', '5.8.33'); +var babel6 = multidepRequire('babel-core', '6.24.0'); + var StripDataTestPropertiesPlugin5 = require('../strip-data-test-properties-plugin'); +var StripDataTestPropertiesPlugin6 = require('../strip-data-test-properties-plugin6'); function testFixture(name) { - it('fixture: ' + name, function() { + it('Babel5: fixture: ' + name, function() { var fixturePath = __dirname + '/fixtures/' + name + '/fixture.js'; var expectedPath = __dirname + '/fixtures/' + name + '/expected.js'; @@ -17,6 +20,19 @@ function testFixture(name) { assert.strictEqual(result.code.trim(), expected.trim()); }); + + it('Babel6: fixture: ' + name, function() { + var fixturePath = __dirname + '/fixtures/' + name + '/fixture.js'; + var expectedPath = __dirname + '/fixtures/' + name + '/expected6.js'; + + var expected = fs.readFileSync(expectedPath).toString(); + + var result = babel6.transformFileSync(fixturePath, { + plugins: [StripDataTestPropertiesPlugin6], + }); + + assert.strictEqual(result.code.trim(), expected.trim()); + }); } describe('StripDataTestProperties plugin', function() { diff --git a/strip-data-test-properties-plugin6.js b/strip-data-test-properties-plugin6.js new file mode 100644 index 00000000..fc0259c5 --- /dev/null +++ b/strip-data-test-properties-plugin6.js @@ -0,0 +1,27 @@ +'use strict'; + +/* eslint-env node */ + +let TEST_SELECTOR_PREFIX = /data-test-.*/; + +function StripDataTestPropertiesPlugin(babel) { + return { + visitor: { + Property(path) { + if (TEST_SELECTOR_PREFIX.test(path.node.key.value)) { + path.remove(); + } + }, + }, + }; +} + +StripDataTestPropertiesPlugin.baseDir = function() { + return __dirname; +}; + +StripDataTestPropertiesPlugin.cacheKey = function() { + return 'ember-test-selectors.strip-data-test-properties'; +}; + +module.exports = StripDataTestPropertiesPlugin;