From c548e789bbe61182a4bbe720ee7edafbb1ccd783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Tue, 19 Mar 2019 23:35:13 +0100 Subject: [PATCH] Bring back isPluginRequired (#9709) --- packages/babel-preset-env/src/index.js | 2 + .../test/filter-items.spec.js | 84 ------------------- .../test/is-plugin-required.js | 82 ++++++++++++++++++ 3 files changed, 84 insertions(+), 84 deletions(-) delete mode 100644 packages/babel-preset-env/test/filter-items.spec.js create mode 100644 packages/babel-preset-env/test/is-plugin-required.js diff --git a/packages/babel-preset-env/src/index.js b/packages/babel-preset-env/src/index.js index 426ad47cc2..a31f8b9897 100644 --- a/packages/babel-preset-env/src/index.js +++ b/packages/babel-preset-env/src/index.js @@ -20,6 +20,8 @@ import availablePlugins from "./available-plugins"; import { filterStageFromList, prettifyTargets } from "./utils"; import { declare } from "@babel/helper-plugin-utils"; +export { isPluginRequired } from "./filter-items"; + const pluginListWithoutProposals = filterStageFromList( pluginList, proposalPlugins, diff --git a/packages/babel-preset-env/test/filter-items.spec.js b/packages/babel-preset-env/test/filter-items.spec.js deleted file mode 100644 index 6488e03d03..0000000000 --- a/packages/babel-preset-env/test/filter-items.spec.js +++ /dev/null @@ -1,84 +0,0 @@ -"use strict"; - -const filterItems = require("../lib/filter-items"); - -describe("filter-items", () => { - describe("isPluginRequired", () => { - const MAX_VERSION = `${Number.MAX_SAFE_INTEGER}.0.0`; - - it("returns true if no targets are specified", () => { - expect(filterItems.isPluginRequired({}, {})).toBe(true); - }); - - it("returns true if plugin feature is not implemented in one or more targets", () => { - let targets; - const plugin = { - edge: false, - firefox: 45, - chrome: 49, - }; - - targets = { - chrome: MAX_VERSION, - firefox: MAX_VERSION, - }; - expect(filterItems.isPluginRequired(targets, plugin)).toBe(false); - - targets = { - edge: "12", - }; - expect(filterItems.isPluginRequired(targets, plugin)).toBe(true); - }); - - it("returns false if plugin feature is implemented by lower than target", () => { - const plugin = { - chrome: 49, - }; - const targets = { - chrome: MAX_VERSION, - }; - - expect(filterItems.isPluginRequired(targets, plugin)).toBe(false); - }); - - it("returns false if plugin feature is implemented is equal to target", () => { - const plugin = { - chrome: 49, - }; - const targets = { - chrome: "49.0.0", - }; - expect(filterItems.isPluginRequired(targets, plugin)).toBe(false); - }); - - it("returns true if plugin feature is implemented is greater than target", () => { - const plugin = { - chrome: 50, - }; - const targets = { - chrome: "49.0.0", - }; - expect(filterItems.isPluginRequired(targets, plugin)).toBe(true); - }); - - it("returns when target is a decimal", () => { - const plugin = { - node: 6.9, - }; - const targets = { - node: "6.10.0", - }; - expect(filterItems.isPluginRequired(targets, plugin)).toBe(false); - }); - - it("throws an error if target version is invalid", () => { - const plugin = { - chrome: 50, - }; - const targets = { - chrome: 55, - }; - expect(() => filterItems.isPluginRequired(targets, plugin)).toThrow(); - }); - }); -}); diff --git a/packages/babel-preset-env/test/is-plugin-required.js b/packages/babel-preset-env/test/is-plugin-required.js new file mode 100644 index 0000000000..be999b7c98 --- /dev/null +++ b/packages/babel-preset-env/test/is-plugin-required.js @@ -0,0 +1,82 @@ +"use strict"; + +const presetEnv = require("../"); + +describe("isPluginRequired", () => { + const MAX_VERSION = `${Number.MAX_SAFE_INTEGER}.0.0`; + + it("returns true if no targets are specified", () => { + expect(presetEnv.isPluginRequired({}, {})).toBe(true); + }); + + it("returns true if plugin feature is not implemented in one or more targets", () => { + let targets; + const plugin = { + edge: false, + firefox: 45, + chrome: 49, + }; + + targets = { + chrome: MAX_VERSION, + firefox: MAX_VERSION, + }; + expect(presetEnv.isPluginRequired(targets, plugin)).toBe(false); + + targets = { + edge: "12", + }; + expect(presetEnv.isPluginRequired(targets, plugin)).toBe(true); + }); + + it("returns false if plugin feature is implemented by lower than target", () => { + const plugin = { + chrome: 49, + }; + const targets = { + chrome: MAX_VERSION, + }; + + expect(presetEnv.isPluginRequired(targets, plugin)).toBe(false); + }); + + it("returns false if plugin feature is implemented is equal to target", () => { + const plugin = { + chrome: 49, + }; + const targets = { + chrome: "49.0.0", + }; + expect(presetEnv.isPluginRequired(targets, plugin)).toBe(false); + }); + + it("returns true if plugin feature is implemented is greater than target", () => { + const plugin = { + chrome: 50, + }; + const targets = { + chrome: "49.0.0", + }; + expect(presetEnv.isPluginRequired(targets, plugin)).toBe(true); + }); + + it("returns when target is a decimal", () => { + const plugin = { + node: 6.9, + }; + const targets = { + node: "6.10.0", + }; + expect(presetEnv.isPluginRequired(targets, plugin)).toBe(false); + }); + + it("throws an error if target version is invalid", () => { + const plugin = { + chrome: 50, + }; + const targets = { + chrome: 55, + }; + expect(() => presetEnv.isPluginRequired(targets, plugin)).toThrow(); + }); +});