Skip to content

Commit

Permalink
fix: deprecate onAfterSetupMiddleware and onBeforeSetupMiddleware
Browse files Browse the repository at this point in the history
… option
  • Loading branch information
snitin315 committed Dec 2, 2021
1 parent 34d8431 commit 6768a2a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/Server.js
Expand Up @@ -949,6 +949,24 @@ class Server {
options.open = [...getOpenItemsFromObject(options.open)];
}

if (options.onAfterSetupMiddleware) {
// TODO: remove in the next major release
util.deprecate(
() => {},
"'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.",
`DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE`
)();
}

if (options.onBeforeSetupMiddleware) {
// TODO: remove in the next major release
util.deprecate(
() => {},
"'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.",
`DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE`
)();
}

if (typeof options.port === "string" && options.port !== "auto") {
options.port = Number(options.port);
}
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/on-after-setup-middleware.test.js
@@ -1,5 +1,6 @@
"use strict";

const util = require("util");
const webpack = require("webpack");
const Server = require("../../lib/Server");
const config = require("../fixtures/client-config/webpack.config");
Expand All @@ -13,9 +14,13 @@ describe("onAfterSetupMiddleware option", () => {
let browser;
let pageErrors;
let consoleMessages;
let utilSpy;

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

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

server = new Server(
{
onAfterSetupMiddleware: (devServer) => {
Expand Down Expand Up @@ -58,6 +63,10 @@ describe("onAfterSetupMiddleware option", () => {
pageErrors.push(error);
});

expect(utilSpy.mock.calls[0][1]).toBe(
"'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option."
);

const response = await page.goto(
`http://127.0.0.1:${port}/after/some/path`,
{
Expand Down Expand Up @@ -94,6 +103,10 @@ describe("onAfterSetupMiddleware option", () => {
interceptedRequest.continue({ method: "POST" });
});

expect(utilSpy.mock.calls[0][1]).toBe(
"'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option."
);

const response = await page.goto(
`http://127.0.0.1:${port}/after/some/path`,
{
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/on-before-setup-middleware.test.js
@@ -1,5 +1,6 @@
"use strict";

const util = require("util");
const webpack = require("webpack");
const Server = require("../../lib/Server");
const config = require("../fixtures/client-config/webpack.config");
Expand All @@ -13,9 +14,13 @@ describe("onBeforeSetupMiddleware option", () => {
let browser;
let pageErrors;
let consoleMessages;
let utilSpy;

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

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

server = new Server(
{
onBeforeSetupMiddleware: (devServer) => {
Expand Down Expand Up @@ -58,6 +63,10 @@ describe("onBeforeSetupMiddleware option", () => {
pageErrors.push(error);
});

expect(utilSpy.mock.calls[0][1]).toBe(
"'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option."
);

const response = await page.goto(
`http://127.0.0.1:${port}/before/some/path`,
{
Expand Down Expand Up @@ -94,6 +103,10 @@ describe("onBeforeSetupMiddleware option", () => {
interceptedRequest.continue({ method: "POST" });
});

expect(utilSpy.mock.calls[0][1]).toBe(
"'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option."
);

const response = await page.goto(
`http://127.0.0.1:${port}/before/some/path`,
{
Expand Down

0 comments on commit 6768a2a

Please sign in to comment.