Skip to content

Commit 08a0ea7

Browse files
committed
fix: ensure undefined options default to an empty object in Server constructor
1 parent 797b9e7 commit 08a0ea7

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

lib/Server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ class Server {
341341
* @param {(Compiler | MultiCompiler)=} compiler compiler, omitted when the server is used as a plugin via `apply()`
342342
*/
343343
constructor(options, compiler) {
344-
options ??= {};
344+
options = options === undefined ? {} : options;
345345

346346
validate(/** @type {Schema} */ (schema), options, {
347347
name: "Dev Server",

test/e2e/api.test.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,17 @@ describe("API", () => {
8181

8282
expect(server.options).toEqual({});
8383

84-
await server.start();
85-
await server.stop();
84+
try {
85+
await server.start();
86+
} finally {
87+
await server.stop();
88+
}
89+
});
90+
91+
it("should reject `null` options via schema validation", () => {
92+
const compiler = webpack(config);
93+
94+
expect(() => new Server(null, compiler)).toThrow(/Invalid options object/);
8695
});
8796
});
8897

0 commit comments

Comments
 (0)