index.test.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. "use strict";
  2. const transform = require("./index").transform;
  3. const transformations = require("./index").transformations;
  4. const input = `
  5. module.exports = {
  6. devtool: 'eval',
  7. entry: [
  8. './src/index'
  9. ],
  10. output: {
  11. path: path.join(__dirname, 'dist'),
  12. filename: 'index.js'
  13. },
  14. module: {
  15. loaders: [{
  16. test: /.js$/,
  17. loaders: ['babel'],
  18. include: path.join(__dirname, 'src')
  19. }]
  20. },
  21. resolve: {
  22. root: path.resolve('/src'),
  23. modules: ['node_modules']
  24. },
  25. plugins: [
  26. new webpack.optimize.UglifyJsPlugin(),
  27. new webpack.optimize.OccurrenceOrderPlugin()
  28. ],
  29. debug: true
  30. };
  31. `;
  32. describe("transform", () => {
  33. it("should not transform if no transformations defined", done => {
  34. transform(input, []).then(output => {
  35. expect(output).toMatchSnapshot(input);
  36. done();
  37. });
  38. });
  39. it("should transform using all transformations", done => {
  40. transform(input).then(output => {
  41. expect(output).toMatchSnapshot();
  42. done();
  43. });
  44. });
  45. it("should transform only using specified transformations", done => {
  46. transform(input, [transformations.loadersTransform]).then(output => {
  47. expect(output).toMatchSnapshot();
  48. done();
  49. });
  50. });
  51. it("should respect recast options", done => {
  52. transform(input, undefined, {
  53. quote: "double",
  54. trailingComma: true
  55. }).then(output => {
  56. expect(output).toMatchSnapshot();
  57. done();
  58. });
  59. });
  60. });