From 0963d744e9bbfbec52e32d1663df03ff0b0ba339 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Tue, 21 May 2019 10:38:37 +0200 Subject: [PATCH] add test case for enum validation --- lib/WebpackOptionsValidationError.js | 8 +++++--- test/Validation.test.js | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/WebpackOptionsValidationError.js b/lib/WebpackOptionsValidationError.js index d66cb2ccca2..62f53f81f43 100644 --- a/lib/WebpackOptionsValidationError.js +++ b/lib/WebpackOptionsValidationError.js @@ -154,6 +154,10 @@ class WebpackOptionsValidationError extends WebpackError { return "RegExp"; } + if (schema.enum) { + return schema.enum.map(item => JSON.stringify(item)).join(" | "); + } + if (schema.$ref) { return formatInnerSchema(getSchemaPart(schema.$ref), true); } @@ -166,9 +170,6 @@ class WebpackOptionsValidationError extends WebpackError { if (schema.anyOf) { return schema.anyOf.map(formatInnerSchema).join(" | "); } - if (schema.enum) { - return schema.enum.map(item => JSON.stringify(item)).join(" | "); - } return JSON.stringify(schema, null, 2); } @@ -250,6 +251,7 @@ class WebpackOptionsValidationError extends WebpackError { err.parentSchema )}`; } else if (err.keyword === "enum") { + console.log(err.parentSchema); if ( err.parentSchema && err.parentSchema.enum && diff --git a/test/Validation.test.js b/test/Validation.test.js index df78b93c1d6..47314e32ac2 100644 --- a/test/Validation.test.js +++ b/test/Validation.test.js @@ -458,6 +458,20 @@ describe("Validation", () => { -> The run point of the plugin, required method. * configuration.plugins[0] should be an instance of function -> Function acting as plugin" +`) + ); + + createTestCase( + "invalid mode", + { + mode: "protuction" + }, + msg => + expect(msg).toMatchInlineSnapshot(` +"Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. + - configuration.mode should be one of these: + \\"development\\" | \\"production\\" | \\"none\\" + -> Enable production optimizations or development hints." `) ); });