index.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import * as babel from "@babel/core";
  2. import es2015 from "../lib";
  3. function transform(code, opts) {
  4. return babel.transform(code, {
  5. cwd: __dirname,
  6. ...opts,
  7. });
  8. }
  9. describe("es2015 preset", function() {
  10. it("does throw clear error when no options passed for Babel 6", () => {
  11. expect(function() {
  12. es2015({ version: "6.5.0" });
  13. }).toThrow(Error, /Requires Babel "\^7.0.0-0"/);
  14. });
  15. describe("options", function() {
  16. describe("loose", function() {
  17. it("throws on non-boolean value", function() {
  18. expect(function() {
  19. transform("", { presets: [[es2015, { loose: 1 }]] });
  20. }).toThrow(/must be a boolean/);
  21. });
  22. });
  23. describe("spec", function() {
  24. it("throws on non-boolean value", function() {
  25. expect(function() {
  26. transform("", { presets: [[es2015, { spec: 1 }]] });
  27. }).toThrow(/must be a boolean/);
  28. });
  29. });
  30. describe("modules", function() {
  31. it("doesn't throw when passing one false", function() {
  32. expect(function() {
  33. transform("", { presets: [[es2015, { modules: false }]] });
  34. }).not.toThrow();
  35. });
  36. it("doesn't throw when passing one of: 'commonjs', 'amd', 'umd', 'systemjs", function() {
  37. expect(function() {
  38. transform("", { presets: [[es2015, { modules: "commonjs" }]] });
  39. }).not.toThrow();
  40. expect(function() {
  41. transform("", { presets: [[es2015, { modules: "amd" }]] });
  42. }).not.toThrow();
  43. expect(function() {
  44. transform("", { presets: [[es2015, { modules: "umd" }]] });
  45. }).not.toThrow();
  46. expect(function() {
  47. transform("", { presets: [[es2015, { modules: "systemjs" }]] });
  48. }).not.toThrow();
  49. });
  50. it("throws when passing neither false nor one of: 'commonjs', 'amd', 'umd', 'systemjs'", function() {
  51. expect(function() {
  52. transform("", { presets: [[es2015, { modules: 1 }]] });
  53. }).toThrow();
  54. });
  55. });
  56. });
  57. });