tests.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. var babel = require("babel-core")
  2. var fs = require("fs")
  3. var path = require("path")
  4. var fixturesDir = path.join(__dirname, "fixtures")
  5. // var inputFilename = path.join(fixturesDir, "input.js")
  6. // var expected = readFile(path.join(fixturesDir, "expected.js"))
  7. var pluginPath = path.join(__dirname, '../../babel-plugin-add-react-displayname')
  8. var assert = require('assert');
  9. describe('add-react-displayname transform', function() {
  10. fs.readdirSync(fixturesDir).forEach(function (fixture) {
  11. var actual = transformFile(path.join(fixturesDir, fixture, 'input.js'))
  12. var expected = readFile((path.join(fixturesDir, fixture, 'expected.js')))
  13. it('transforms ' + path.basename(fixture), function() {
  14. assert.equal(actual, expected)
  15. })
  16. })
  17. });
  18. function readFile(filename) {
  19. var file = fs.readFileSync(filename, "utf8").trim()
  20. file = file.replace(/\r\n/g, "\n");
  21. return file;
  22. }
  23. function transformFile(filename) {
  24. return babel.transformFileSync(filename, {
  25. presets: ['react', 'stage-1'],
  26. plugins: [
  27. [pluginPath, {'knownComponents': ['Component5a', 'Component5b', 'Component5c']}],
  28. 'transform-decorators-legacy',
  29. ]
  30. }).code
  31. }