diff --git a/package.json b/package.json index 7ab855c..e098e5f 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,9 @@ "babel-core": "^6.14.0", "babel-helper-plugin-test-runner": "^6.8.0", "babel-plugin-transform-decorators-legacy": "^1.3.4", + "babel-plugin-transform-inline-environment-variables": "^0.1.1", + "babel-plugin-transform-react-constant-elements": "^6.23.0", + "babel-plugin-transform-react-inline-elements": "^6.22.0", "babel-preset-react": "^6.24.1", "babel-preset-stage-0": "^6.16.0", "mocha": "^3.0.2", @@ -25,5 +28,11 @@ "bugs": { "url": "https://github.com/opbeat/babel-plugin-add-react-displayname/issues" }, - "homepage": "https://github.com/opbeat/babel-plugin-add-react-displayname#readme" + "homepage": "https://github.com/opbeat/babel-plugin-add-react-displayname#readme", + "standard": { + "globals": [ + "describe", + "it" + ] + } } diff --git a/test/fixtures/arrowFun/expected-inline.js b/test/fixtures/arrowFun/expected-inline.js new file mode 100644 index 0000000..c2bf559 --- /dev/null +++ b/test/fixtures/arrowFun/expected-inline.js @@ -0,0 +1,7 @@ +var _jsx = function () { var REACT_ELEMENT_TYPE = typeof Symbol === "function" && Symbol.for && Symbol.for("react.element") || 0xeac7; return function createRawReactElement(type, props, key, children) { var defaultProps = type && type.defaultProps; var childrenLength = arguments.length - 3; if (!props && childrenLength !== 0) { props = {}; } if (props && defaultProps) { for (var propName in defaultProps) { if (props[propName] === void 0) { props[propName] = defaultProps[propName]; } } } else if (!props) { props = defaultProps || {}; } if (childrenLength === 1) { props.children = children; } else if (childrenLength > 1) { var childArray = Array(childrenLength); for (var i = 0; i < childrenLength; i++) { childArray[i] = arguments[i + 3]; } props.children = childArray; } return { $$typeof: REACT_ELEMENT_TYPE, type: type, key: key === undefined ? null : '' + key, ref: null, props: props, _owner: null }; }; }(); + +// Stateless componenet with an arrow function +var Component2 = ({ value }) => { + return _jsx("div", {}, void 0, value); +}; +Component2.displayName = "Component2"; \ No newline at end of file diff --git a/test/tests.js b/test/tests.js index 1e56da5..ede8e8f 100644 --- a/test/tests.js +++ b/test/tests.js @@ -1,38 +1,50 @@ -var babel = require("babel-core") -var fs = require("fs") -var path = require("path") -var fixturesDir = path.join(__dirname, "fixtures") +var babel = require('babel-core') +var fs = require('fs') +var path = require('path') +var fixturesDir = path.join(__dirname, 'fixtures') // var inputFilename = path.join(fixturesDir, "input.js") // var expected = readFile(path.join(fixturesDir, "expected.js")) - var pluginPath = path.join(__dirname, '../../babel-plugin-add-react-displayname') -var assert = require('assert'); -describe('add-react-displayname transform', function() { - +var assert = require('assert') +describe('add-react-displayname transform', function () { fs.readdirSync(fixturesDir).forEach(function (fixture) { var actual = transformFile(path.join(fixturesDir, fixture, 'input.js')) var expected = readFile((path.join(fixturesDir, fixture, 'expected.js'))) - it('transforms ' + path.basename(fixture), function() { + it('transforms ' + path.basename(fixture), function () { assert.equal(actual, expected) }) }) -}); -function readFile(filename) { - var file = fs.readFileSync(filename, "utf8").trim() - file = file.replace(/\r\n/g, "\n"); - return file; + it('should work with other plugins', function () { + var actual = transformFile(path.join(fixturesDir, 'arrowFun', 'input.js'), + ['transform-react-inline-elements', + 'transform-react-constant-elements', + 'transform-inline-environment-variables']) + var expected = readFile((path.join(fixturesDir, 'arrowFun', 'expected-inline.js'))) + + assert.equal(actual, expected) + }) +}) + +function readFile (filename) { + var file = fs.readFileSync(filename, 'utf8').trim() + file = file.replace(/\r\n/g, '\n') + return file } -function transformFile(filename) { +function transformFile (filename, testPlugins) { + var plugins = [ + [pluginPath, {'knownComponents': ['Component5a', 'Component5b', 'Component5c']}], + 'transform-decorators-legacy' + ] + if (testPlugins) { + plugins = plugins.concat(testPlugins) + } return babel.transformFileSync(filename, { presets: ['react', 'stage-1'], - plugins: [ - [pluginPath, {'knownComponents': ['Component5a', 'Component5b', 'Component5c']}], - 'transform-decorators-legacy', - ] + plugins: plugins }).code }