Skip to content

Commit bb9fe2c

Browse files
committed
test: add validation tests
1 parent ffe5aff commit bb9fe2c

File tree

3 files changed

+310
-0
lines changed

3 files changed

+310
-0
lines changed

test/__snapshots__/validate-options.test.js.snap.webpack4

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,124 @@ exports[`options validate should throw an error on the "proxy" option with 'fals
608608
[object { … } | function, ...]"
609609
`;
610610

611+
exports[`options validate should throw an error on the "server" option with '{"type":"https","additional":"test"}' value 1`] = `
612+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
613+
- options.server has an unknown property 'additional'. These properties are valid:
614+
object { type?, options? }"
615+
`;
616+
617+
exports[`options validate should throw an error on the "server" option with '{"type":"https","options":{"ca":true}}' value 1`] = `
618+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
619+
- options.server should be one of these:
620+
\\"http\\" | \\"https\\" | \\"spdy\\" | object { type?, options? }
621+
-> Allows to set server and options (by default 'http').
622+
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverserver
623+
Details:
624+
* options.server.options.ca should be one of these:
625+
[string | Buffer, ...] | string | Buffer
626+
-> Path to an SSL CA certificate or content of an SSL CA certificate.
627+
Details:
628+
* options.server.options.ca should be an array:
629+
[string | Buffer, ...]
630+
* options.server.options.ca should be a string.
631+
* options.server.options.ca should be an instance of Buffer."
632+
`;
633+
634+
exports[`options validate should throw an error on the "server" option with '{"type":"https","options":{"cert":true}}' value 1`] = `
635+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
636+
- options.server should be one of these:
637+
\\"http\\" | \\"https\\" | \\"spdy\\" | object { type?, options? }
638+
-> Allows to set server and options (by default 'http').
639+
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverserver
640+
Details:
641+
* options.server.options.cert should be one of these:
642+
[string | Buffer, ...] | string | Buffer
643+
-> Path to an SSL certificate or content of an SSL certificate.
644+
Details:
645+
* options.server.options.cert should be an array:
646+
[string | Buffer, ...]
647+
* options.server.options.cert should be a string.
648+
* options.server.options.cert should be an instance of Buffer."
649+
`;
650+
651+
exports[`options validate should throw an error on the "server" option with '{"type":"https","options":{"key":10}}' value 1`] = `
652+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
653+
- options.server should be one of these:
654+
\\"http\\" | \\"https\\" | \\"spdy\\" | object { type?, options? }
655+
-> Allows to set server and options (by default 'http').
656+
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverserver
657+
Details:
658+
* options.server.options.key should be one of these:
659+
[string | Buffer | object { … }, ...] | string | Buffer
660+
-> Path to an SSL key or content of an SSL key.
661+
Details:
662+
* options.server.options.key should be an array:
663+
[string | Buffer | object { … }, ...]
664+
* options.server.options.key should be a string.
665+
* options.server.options.key should be an instance of Buffer."
666+
`;
667+
668+
exports[`options validate should throw an error on the "server" option with '{"type":"https","options":{"passphrase":false}}' value 1`] = `
669+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
670+
- options.server.options.passphrase should be a string.
671+
-> Passphrase for a pfx file."
672+
`;
673+
674+
exports[`options validate should throw an error on the "server" option with '{"type":"https","options":{"pfx":10}}' value 1`] = `
675+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
676+
- options.server should be one of these:
677+
\\"http\\" | \\"https\\" | \\"spdy\\" | object { type?, options? }
678+
-> Allows to set server and options (by default 'http').
679+
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverserver
680+
Details:
681+
* options.server.options.pfx should be one of these:
682+
[string | Buffer | object { … }, ...] | string | Buffer
683+
-> Path to an SSL pfx file or content of an SSL pfx file.
684+
Details:
685+
* options.server.options.pfx should be an array:
686+
[string | Buffer | object { … }, ...]
687+
* options.server.options.pfx should be a string.
688+
* options.server.options.pfx should be an instance of Buffer."
689+
`;
690+
691+
exports[`options validate should throw an error on the "server" option with '{"type":"https","options":{"requestCert":"false"}}' value 1`] = `
692+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
693+
- options.server.options.requestCert should be a boolean.
694+
-> Request for an SSL certificate."
695+
`;
696+
697+
exports[`options validate should throw an error on the "server" option with '{"type":"invalid"}' value 1`] = `
698+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
699+
- options.server.type should be one of these:
700+
\\"http\\" | \\"https\\" | \\"spdy\\""
701+
`;
702+
703+
exports[`options validate should throw an error on the "server" option with 'http2' value 1`] = `
704+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
705+
- options.server should be one of these:
706+
\\"http\\" | \\"https\\" | \\"spdy\\" | object { type?, options? }
707+
-> Allows to set server and options (by default 'http').
708+
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverserver
709+
Details:
710+
* options.server should be one of these:
711+
\\"http\\" | \\"https\\" | \\"spdy\\"
712+
* options.server should be an object:
713+
object { type?, options? }"
714+
`;
715+
716+
exports[`options validate should throw an error on the "server" option with 'invalid' value 1`] = `
717+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
718+
- options.server should be one of these:
719+
\\"http\\" | \\"https\\" | \\"spdy\\" | object { type?, options? }
720+
-> Allows to set server and options (by default 'http').
721+
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverserver
722+
Details:
723+
* options.server should be one of these:
724+
\\"http\\" | \\"https\\" | \\"spdy\\"
725+
* options.server should be an object:
726+
object { type?, options? }"
727+
`;
728+
611729
exports[`options validate should throw an error on the "static" option with '' value 1`] = `
612730
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
613731
- options.static should be a non-empty string."

test/__snapshots__/validate-options.test.js.snap.webpack5

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,124 @@ exports[`options validate should throw an error on the "proxy" option with 'fals
608608
[object { … } | function, ...]"
609609
`;
610610

611+
exports[`options validate should throw an error on the "server" option with '{"type":"https","additional":"test"}' value 1`] = `
612+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
613+
- options.server has an unknown property 'additional'. These properties are valid:
614+
object { type?, options? }"
615+
`;
616+
617+
exports[`options validate should throw an error on the "server" option with '{"type":"https","options":{"ca":true}}' value 1`] = `
618+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
619+
- options.server should be one of these:
620+
\\"http\\" | \\"https\\" | \\"spdy\\" | object { type?, options? }
621+
-> Allows to set server and options (by default 'http').
622+
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverserver
623+
Details:
624+
* options.server.options.ca should be one of these:
625+
[string | Buffer, ...] | string | Buffer
626+
-> Path to an SSL CA certificate or content of an SSL CA certificate.
627+
Details:
628+
* options.server.options.ca should be an array:
629+
[string | Buffer, ...]
630+
* options.server.options.ca should be a string.
631+
* options.server.options.ca should be an instance of Buffer."
632+
`;
633+
634+
exports[`options validate should throw an error on the "server" option with '{"type":"https","options":{"cert":true}}' value 1`] = `
635+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
636+
- options.server should be one of these:
637+
\\"http\\" | \\"https\\" | \\"spdy\\" | object { type?, options? }
638+
-> Allows to set server and options (by default 'http').
639+
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverserver
640+
Details:
641+
* options.server.options.cert should be one of these:
642+
[string | Buffer, ...] | string | Buffer
643+
-> Path to an SSL certificate or content of an SSL certificate.
644+
Details:
645+
* options.server.options.cert should be an array:
646+
[string | Buffer, ...]
647+
* options.server.options.cert should be a string.
648+
* options.server.options.cert should be an instance of Buffer."
649+
`;
650+
651+
exports[`options validate should throw an error on the "server" option with '{"type":"https","options":{"key":10}}' value 1`] = `
652+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
653+
- options.server should be one of these:
654+
\\"http\\" | \\"https\\" | \\"spdy\\" | object { type?, options? }
655+
-> Allows to set server and options (by default 'http').
656+
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverserver
657+
Details:
658+
* options.server.options.key should be one of these:
659+
[string | Buffer | object { … }, ...] | string | Buffer
660+
-> Path to an SSL key or content of an SSL key.
661+
Details:
662+
* options.server.options.key should be an array:
663+
[string | Buffer | object { … }, ...]
664+
* options.server.options.key should be a string.
665+
* options.server.options.key should be an instance of Buffer."
666+
`;
667+
668+
exports[`options validate should throw an error on the "server" option with '{"type":"https","options":{"passphrase":false}}' value 1`] = `
669+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
670+
- options.server.options.passphrase should be a string.
671+
-> Passphrase for a pfx file."
672+
`;
673+
674+
exports[`options validate should throw an error on the "server" option with '{"type":"https","options":{"pfx":10}}' value 1`] = `
675+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
676+
- options.server should be one of these:
677+
\\"http\\" | \\"https\\" | \\"spdy\\" | object { type?, options? }
678+
-> Allows to set server and options (by default 'http').
679+
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverserver
680+
Details:
681+
* options.server.options.pfx should be one of these:
682+
[string | Buffer | object { … }, ...] | string | Buffer
683+
-> Path to an SSL pfx file or content of an SSL pfx file.
684+
Details:
685+
* options.server.options.pfx should be an array:
686+
[string | Buffer | object { … }, ...]
687+
* options.server.options.pfx should be a string.
688+
* options.server.options.pfx should be an instance of Buffer."
689+
`;
690+
691+
exports[`options validate should throw an error on the "server" option with '{"type":"https","options":{"requestCert":"false"}}' value 1`] = `
692+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
693+
- options.server.options.requestCert should be a boolean.
694+
-> Request for an SSL certificate."
695+
`;
696+
697+
exports[`options validate should throw an error on the "server" option with '{"type":"invalid"}' value 1`] = `
698+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
699+
- options.server.type should be one of these:
700+
\\"http\\" | \\"https\\" | \\"spdy\\""
701+
`;
702+
703+
exports[`options validate should throw an error on the "server" option with 'http2' value 1`] = `
704+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
705+
- options.server should be one of these:
706+
\\"http\\" | \\"https\\" | \\"spdy\\" | object { type?, options? }
707+
-> Allows to set server and options (by default 'http').
708+
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverserver
709+
Details:
710+
* options.server should be one of these:
711+
\\"http\\" | \\"https\\" | \\"spdy\\"
712+
* options.server should be an object:
713+
object { type?, options? }"
714+
`;
715+
716+
exports[`options validate should throw an error on the "server" option with 'invalid' value 1`] = `
717+
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
718+
- options.server should be one of these:
719+
\\"http\\" | \\"https\\" | \\"spdy\\" | object { type?, options? }
720+
-> Allows to set server and options (by default 'http').
721+
-> Read more at https://webpack.js.org/configuration/dev-server/#devserverserver
722+
Details:
723+
* options.server should be one of these:
724+
\\"http\\" | \\"https\\" | \\"spdy\\"
725+
* options.server should be an object:
726+
object { type?, options? }"
727+
`;
728+
611729
exports[`options validate should throw an error on the "static" option with '' value 1`] = `
612730
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
613731
- options.static should be a non-empty string."

test/validate-options.test.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,80 @@ const tests = {
388388
],
389389
failure: [() => {}, false],
390390
},
391+
server: {
392+
success: [
393+
"http",
394+
"https",
395+
"spdy",
396+
{
397+
type: "http",
398+
},
399+
{
400+
type: "https",
401+
},
402+
{
403+
type: "spdy",
404+
},
405+
{
406+
type: "https",
407+
options: {
408+
ca: path.join(httpsCertificateDirectory, "ca.pem"),
409+
key: path.join(httpsCertificateDirectory, "server.key"),
410+
pfx: path.join(httpsCertificateDirectory, "server.pfx"),
411+
cert: path.join(httpsCertificateDirectory, "server.crt"),
412+
requestCert: true,
413+
passphrase: "webpack-dev-server",
414+
},
415+
},
416+
],
417+
failure: [
418+
"http2",
419+
"invalid",
420+
{
421+
type: "invalid",
422+
},
423+
{
424+
type: "https",
425+
additional: "test",
426+
},
427+
{
428+
type: "https",
429+
options: {
430+
key: 10,
431+
},
432+
},
433+
{
434+
type: "https",
435+
options: {
436+
cert: true,
437+
},
438+
},
439+
{
440+
type: "https",
441+
options: {
442+
ca: true,
443+
},
444+
},
445+
{
446+
type: "https",
447+
options: {
448+
pfx: 10,
449+
},
450+
},
451+
{
452+
type: "https",
453+
options: {
454+
passphrase: false,
455+
},
456+
},
457+
{
458+
type: "https",
459+
options: {
460+
requestCert: "false",
461+
},
462+
},
463+
],
464+
},
391465
static: {
392466
success: [
393467
"path",

0 commit comments

Comments
 (0)