diff --git a/lib/options.json b/lib/options.json index 7c743a9ae4..52cd0e9eba 100644 --- a/lib/options.json +++ b/lib/options.json @@ -6,6 +6,7 @@ "anyOf": [ { "type": "array", + "minItems": 1, "items": { "$ref": "#/definitions/AllowedHostsItem" } diff --git a/test/__snapshots__/validate-options.test.js.snap.webpack4 b/test/__snapshots__/validate-options.test.js.snap.webpack4 index 7227bcc5a3..ef404505a2 100644 --- a/test/__snapshots__/validate-options.test.js.snap.webpack4 +++ b/test/__snapshots__/validate-options.test.js.snap.webpack4 @@ -1,13 +1,23 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`options validate should throw an error on the "allowedHosts" option with '[""]' value 1`] = ` +"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. + - options.allowedHosts[0] should be an non-empty string." +`; + +exports[`options validate should throw an error on the "allowedHosts" option with '[]' value 1`] = ` +"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. + - options.allowedHosts should be an non-empty array." +`; + exports[`options validate should throw an error on the "allowedHosts" option with '123' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options.allowedHosts should be one of these: - [non-empty string, ...] | \\"auto\\" | \\"all\\" | non-empty string + [non-empty string, ...] (should not have fewer than 1 item) | \\"auto\\" | \\"all\\" | non-empty string -> Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts Details: * options.allowedHosts should be an array: - [non-empty string, ...] + [non-empty string, ...] (should not have fewer than 1 item) * options.allowedHosts should be one of these: \\"auto\\" | \\"all\\" * options.allowedHosts should be a non-empty string." @@ -16,11 +26,11 @@ exports[`options validate should throw an error on the "allowedHosts" option wit exports[`options validate should throw an error on the "allowedHosts" option with 'false' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options.allowedHosts should be one of these: - [non-empty string, ...] | \\"auto\\" | \\"all\\" | non-empty string + [non-empty string, ...] (should not have fewer than 1 item) | \\"auto\\" | \\"all\\" | non-empty string -> Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts Details: * options.allowedHosts should be an array: - [non-empty string, ...] + [non-empty string, ...] (should not have fewer than 1 item) * options.allowedHosts should be one of these: \\"auto\\" | \\"all\\" * options.allowedHosts should be a non-empty string." @@ -29,11 +39,11 @@ exports[`options validate should throw an error on the "allowedHosts" option wit exports[`options validate should throw an error on the "allowedHosts" option with 'true' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options.allowedHosts should be one of these: - [non-empty string, ...] | \\"auto\\" | \\"all\\" | non-empty string + [non-empty string, ...] (should not have fewer than 1 item) | \\"auto\\" | \\"all\\" | non-empty string -> Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts Details: * options.allowedHosts should be an array: - [non-empty string, ...] + [non-empty string, ...] (should not have fewer than 1 item) * options.allowedHosts should be one of these: \\"auto\\" | \\"all\\" * options.allowedHosts should be a non-empty string." diff --git a/test/__snapshots__/validate-options.test.js.snap.webpack5 b/test/__snapshots__/validate-options.test.js.snap.webpack5 index 7227bcc5a3..ef404505a2 100644 --- a/test/__snapshots__/validate-options.test.js.snap.webpack5 +++ b/test/__snapshots__/validate-options.test.js.snap.webpack5 @@ -1,13 +1,23 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`options validate should throw an error on the "allowedHosts" option with '[""]' value 1`] = ` +"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. + - options.allowedHosts[0] should be an non-empty string." +`; + +exports[`options validate should throw an error on the "allowedHosts" option with '[]' value 1`] = ` +"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. + - options.allowedHosts should be an non-empty array." +`; + exports[`options validate should throw an error on the "allowedHosts" option with '123' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options.allowedHosts should be one of these: - [non-empty string, ...] | \\"auto\\" | \\"all\\" | non-empty string + [non-empty string, ...] (should not have fewer than 1 item) | \\"auto\\" | \\"all\\" | non-empty string -> Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts Details: * options.allowedHosts should be an array: - [non-empty string, ...] + [non-empty string, ...] (should not have fewer than 1 item) * options.allowedHosts should be one of these: \\"auto\\" | \\"all\\" * options.allowedHosts should be a non-empty string." @@ -16,11 +26,11 @@ exports[`options validate should throw an error on the "allowedHosts" option wit exports[`options validate should throw an error on the "allowedHosts" option with 'false' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options.allowedHosts should be one of these: - [non-empty string, ...] | \\"auto\\" | \\"all\\" | non-empty string + [non-empty string, ...] (should not have fewer than 1 item) | \\"auto\\" | \\"all\\" | non-empty string -> Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts Details: * options.allowedHosts should be an array: - [non-empty string, ...] + [non-empty string, ...] (should not have fewer than 1 item) * options.allowedHosts should be one of these: \\"auto\\" | \\"all\\" * options.allowedHosts should be a non-empty string." @@ -29,11 +39,11 @@ exports[`options validate should throw an error on the "allowedHosts" option wit exports[`options validate should throw an error on the "allowedHosts" option with 'true' value 1`] = ` "ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options.allowedHosts should be one of these: - [non-empty string, ...] | \\"auto\\" | \\"all\\" | non-empty string + [non-empty string, ...] (should not have fewer than 1 item) | \\"auto\\" | \\"all\\" | non-empty string -> Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts Details: * options.allowedHosts should be an array: - [non-empty string, ...] + [non-empty string, ...] (should not have fewer than 1 item) * options.allowedHosts should be one of these: \\"auto\\" | \\"all\\" * options.allowedHosts should be a non-empty string." diff --git a/test/validate-options.test.js b/test/validate-options.test.js index 7ba8d382ba..9533c29976 100644 --- a/test/validate-options.test.js +++ b/test/validate-options.test.js @@ -167,7 +167,7 @@ const tests = { }, allowedHosts: { success: ['auto', 'all', ['foo'], 'bar'], - failure: [true, false, 123], + failure: [true, false, 123, [], ['']], }, headers: { success: [{}, { foo: 'bar' }, () => {}],