Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show deprecation warning for cacert option #4115

Merged
merged 1 commit into from Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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