Skip to content

Commit

Permalink
Fixed useBuiltIns and modules validation when using 'false' as option (
Browse files Browse the repository at this point in the history
…#11373)

* Fixed useBuiltIns and modules validation when using 'false' as option

* Added tests for 'validateUseBuiltInsOptions' and for 'validateModulesOption' when input is 'false'

Co-authored-by: Jovica Markoski <jovica@upshiftwork.com>
  • Loading branch information
JMarkoski and Jovica Markoski committed Apr 3, 2020
1 parent 2c31587 commit 40db926
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/babel-preset-env/src/normalize-options.js
Expand Up @@ -167,8 +167,7 @@ export const validateModulesOption = (
modulesOpt: ModuleOption = ModulesOption.auto,
) => {
invariant(
ModulesOption[modulesOpt.toString()] ||
ModulesOption[modulesOpt.toString()] === ModulesOption.false,
ModulesOption[modulesOpt.toString()] || modulesOpt === ModulesOption.false,
`Invalid Option: The 'modules' option must be one of \n` +
` - 'false' to indicate no module processing\n` +
` - a specific module type: 'commonjs', 'amd', 'umd', 'systemjs'` +
Expand All @@ -184,7 +183,7 @@ export const validateUseBuiltInsOption = (
) => {
invariant(
UseBuiltInsOption[builtInsOpt.toString()] ||
UseBuiltInsOption[builtInsOpt.toString()] === UseBuiltInsOption.false,
builtInsOpt === UseBuiltInsOption.false,
`Invalid Option: The 'useBuiltIns' option must be either
'false' (default) to indicate no polyfill,
'"entry"' to indicate replacing the entry polyfill, or
Expand Down
27 changes: 27 additions & 0 deletions packages/babel-preset-env/test/normalize-options.spec.js
Expand Up @@ -6,6 +6,7 @@ const {
checkDuplicateIncludeExcludes,
validateBoolOption,
validateModulesOption,
validateUseBuiltInsOption,
normalizePluginName,
} = normalizeOptions;
describe("normalize-options", () => {
Expand Down Expand Up @@ -242,10 +243,36 @@ describe("normalize-options", () => {
}).toThrow();
});

it("`'false'` option is invalid", () => {
expect(() => {
validateModulesOption("false");
}).toThrow();
});

it("array option is invalid", () => {
expect(() => {
validateModulesOption([]);
}).toThrow();
});
});

describe("validateUseBuiltInsOptions", () => {
it("usage option is valid", () => {
expect(validateUseBuiltInsOption("usage")).toBe("usage");
});

it("entry option is valid", () => {
expect(validateUseBuiltInsOption("entry")).toBe("entry");
});

it("`false` option returns false", () => {
expect(validateUseBuiltInsOption(false)).toBe(false);
});

it("`'false'` option is invalid", () => {
expect(() => {
validateUseBuiltInsOption("false");
}).toThrow();
});
});
});

0 comments on commit 40db926

Please sign in to comment.