polish: throw human-friendly error when item-option pair is in… (#10969)

* polish: throw human-friendly error when item-option pair is incorrectly unwrapped

* add testcase for plugin

* fix: exclude false positive

* fix: validate should support plugin optionsSourceKind

* Revert "fix: validate should support plugin optionsSourceKind"

* fix: validate plugin object in assertNoUnwrappedItemOptionPairs

* fix flow error

* update test fixtures

* refactor: move to loadDescriptor catch clause

* chore: throw Error instead of builtin ReferenceError

* fix flow errors

* chore: add more test cases
This commit is contained in:
Huáng Jùnliàng
2020-01-20 15:05:07 -05:00
committed by Nicolò Ribaudo
parent 43b23e0869
commit fa975bf7cd
7 changed files with 164 additions and 14 deletions

View File

@@ -0,0 +1,34 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`option-manager config plugin/preset flattening and overriding should throw when an option is following a preset 1`] = `
"[BABEL] unknown: Unknown option: .useSpread. Check out https://babeljs.io/docs/en/babel-core/#options for more information about options.
- Maybe you meant to use
\\"preset\\": [
[\\"./fixtures/option-manager/babel-preset-bar\\", {
\\"useSpread\\": true
}]
]
To be a valid preset, its name and options should be wrapped in a pair of brackets"
`;
exports[`option-manager config plugin/preset flattening and overriding should throw when an option is provided as a plugin 1`] = `
"[BABEL] unknown: .useSpread is not a valid Plugin property
- Maybe you meant to use
\\"plugin\\": [
[\\"./fixtures/option-manager/babel-plugin-foo\\", {
\\"useSpread\\": true
}]
]
To be a valid plugin, its name and options should be wrapped in a pair of brackets"
`;
exports[`option-manager config plugin/preset flattening and overriding should throw when an option is provided as a preset 1`] = `
"[BABEL] unknown: Unknown option: .useBuiltIns. Check out https://babeljs.io/docs/en/babel-core/#options for more information about options.
- Maybe you meant to use
\\"preset\\": [
[\\"./fixtures/option-manager/babel-preset-bar\\", {
\\"useBuiltIns\\": \\"entry\\"
}]
]
To be a valid preset, its name and options should be wrapped in a pair of brackets"
`;

View File

@@ -0,0 +1 @@
module.exports = () => ({});

View File

@@ -0,0 +1 @@
module.exports = () => ({});

View File

@@ -27,6 +27,52 @@ describe("option-manager", () => {
return { plugin, calls };
}
it("should throw when an option is provided as a preset", () => {
expect(() => {
loadOptions({
presets: [
"./fixtures/option-manager/babel-preset-bar",
{ useBuiltIns: "entry" },
],
});
}).toThrowErrorMatchingSnapshot();
});
it("should throw when an option is provided as a plugin", () => {
expect(() => {
loadOptions({
plugins: [
"./fixtures/option-manager/babel-plugin-foo",
{ useSpread: true },
],
});
}).toThrowErrorMatchingSnapshot();
});
it("should throw when an option is following a preset", () => {
expect(() => {
loadOptions({
presets: [
"./fixtures/option-manager/babel-plugin-foo",
"./fixtures/option-manager/babel-preset-bar",
{ useSpread: true },
],
});
}).toThrowErrorMatchingSnapshot();
});
it("should not throw when a preset string followed by valid preset object", () => {
const { plugin } = makePlugin("my-plugin");
expect(
loadOptions({
presets: [
"@babel/env",
{ plugins: [[plugin, undefined, "my-plugin"]] },
],
}),
).toBeTruthy();
});
it("should throw if a plugin is repeated, with information about the repeated plugin", () => {
const { calls, plugin } = makePlugin("my-plugin");