Skip to content

Commit 8f749ec

Browse files
committed
test: add tests for hot middleware
Covers schema validation of the `hot` option (success and failure cases with snapshots), unit tests for `pathMatch`, `formatErrors`, `buildModuleMap` and `createEventStream`, and integration tests that verify SSE headers, the default and custom hot paths, MultiCompiler support, `close()` teardown, and the `log` option (custom function and `log: false`).
1 parent f12a413 commit 8f749ec

3 files changed

Lines changed: 438 additions & 0 deletions

File tree

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,63 @@ exports[`validation should throw an error on the "headers" option with "true" va
7575
* options.headers should be an instance of function."
7676
`;
7777

78+
exports[`validation should throw an error on the "hot" option with "{"heartbeat":-1}" value 1`] = `
79+
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
80+
- options.hot.heartbeat should be >= 0.
81+
-> Heartbeat interval (in milliseconds) used to keep the SSE connection alive."
82+
`;
83+
84+
exports[`validation should throw an error on the "hot" option with "{"log":true}" value 1`] = `
85+
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
86+
- options.hot should be one of these:
87+
boolean | object { path?, heartbeat?, log?, statsOptions? }
88+
-> Enable hot module replacement via a Server-Sent Events endpoint.
89+
-> Read more at https://github.com/webpack/webpack-dev-middleware#hot
90+
Details:
91+
* options.hot.log should be one of these:
92+
false | function
93+
-> Logger used to print build status. Pass \`false\` to disable.
94+
Details:
95+
* options.hot.log should be false.
96+
* options.hot.log should be an instance of function."
97+
`;
98+
99+
exports[`validation should throw an error on the "hot" option with "{"path":""}" value 1`] = `
100+
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
101+
- options.hot.path should be a non-empty string.
102+
-> The path the SSE endpoint is served at."
103+
`;
104+
105+
exports[`validation should throw an error on the "hot" option with "{"unknown":true}" value 1`] = `
106+
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
107+
- options.hot has an unknown property 'unknown'. These properties are valid:
108+
object { path?, heartbeat?, log?, statsOptions? }"
109+
`;
110+
111+
exports[`validation should throw an error on the "hot" option with "0" value 1`] = `
112+
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
113+
- options.hot should be one of these:
114+
boolean | object { path?, heartbeat?, log?, statsOptions? }
115+
-> Enable hot module replacement via a Server-Sent Events endpoint.
116+
-> Read more at https://github.com/webpack/webpack-dev-middleware#hot
117+
Details:
118+
* options.hot should be a boolean.
119+
* options.hot should be an object:
120+
object { path?, heartbeat?, log?, statsOptions? }"
121+
`;
122+
123+
exports[`validation should throw an error on the "hot" option with "foo" value 1`] = `
124+
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
125+
- options.hot should be one of these:
126+
boolean | object { path?, heartbeat?, log?, statsOptions? }
127+
-> Enable hot module replacement via a Server-Sent Events endpoint.
128+
-> Read more at https://github.com/webpack/webpack-dev-middleware#hot
129+
Details:
130+
* options.hot should be a boolean.
131+
* options.hot should be an object:
132+
object { path?, heartbeat?, log?, statsOptions? }"
133+
`;
134+
78135
exports[`validation should throw an error on the "index" option with "{}" value 1`] = `
79136
"Invalid options object. Dev Middleware has been initialized using an options object that does not match the API schema.
80137
- options.index should be one of these:

0 commit comments

Comments
 (0)