Skip to content

Commit

Permalink
fix: update listen and close deprecation warning message (#4097)
Browse files Browse the repository at this point in the history
* fix: update `listen` and `close` deprecation warning message

* test: add snapshots

* test: update webpack 4 snapshot
  • Loading branch information
snitin315 authored Dec 10, 2021
1 parent 693c28a commit b217a19
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2405,7 +2405,7 @@ class Server {
listen(port, hostname, fn) {
util.deprecate(
() => {},
"'listen' is deprecated. Please use async 'start' or 'startCallback' methods.",
"'listen' is deprecated. Please use the async 'start' or 'startCallback' method.",
"DEP_WEBPACK_DEV_SERVER_LISTEN"
)();

Expand Down Expand Up @@ -2465,7 +2465,7 @@ class Server {
close(callback) {
util.deprecate(
() => {},
"'close' is deprecated. Please use async 'stop' or 'stopCallback' methods.",
"'close' is deprecated. Please use the async 'stop' or 'stopCallback' method.",
"DEP_WEBPACK_DEV_SERVER_CLOSE"
)();

Expand Down
8 changes: 5 additions & 3 deletions test/e2e/__snapshots__/api.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ Array [

exports[`API should work with callback API: page errors 1`] = `Array []`;

exports[`API should work with deprecated API ('listen' and \`close\` methods): console messages 1`] = `
exports[`API should work with deprecated API ('listen' and 'close' methods): close deprecation log 1`] = `"'close' is deprecated. Please use the async 'stop' or 'stopCallback' method."`;

exports[`API should work with deprecated API ('listen' and 'close' methods): console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
Expand All @@ -64,9 +66,9 @@ Array [
]
`;

exports[`API should work with deprecated API ('listen' and \`close\` methods): deprecation log 1`] = `"'listen' is deprecated. Please use async 'start' or 'startCallback' methods."`;
exports[`API should work with deprecated API ('listen' and 'close' methods): listen deprecation log 1`] = `"'listen' is deprecated. Please use the async 'start' or 'startCallback' method."`;

exports[`API should work with deprecated API ('listen' and \`close\` methods): page errors 1`] = `Array []`;
exports[`API should work with deprecated API ('listen' and 'close' methods): page errors 1`] = `Array []`;

exports[`API should work with deprecated API (only compiler in constructor): console messages 1`] = `
Array [
Expand Down
8 changes: 5 additions & 3 deletions test/e2e/__snapshots__/api.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ Array [

exports[`API should work with callback API: page errors 1`] = `Array []`;

exports[`API should work with deprecated API ('listen' and \`close\` methods): console messages 1`] = `
exports[`API should work with deprecated API ('listen' and 'close' methods): close deprecation log 1`] = `"'close' is deprecated. Please use the async 'stop' or 'stopCallback' method."`;

exports[`API should work with deprecated API ('listen' and 'close' methods): console messages 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
Expand All @@ -64,9 +66,9 @@ Array [
]
`;

exports[`API should work with deprecated API ('listen' and \`close\` methods): deprecation log 1`] = `"'listen' is deprecated. Please use async 'start' or 'startCallback' methods."`;
exports[`API should work with deprecated API ('listen' and 'close' methods): listen deprecation log 1`] = `"'listen' is deprecated. Please use the async 'start' or 'startCallback' method."`;

exports[`API should work with deprecated API ('listen' and \`close\` methods): page errors 1`] = `Array []`;
exports[`API should work with deprecated API ('listen' and 'close' methods): page errors 1`] = `Array []`;

exports[`API should work with deprecated API (only compiler in constructor): console messages 1`] = `
Array [
Expand Down
11 changes: 8 additions & 3 deletions test/e2e/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ describe("API", () => {
await server.stop();
});

it("should work with deprecated API ('listen' and `close` methods)", async () => {
it("should work with deprecated API ('listen' and 'close' methods)", async () => {
const compiler = webpack(config);
const devServerOptions = { port };
const utilSpy = jest.spyOn(util, "deprecate");
Expand Down Expand Up @@ -239,19 +239,24 @@ describe("API", () => {
waitUntil: "networkidle0",
});

expect(utilSpy.mock.calls[0][1]).toMatchSnapshot("deprecation log");
expect(utilSpy.mock.calls[0][1]).toMatchSnapshot("listen deprecation log");
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
"console messages"
);
expect(pageErrors).toMatchSnapshot("page errors");

utilSpy.mockRestore();
await browser.close();
await new Promise((resolve) => {
server.close(() => {
resolve();
});
});

expect(
utilSpy.mock.calls[utilSpy.mock.calls.length - 1][1]
).toMatchSnapshot("close deprecation log");

utilSpy.mockRestore();
});

it(`should work with deprecated API (the order of the arguments in the constructor)`, async () => {
Expand Down

0 comments on commit b217a19

Please sign in to comment.