Skip to content

Commit

Permalink
feat: show deprecation warning for https/http2 option (#4003)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Nov 5, 2021
1 parent 19cc6a5 commit 521cf85
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/Server.js
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/http2.test.js
Expand Up @@ -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");
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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");
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/https.test.js
Expand Up @@ -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");
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 521cf85

Please sign in to comment.