From 49da681712f5b277f493665cc2c0e39eb8db20c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Thu, 5 Dec 2019 14:32:41 -0500 Subject: [PATCH] chore: copy preset-env-standalone test --- packages/babel-standalone/test/babel.js | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/packages/babel-standalone/test/babel.js b/packages/babel-standalone/test/babel.js index 056bfafca847..8fd2b8a60d56 100644 --- a/packages/babel-standalone/test/babel.js +++ b/packages/babel-standalone/test/babel.js @@ -110,6 +110,61 @@ ).toThrow(/Invalid plugin specified in Babel options: "lolfail"/); }); + describe("env preset", () => { + it("works w/o targets", () => { + const output = Babel.transform("const a = 1;", { + sourceType: "script", + presets: ["env"], + }).code; + expect(output).toBe("var a = 1;"); + }); + + it("doesn't transpile `const` with chrome 60", () => { + const output = Babel.transform("const a = 1;", { + sourceType: "script", + presets: [ + [ + "env", + { + targets: { + chrome: 60, + }, + }, + ], + ], + }).code; + expect(output).toBe("const a = 1;"); + }); + + it("transpiles `const` with chrome 60 and preset-es2015", () => { + const output = Babel.transform("const a = 1;", { + sourceType: "script", + presets: [ + [ + "env", + { + targets: { + chrome: 60, + }, + }, + ], + "es2015", + ], + }).code; + expect(output).toBe("var a = 1;"); + }); + + it("uses transform-new-targets plugin", () => { + const output = Babel.transform("function Foo() {new.target}", { + sourceType: "script", + presets: ["env"], + }).code; + expect(output).toBe( + "function Foo() {\n this instanceof Foo ? this.constructor : void 0;\n}", + ); + }); + }); + describe("custom plugins and presets", () => { const lolizer = () => ({ visitor: {