Skip to content

Commit 4537e73

Browse files
committed
fix: deprecate onAfterSetupMiddleware and onBeforeSetupMiddleware option
1 parent f26e61e commit 4537e73

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

lib/Server.js

+18
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,24 @@ class Server {
956956
options.open = [...getOpenItemsFromObject(options.open)];
957957
}
958958

959+
if (options.onAfterSetupMiddleware) {
960+
// TODO: remove in the next major release
961+
util.deprecate(
962+
() => {},
963+
"'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.",
964+
`DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE`
965+
)();
966+
}
967+
968+
if (options.onBeforeSetupMiddleware) {
969+
// TODO: remove in the next major release
970+
util.deprecate(
971+
() => {},
972+
"'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.",
973+
`DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE`
974+
)();
975+
}
976+
959977
if (typeof options.port === "string" && options.port !== "auto") {
960978
options.port = Number(options.port);
961979
}

test/e2e/on-after-setup-middleware.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22

3+
const util = require("util");
34
const webpack = require("webpack");
45
const Server = require("../../lib/Server");
56
const config = require("../fixtures/client-config/webpack.config");
@@ -13,9 +14,13 @@ describe("onAfterSetupMiddleware option", () => {
1314
let browser;
1415
let pageErrors;
1516
let consoleMessages;
17+
let utilSpy;
1618

1719
beforeEach(async () => {
1820
compiler = webpack(config);
21+
22+
utilSpy = jest.spyOn(util, "deprecate");
23+
1924
server = new Server(
2025
{
2126
onAfterSetupMiddleware: (devServer) => {
@@ -58,6 +63,10 @@ describe("onAfterSetupMiddleware option", () => {
5863
pageErrors.push(error);
5964
});
6065

66+
expect(utilSpy.mock.calls[0][1]).toBe(
67+
"'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option."
68+
);
69+
6170
const response = await page.goto(
6271
`http://127.0.0.1:${port}/after/some/path`,
6372
{
@@ -94,6 +103,10 @@ describe("onAfterSetupMiddleware option", () => {
94103
interceptedRequest.continue({ method: "POST" });
95104
});
96105

106+
expect(utilSpy.mock.calls[0][1]).toBe(
107+
"'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option."
108+
);
109+
97110
const response = await page.goto(
98111
`http://127.0.0.1:${port}/after/some/path`,
99112
{

test/e2e/on-before-setup-middleware.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22

3+
const util = require("util");
34
const webpack = require("webpack");
45
const Server = require("../../lib/Server");
56
const config = require("../fixtures/client-config/webpack.config");
@@ -13,9 +14,13 @@ describe("onBeforeSetupMiddleware option", () => {
1314
let browser;
1415
let pageErrors;
1516
let consoleMessages;
17+
let utilSpy;
1618

1719
beforeEach(async () => {
1820
compiler = webpack(config);
21+
22+
utilSpy = jest.spyOn(util, "deprecate");
23+
1924
server = new Server(
2025
{
2126
onBeforeSetupMiddleware: (devServer) => {
@@ -58,6 +63,10 @@ describe("onBeforeSetupMiddleware option", () => {
5863
pageErrors.push(error);
5964
});
6065

66+
expect(utilSpy.mock.calls[0][1]).toBe(
67+
"'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option."
68+
);
69+
6170
const response = await page.goto(
6271
`http://127.0.0.1:${port}/before/some/path`,
6372
{
@@ -94,6 +103,10 @@ describe("onBeforeSetupMiddleware option", () => {
94103
interceptedRequest.continue({ method: "POST" });
95104
});
96105

106+
expect(utilSpy.mock.calls[0][1]).toBe(
107+
"'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option."
108+
);
109+
97110
const response = await page.goto(
98111
`http://127.0.0.1:${port}/before/some/path`,
99112
{

0 commit comments

Comments
 (0)