From 521cf852a81c5913e17cf36c90140c566d4218e5 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Fri, 5 Nov 2021 04:20:38 -0700 Subject: [PATCH] feat: show deprecation warning for `https`/`http2` option (#4003) --- lib/Server.js | 11 +++++++++++ test/e2e/http2.test.js | 8 ++++++++ test/e2e/https.test.js | 8 ++++++++ 3 files changed, 27 insertions(+) diff --git a/lib/Server.js b/lib/Server.js index 6fe00da346..d35e507d75 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -523,6 +523,17 @@ class Server { const isHTTPs = Boolean(options.https); const isSPDY = Boolean(options.http2); + if (isHTTPs || isSPDY) { + // 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"}` + )(); + } + options.server = { type: // eslint-disable-next-line no-nested-ternary diff --git a/test/e2e/http2.test.js b/test/e2e/http2.test.js index dd57c62755..e5dffc005b 100644 --- a/test/e2e/http2.test.js +++ b/test/e2e/http2.test.js @@ -2,6 +2,7 @@ const path = require("path"); const http2 = require("http2"); +const util = require("util"); const webpack = require("webpack"); const Server = require("../../lib/Server"); const config = require("../fixtures/static-config/webpack.config"); @@ -92,10 +93,13 @@ describe("http2 option", () => { let browser; let pageErrors; let consoleMessages; + let utilSpy; beforeEach(async () => { compiler = webpack(config); + utilSpy = jest.spyOn(util, "deprecate"); + server = new Server( { static: staticDirectory, @@ -135,6 +139,10 @@ describe("http2 option", () => { () => performance.getEntries()[0].nextHopProtocol ); + expect(utilSpy.mock.calls[0][1]).toBe( + "'http2' option is deprecated. Please use the 'server' option." + ); + expect(HTTPVersion).toMatchSnapshot("HTTP version"); expect(response.status()).toMatchSnapshot("response status"); diff --git a/test/e2e/https.test.js b/test/e2e/https.test.js index b6e384e13a..23b4e0a146 100644 --- a/test/e2e/https.test.js +++ b/test/e2e/https.test.js @@ -2,6 +2,7 @@ const https = require("https"); const path = require("path"); +const util = require("util"); const fs = require("graceful-fs"); const request = require("supertest"); const webpack = require("webpack"); @@ -30,10 +31,13 @@ describe("https option", () => { let browser; let pageErrors; let consoleMessages; + let utilSpy; beforeEach(async () => { compiler = webpack(config); + utilSpy = jest.spyOn(util, "deprecate"); + server = new Server( { static: { @@ -72,6 +76,10 @@ describe("https option", () => { waitUntil: "networkidle0", }); + expect(utilSpy.mock.calls[0][1]).toBe( + "'https' option is deprecated. Please use the 'server' option." + ); + expect(response.status()).toMatchSnapshot("response status"); expect(await response.text()).toMatchSnapshot("response text");