From b217a191d09a93e8dcc1fff2ee26e97857e096d3 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Fri, 10 Dec 2021 19:37:17 +0530 Subject: [PATCH] fix: update `listen` and `close` deprecation warning message (#4097) * fix: update `listen` and `close` deprecation warning message * test: add snapshots * test: update webpack 4 snapshot --- lib/Server.js | 4 ++-- test/e2e/__snapshots__/api.test.js.snap.webpack4 | 8 +++++--- test/e2e/__snapshots__/api.test.js.snap.webpack5 | 8 +++++--- test/e2e/api.test.js | 11 ++++++++--- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/Server.js b/lib/Server.js index 312bfeea4b..8301581d01 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -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" )(); @@ -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" )(); diff --git a/test/e2e/__snapshots__/api.test.js.snap.webpack4 b/test/e2e/__snapshots__/api.test.js.snap.webpack4 index 4192afa46f..092e5ef6e8 100644 --- a/test/e2e/__snapshots__/api.test.js.snap.webpack4 +++ b/test/e2e/__snapshots__/api.test.js.snap.webpack4 @@ -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.", @@ -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 [ diff --git a/test/e2e/__snapshots__/api.test.js.snap.webpack5 b/test/e2e/__snapshots__/api.test.js.snap.webpack5 index 4192afa46f..092e5ef6e8 100644 --- a/test/e2e/__snapshots__/api.test.js.snap.webpack5 +++ b/test/e2e/__snapshots__/api.test.js.snap.webpack5 @@ -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.", @@ -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 [ diff --git a/test/e2e/api.test.js b/test/e2e/api.test.js index 5294625e78..6807932bb9 100644 --- a/test/e2e/api.test.js +++ b/test/e2e/api.test.js @@ -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"); @@ -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 () => {