Skip to content

Commit 7a8a780

Browse files
snitin315alexander-akait
authored andcommitted
fix: deprecate onAfterSetupMiddleware and onBeforeSetupMiddleware option
1 parent f0d6811 commit 7a8a780

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

lib/Server.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,24 @@ class Server {
965965
options.open = [...getOpenItemsFromObject(options.open)];
966966
}
967967

968+
if (options.onAfterSetupMiddleware) {
969+
// TODO: remove in the next major release
970+
util.deprecate(
971+
() => {},
972+
"'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.",
973+
`DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE`
974+
)();
975+
}
976+
977+
if (options.onBeforeSetupMiddleware) {
978+
// TODO: remove in the next major release
979+
util.deprecate(
980+
() => {},
981+
"'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.",
982+
`DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE`
983+
)();
984+
}
985+
968986
if (typeof options.port === "string" && options.port !== "auto") {
969987
options.port = Number(options.port);
970988
}

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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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)