From d8d5d71c8ca495098e1ee30ebc72ffd657ad5ba0 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Thu, 2 Dec 2021 18:44:38 +0530 Subject: [PATCH] fix: show deprecation warning for both `https` and `http2` (#4069) --- lib/Server.js | 17 ++++++++++++----- test/e2e/http2.test.js | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/Server.js b/lib/Server.js index adcdb1cf4f..899a9846f1 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -674,14 +674,21 @@ class Server { const isHTTPs = Boolean(options.https); const isSPDY = Boolean(options.http2); - if (isHTTPs || isSPDY) { + if (isHTTPs) { // TODO: remove in the next major release util.deprecate( () => {}, - `'${ - isHTTPs ? "https" : "http2" - }' option is deprecated. Please use the 'server' option.`, - `DEP_WEBPACK_DEV_SERVER_${isHTTPs ? "HTTPS" : "HTTP2"}` + "'https' option is deprecated. Please use the 'server' option.", + "DEP_WEBPACK_DEV_SERVER_HTTPS" + )(); + } + + if (isSPDY) { + // TODO: remove in the next major release + util.deprecate( + () => {}, + "'http2' option is deprecated. Please use the 'server' option.", + "DEP_WEBPACK_DEV_SERVER_HTTP2" )(); } diff --git a/test/e2e/http2.test.js b/test/e2e/http2.test.js index e5dffc005b..74a2e863b4 100644 --- a/test/e2e/http2.test.js +++ b/test/e2e/http2.test.js @@ -21,10 +21,13 @@ describe("http2 option", () => { let page; let browser; let HTTPVersion; + let utilSpy; beforeEach(async () => { compiler = webpack(config); + utilSpy = jest.spyOn(util, "deprecate"); + server = new Server( { static: staticDirectory, @@ -49,6 +52,7 @@ describe("http2 option", () => { }); afterEach(async () => { + utilSpy.mockRestore(); await browser.close(); await server.stop(); }); @@ -82,6 +86,15 @@ describe("http2 option", () => { expect(HTTPVersion).toEqual("h2"); + // should show deprecated warning for both `https` and `http2` + expect(utilSpy.mock.calls[0][1]).toBe( + "'https' option is deprecated. Please use the 'server' option." + ); + + expect(utilSpy.mock.calls[1][1]).toBe( + "'http2' option is deprecated. Please use the 'server' option." + ); + http2Req.end(); }); }); @@ -118,6 +131,7 @@ describe("http2 option", () => { }); afterEach(async () => { + utilSpy.mockRestore(); await browser.close(); await server.stop(); });