babel-preset-env.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. (process.env.TEST_TYPE === "cov" ? describe.skip : describe)(
  2. "babel-preset-env-standalone",
  3. () => {
  4. const Babel = require("@babel/standalone/babel");
  5. jest.mock("Babel", () => require("@babel/standalone/babel"), {
  6. virtual: true,
  7. });
  8. require("../babel-preset-env");
  9. it("works w/o targets", () => {
  10. const output = Babel.transform("const a = 1;", {
  11. sourceType: "script",
  12. presets: ["env"],
  13. }).code;
  14. expect(output).toBe("var a = 1;");
  15. });
  16. it("doesn't transpile `const` with chrome 60", () => {
  17. const output = Babel.transform("const a = 1;", {
  18. sourceType: "script",
  19. presets: [
  20. [
  21. "env",
  22. {
  23. targets: {
  24. chrome: 60,
  25. },
  26. },
  27. ],
  28. ],
  29. }).code;
  30. expect(output).toBe("const a = 1;");
  31. });
  32. it("transpiles `const` with chrome 60 and preset-es2015", () => {
  33. const output = Babel.transform("const a = 1;", {
  34. sourceType: "script",
  35. presets: [
  36. [
  37. "env",
  38. {
  39. targets: {
  40. chrome: 60,
  41. },
  42. },
  43. ],
  44. "es2015",
  45. ],
  46. }).code;
  47. expect(output).toBe("var a = 1;");
  48. });
  49. it("uses transform-new-targets plugin", () => {
  50. const output = Babel.transform("function Foo() {new.target}", {
  51. sourceType: "script",
  52. presets: ["env"],
  53. }).code;
  54. expect(output).toBe(
  55. "function Foo() {\n this instanceof Foo ? this.constructor : void 0;\n}",
  56. );
  57. });
  58. },
  59. );