Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Babel 6 compatibility #86

Merged
merged 3 commits into from
Mar 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# dependencies
/node_modules
/bower_components
/node-tests/multidep_modules

# misc
/.sass-cache
Expand Down
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

/* eslint-env node */

const VersionChecker = require('ember-cli-version-checker');

module.exports = {
name: 'ember-test-selectors',

Expand Down Expand Up @@ -54,11 +56,20 @@ module.exports = {
// add the StripDataTestPropertiesPlugin to the list of plugins used by
// the `ember-cli-babel` addon
if (this._stripTestSelectors && !this._registeredWithBabel) {
let checker = new VersionChecker(this).for('ember-cli-babel', 'npm');

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'));
if (checker.satisfies('^5.0.0')) {
app.options.babel.plugins.push(require('./strip-data-test-properties-plugin'));
} else if (checker.satisfies('^6.0.0-beta.1')) {
app.options.babel.plugins.push(require('./strip-data-test-properties-plugin6'));
} else {
this.ui.writeWarnLine('ember-test-selectors: You are using an unsupported ember-cli-babel version. data-test ' +
'properties are not automatically stripped from your JS code.');
}

this._registeredWithBabel = true;
}
Expand Down
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'
});
6 changes: 6 additions & 0 deletions node-tests/multidep.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"path": "node-tests/multidep_modules",
"versions": {
"babel-core": ["5.8.33", "6.24.0"]
}
}
27 changes: 22 additions & 5 deletions node-tests/strip-data-test-properties-plugin-test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
var fs = require('fs');
var assert = require('assert');
var multidepRequire = require('multidep')('node-tests/multidep.json');

var babel = require('babel-core');
var StripDataTestPropertiesPlugin = require('../strip-data-test-properties-plugin');
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';

var expected = fs.readFileSync(expectedPath).toString();
var result = babel.transformFileSync(fixturePath, {
plugins: [StripDataTestPropertiesPlugin],
var result = babel5.transformFileSync(fixturePath, {
plugins: [StripDataTestPropertiesPlugin5],
});

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());
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
"test": "npm run test:keep && npm run test:strip",
"test:all": "ember try:each",
"test:keep": "ember test",
"pretest:node": "multidep node-tests/multidep.json",
"test:node": "mocha node-tests",
"test:strip": "STRIP_TEST_SELECTORS=true ember test"
},
"dependencies": {
"ember-cli-babel": "^5.1.7"
"ember-cli-babel": "^5.1.7",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably bump to ^6.0.0-beta.9 so that the addons own files are compiled with babel 6. That can definitely be done separately though...

"ember-cli-version-checker": "^1.2.0"
},
"devDependencies": {
"broccoli-asset-rev": "^2.4.5",
Expand All @@ -48,7 +50,8 @@
"eslint-plugin-ember": "^3.0.1",
"eslint-plugin-qunit": "^2.3.0",
"loader.js": "^4.0.10",
"mocha": "^3.2.0"
"mocha": "^3.2.0",
"multidep": "^2.0.2"
},
"engines": {
"node": ">= 4"
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() {
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;