Skip to content

Commit

Permalink
Port "strip-data-test-properties-plugin" to Babel 6
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Mar 27, 2017
1 parent 8d4235b commit 993229b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
6 changes: 6 additions & 0 deletions node-tests/fixtures/default/expected6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Ember from 'ember';

export default Ember.Component.extend({
foo: 'foo',
'data-test': 'test'
});
2 changes: 1 addition & 1 deletion node-tests/multidep.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"path": "node-tests/multidep_modules",
"versions": {
"babel-core": ["5.8.33"]
"babel-core": ["5.8.33", "6.24.0"]
}
}
18 changes: 17 additions & 1 deletion node-tests/strip-data-test-properties-plugin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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() {
Expand Down
27 changes: 27 additions & 0 deletions strip-data-test-properties-plugin6.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 993229b

Please sign in to comment.