Skip to content

Commit

Permalink
feat: show deprecation warning for cacert option (#4115)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Dec 16, 2021
1 parent 5f6d903 commit c73ddfb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/Server.js
Expand Up @@ -726,13 +726,21 @@ class Server {
options.server.options.requestCert = false;
}

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

if (property === "cacert") {
// TODO remove the `cacert` option in favor `ca` in the next major release
util.deprecate(
() => {},
"The 'cacert' option is deprecated. Please use the 'ca' option.",
"DEP_WEBPACK_DEV_SERVER_CACERT"
)();
}

const value = options.server.options[property];
const readFile = (item) => {
if (
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/https.test.js
Expand Up @@ -655,11 +655,13 @@ describe("https option", () => {
let browser;
let pageErrors;
let consoleMessages;
let utilSpy;

beforeEach(async () => {
compiler = webpack(config);

createServerSpy = jest.spyOn(https, "createServer");
utilSpy = jest.spyOn(util, "deprecate");

server = new Server(
{
Expand Down Expand Up @@ -697,6 +699,7 @@ describe("https option", () => {

afterEach(async () => {
createServerSpy.mockRestore();
utilSpy.mockRestore();

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

expect(utilSpy.mock.calls[1][1]).toBe(
"The 'cacert' option is deprecated. Please use the 'ca' option."
);
expect(
normalizeOptions(createServerSpy.mock.calls[0][0])
).toMatchSnapshot("https options");
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/server.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 spdy = require("spdy");
Expand Down Expand Up @@ -871,11 +872,13 @@ describe("server option", () => {
let browser;
let pageErrors;
let consoleMessages;
let utilSpy;

beforeEach(async () => {
compiler = webpack(config);

createServerSpy = jest.spyOn(https, "createServer");
utilSpy = jest.spyOn(util, "deprecate");

server = new Server(
{
Expand Down Expand Up @@ -916,6 +919,7 @@ describe("server option", () => {

afterEach(async () => {
createServerSpy.mockRestore();
utilSpy.mockRestore();

await browser.close();
await server.stop();
Expand All @@ -934,6 +938,9 @@ describe("server option", () => {
waitUntil: "networkidle0",
});

expect(utilSpy.mock.calls[0][1]).toBe(
"The 'cacert' option is deprecated. Please use the 'ca' option."
);
expect(
normalizeOptions(createServerSpy.mock.calls[0][0])
).toMatchSnapshot("https options");
Expand Down

0 comments on commit c73ddfb

Please sign in to comment.