diff --git a/lib/Server.js b/lib/Server.js index 4a0af3b3f1..82932b897f 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -2175,7 +2175,9 @@ class Server { } startCallback(callback) { - this.start().then(() => callback(null), callback); + this.start() + .then(() => callback(null), callback) + .catch(callback); } async stop() { @@ -2235,7 +2237,9 @@ class Server { } stopCallback(callback) { - this.stop().then(() => callback(null), callback); + this.stop() + .then(() => callback(null), callback) + .catch(callback); } // TODO remove in the next major release diff --git a/test/e2e/api.test.js b/test/e2e/api.test.js index a361ecfc87..f11896592b 100644 --- a/test/e2e/api.test.js +++ b/test/e2e/api.test.js @@ -80,6 +80,29 @@ describe("API", () => { }); }); + it(`should catch errors within startCallback`, async () => { + const compiler = webpack(config); + const server = new Server( + { port, static: "https://absolute-url.com/somewhere" }, + compiler + ); + + await new Promise((resolve) => { + server.startCallback((err) => { + expect(err.message).toEqual( + "Using a URL as static.directory is not supported" + ); + resolve(); + }); + }); + + await new Promise((resolve) => { + server.stopCallback(() => { + resolve(); + }); + }); + }); + it(`should work when using configured manually`, async () => { const compiler = webpack({ ...config,