From 2e85dd1dc41d2245d683b11ce3b345eb6f9e3c22 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Fri, 10 Dec 2021 16:40:55 +0530 Subject: [PATCH] test: add assertion for deprecation warning message (#4095) --- test/e2e/__snapshots__/api.test.js.snap.webpack4 | 6 ++++++ test/e2e/__snapshots__/api.test.js.snap.webpack5 | 6 ++++++ test/e2e/api.test.js | 11 +++++++++++ 3 files changed, 23 insertions(+) diff --git a/test/e2e/__snapshots__/api.test.js.snap.webpack4 b/test/e2e/__snapshots__/api.test.js.snap.webpack4 index b99c7ef97c..4192afa46f 100644 --- a/test/e2e/__snapshots__/api.test.js.snap.webpack4 +++ b/test/e2e/__snapshots__/api.test.js.snap.webpack4 @@ -64,6 +64,8 @@ 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): page errors 1`] = `Array []`; exports[`API should work with deprecated API (only compiler in constructor): console messages 1`] = ` @@ -75,6 +77,8 @@ Array [ ] `; +exports[`API should work with deprecated API (only compiler in constructor): deprecation log 1`] = `"Using 'compiler' as the first argument is deprecated. Please use 'options' as the first argument and 'compiler' as the second argument."`; + exports[`API should work with deprecated API (only compiler in constructor): page errors 1`] = `Array []`; exports[`API should work with deprecated API (the order of the arguments in the constructor): console messages 1`] = ` @@ -86,4 +90,6 @@ Array [ ] `; +exports[`API should work with deprecated API (the order of the arguments in the constructor): deprecation log 1`] = `"Using 'compiler' as the first argument is deprecated. Please use 'options' as the first argument and 'compiler' as the second argument."`; + exports[`API should work with deprecated API (the order of the arguments in the constructor): page errors 1`] = `Array []`; diff --git a/test/e2e/__snapshots__/api.test.js.snap.webpack5 b/test/e2e/__snapshots__/api.test.js.snap.webpack5 index b99c7ef97c..4192afa46f 100644 --- a/test/e2e/__snapshots__/api.test.js.snap.webpack5 +++ b/test/e2e/__snapshots__/api.test.js.snap.webpack5 @@ -64,6 +64,8 @@ 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): page errors 1`] = `Array []`; exports[`API should work with deprecated API (only compiler in constructor): console messages 1`] = ` @@ -75,6 +77,8 @@ Array [ ] `; +exports[`API should work with deprecated API (only compiler in constructor): deprecation log 1`] = `"Using 'compiler' as the first argument is deprecated. Please use 'options' as the first argument and 'compiler' as the second argument."`; + exports[`API should work with deprecated API (only compiler in constructor): page errors 1`] = `Array []`; exports[`API should work with deprecated API (the order of the arguments in the constructor): console messages 1`] = ` @@ -86,4 +90,6 @@ Array [ ] `; +exports[`API should work with deprecated API (the order of the arguments in the constructor): deprecation log 1`] = `"Using 'compiler' as the first argument is deprecated. Please use 'options' as the first argument and 'compiler' as the second argument."`; + exports[`API should work with deprecated API (the order of the arguments in the constructor): page errors 1`] = `Array []`; diff --git a/test/e2e/api.test.js b/test/e2e/api.test.js index f11896592b..5294625e78 100644 --- a/test/e2e/api.test.js +++ b/test/e2e/api.test.js @@ -1,6 +1,7 @@ "use strict"; const path = require("path"); +const util = require("util"); const webpack = require("webpack"); const Server = require("../../lib/Server"); const config = require("../fixtures/client-config/webpack.config"); @@ -206,6 +207,7 @@ describe("API", () => { it("should work with deprecated API ('listen' and `close` methods)", async () => { const compiler = webpack(config); const devServerOptions = { port }; + const utilSpy = jest.spyOn(util, "deprecate"); const server = new Server(devServerOptions, compiler); await new Promise((resolve, reject) => { @@ -237,11 +239,13 @@ describe("API", () => { waitUntil: "networkidle0", }); + expect(utilSpy.mock.calls[0][1]).toMatchSnapshot("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(() => { @@ -253,6 +257,7 @@ describe("API", () => { it(`should work with deprecated API (the order of the arguments in the constructor)`, async () => { const compiler = webpack(config); const devServerOptions = { port }; + const utilSpy = jest.spyOn(util, "deprecate"); const server = new Server(compiler, devServerOptions); await server.start(); @@ -274,17 +279,21 @@ describe("API", () => { waitUntil: "networkidle0", }); + expect(utilSpy.mock.calls[0][1]).toMatchSnapshot("deprecation log"); + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( "console messages" ); expect(pageErrors).toMatchSnapshot("page errors"); + utilSpy.mockRestore(); await browser.close(); await server.stop(); }); it(`should work with deprecated API (only compiler in constructor)`, async () => { const compiler = webpack(config); + const utilSpy = jest.spyOn(util, "deprecate"); const server = new Server(compiler); server.options.port = port; @@ -308,11 +317,13 @@ describe("API", () => { waitUntil: "networkidle0", }); + expect(utilSpy.mock.calls[0][1]).toMatchSnapshot("deprecation log"); expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( "console messages" ); expect(pageErrors).toMatchSnapshot("page errors"); + utilSpy.mockRestore(); await browser.close(); await server.stop(); });