Skip to content

Commit c73ddfb

Browse files
authored
feat: show deprecation warning for cacert option (#4115)
1 parent 5f6d903 commit c73ddfb

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

lib/Server.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -726,13 +726,21 @@ class Server {
726726
options.server.options.requestCert = false;
727727
}
728728

729-
// TODO remove the `cacert` option in favor `ca` in the next major release
730729
for (const property of ["cacert", "ca", "cert", "crl", "key", "pfx"]) {
731730
if (typeof options.server.options[property] === "undefined") {
732731
// eslint-disable-next-line no-continue
733732
continue;
734733
}
735734

735+
if (property === "cacert") {
736+
// TODO remove the `cacert` option in favor `ca` in the next major release
737+
util.deprecate(
738+
() => {},
739+
"The 'cacert' option is deprecated. Please use the 'ca' option.",
740+
"DEP_WEBPACK_DEV_SERVER_CACERT"
741+
)();
742+
}
743+
736744
const value = options.server.options[property];
737745
const readFile = (item) => {
738746
if (

test/e2e/https.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -655,11 +655,13 @@ describe("https option", () => {
655655
let browser;
656656
let pageErrors;
657657
let consoleMessages;
658+
let utilSpy;
658659

659660
beforeEach(async () => {
660661
compiler = webpack(config);
661662

662663
createServerSpy = jest.spyOn(https, "createServer");
664+
utilSpy = jest.spyOn(util, "deprecate");
663665

664666
server = new Server(
665667
{
@@ -697,6 +699,7 @@ describe("https option", () => {
697699

698700
afterEach(async () => {
699701
createServerSpy.mockRestore();
702+
utilSpy.mockRestore();
700703

701704
await browser.close();
702705
await server.stop();
@@ -715,6 +718,9 @@ describe("https option", () => {
715718
waitUntil: "networkidle0",
716719
});
717720

721+
expect(utilSpy.mock.calls[1][1]).toBe(
722+
"The 'cacert' option is deprecated. Please use the 'ca' option."
723+
);
718724
expect(
719725
normalizeOptions(createServerSpy.mock.calls[0][0])
720726
).toMatchSnapshot("https options");

test/e2e/server.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const https = require("https");
44
const path = require("path");
5+
const util = require("util");
56
const fs = require("graceful-fs");
67
const request = require("supertest");
78
const spdy = require("spdy");
@@ -871,11 +872,13 @@ describe("server option", () => {
871872
let browser;
872873
let pageErrors;
873874
let consoleMessages;
875+
let utilSpy;
874876

875877
beforeEach(async () => {
876878
compiler = webpack(config);
877879

878880
createServerSpy = jest.spyOn(https, "createServer");
881+
utilSpy = jest.spyOn(util, "deprecate");
879882

880883
server = new Server(
881884
{
@@ -916,6 +919,7 @@ describe("server option", () => {
916919

917920
afterEach(async () => {
918921
createServerSpy.mockRestore();
922+
utilSpy.mockRestore();
919923

920924
await browser.close();
921925
await server.stop();
@@ -934,6 +938,9 @@ describe("server option", () => {
934938
waitUntil: "networkidle0",
935939
});
936940

941+
expect(utilSpy.mock.calls[0][1]).toBe(
942+
"The 'cacert' option is deprecated. Please use the 'ca' option."
943+
);
937944
expect(
938945
normalizeOptions(createServerSpy.mock.calls[0][0])
939946
).toMatchSnapshot("https options");

0 commit comments

Comments
 (0)