Skip to content

Commit

Permalink
Bring back isPluginRequired (#9709)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Mar 19, 2019
1 parent 8476cf6 commit c548e78
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 84 deletions.
2 changes: 2 additions & 0 deletions packages/babel-preset-env/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
84 changes: 0 additions & 84 deletions packages/babel-preset-env/test/filter-items.spec.js

This file was deleted.

82 changes: 82 additions & 0 deletions packages/babel-preset-env/test/is-plugin-required.js
Original file line number Diff line number Diff line change
@@ -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();
});
});

0 comments on commit c548e78

Please sign in to comment.