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: update listen and close deprecation warning message #4097

Merged
merged 3 commits into from
Dec 10, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2404,7 +2404,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 @@ -2464,7 +2464,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