Fixed null error in plugin opts and added a test for it (#9945)

* Fixed null error in plugin opts and added a test for it

* Remove !opts and add opts === null check to avoid confusion with false and undefined cases

Co-Authored-By: divbhasin <divbest99@gmail.com>
This commit is contained in:
Divyam Bhasin 2019-05-07 10:23:01 -04:00 committed by Nicolò Ribaudo
parent 354666aa17
commit 7942dc0f07
2 changed files with 12 additions and 2 deletions

View File

@ -337,7 +337,7 @@ function assertPluginItem(loc: GeneralPath, value: mixed): PluginItem {
if (
opts !== undefined &&
opts !== false &&
(typeof opts !== "object" || Array.isArray(opts))
(typeof opts !== "object" || Array.isArray(opts) || opts === null)
) {
throw new Error(
`${msg(access(loc, 1))} must be an object, false, or undefined`,

View File

@ -38,6 +38,17 @@ describe("option-manager", () => {
expect(calls).toEqual([]);
});
it("throws for null options", () => {
const { calls, plugin } = makePlugin();
expect(() => {
loadOptions({
plugins: [[plugin, null]],
}).toThrow(/.plugins[0][1] must be an object, false, or undefined/);
});
expect(calls).toEqual([]);
});
it("should not throw if a repeated plugin has a different name", () => {
const { calls: calls1, plugin: plugin1 } = makePlugin();
const { calls: calls2, plugin: plugin2 } = makePlugin();
@ -87,7 +98,6 @@ describe("option-manager", () => {
expect(calls1).toEqual([{ arg: 1 }]);
expect(calls2).toEqual([{ arg: 2 }]);
});
it("should merge .env[] presets with parent presets", () => {
const { calls: calls1, plugin: preset1 } = makePlugin();
const { calls: calls2, plugin: preset2 } = makePlugin();