Skip to content

Commit

Permalink
add test case for enum validation
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed May 22, 2019
1 parent f1df013 commit 0963d74
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/WebpackOptionsValidationError.js
Expand Up @@ -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);
}
Expand All @@ -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);
}

Expand Down Expand Up @@ -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 &&
Expand Down
14 changes: 14 additions & 0 deletions test/Validation.test.js
Expand Up @@ -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."
`)
);
});

0 comments on commit 0963d74

Please sign in to comment.