Skip to content

Commit 2e85dd1

Browse files
authored
test: add assertion for deprecation warning message (#4095)
1 parent f97c9e2 commit 2e85dd1

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

test/e2e/__snapshots__/api.test.js.snap.webpack4

+6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ Array [
6464
]
6565
`;
6666

67+
exports[`API should work with deprecated API ('listen' and \`close\` methods): deprecation log 1`] = `"'listen' is deprecated. Please use async 'start' or 'startCallback' methods."`;
68+
6769
exports[`API should work with deprecated API ('listen' and \`close\` methods): page errors 1`] = `Array []`;
6870

6971
exports[`API should work with deprecated API (only compiler in constructor): console messages 1`] = `
@@ -75,6 +77,8 @@ Array [
7577
]
7678
`;
7779

80+
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."`;
81+
7882
exports[`API should work with deprecated API (only compiler in constructor): page errors 1`] = `Array []`;
7983

8084
exports[`API should work with deprecated API (the order of the arguments in the constructor): console messages 1`] = `
@@ -86,4 +90,6 @@ Array [
8690
]
8791
`;
8892

93+
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."`;
94+
8995
exports[`API should work with deprecated API (the order of the arguments in the constructor): page errors 1`] = `Array []`;

test/e2e/__snapshots__/api.test.js.snap.webpack5

+6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ Array [
6464
]
6565
`;
6666

67+
exports[`API should work with deprecated API ('listen' and \`close\` methods): deprecation log 1`] = `"'listen' is deprecated. Please use async 'start' or 'startCallback' methods."`;
68+
6769
exports[`API should work with deprecated API ('listen' and \`close\` methods): page errors 1`] = `Array []`;
6870

6971
exports[`API should work with deprecated API (only compiler in constructor): console messages 1`] = `
@@ -75,6 +77,8 @@ Array [
7577
]
7678
`;
7779

80+
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."`;
81+
7882
exports[`API should work with deprecated API (only compiler in constructor): page errors 1`] = `Array []`;
7983

8084
exports[`API should work with deprecated API (the order of the arguments in the constructor): console messages 1`] = `
@@ -86,4 +90,6 @@ Array [
8690
]
8791
`;
8892

93+
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."`;
94+
8995
exports[`API should work with deprecated API (the order of the arguments in the constructor): page errors 1`] = `Array []`;

test/e2e/api.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22

33
const path = require("path");
4+
const util = require("util");
45
const webpack = require("webpack");
56
const Server = require("../../lib/Server");
67
const config = require("../fixtures/client-config/webpack.config");
@@ -206,6 +207,7 @@ describe("API", () => {
206207
it("should work with deprecated API ('listen' and `close` methods)", async () => {
207208
const compiler = webpack(config);
208209
const devServerOptions = { port };
210+
const utilSpy = jest.spyOn(util, "deprecate");
209211
const server = new Server(devServerOptions, compiler);
210212

211213
await new Promise((resolve, reject) => {
@@ -237,11 +239,13 @@ describe("API", () => {
237239
waitUntil: "networkidle0",
238240
});
239241

242+
expect(utilSpy.mock.calls[0][1]).toMatchSnapshot("deprecation log");
240243
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
241244
"console messages"
242245
);
243246
expect(pageErrors).toMatchSnapshot("page errors");
244247

248+
utilSpy.mockRestore();
245249
await browser.close();
246250
await new Promise((resolve) => {
247251
server.close(() => {
@@ -253,6 +257,7 @@ describe("API", () => {
253257
it(`should work with deprecated API (the order of the arguments in the constructor)`, async () => {
254258
const compiler = webpack(config);
255259
const devServerOptions = { port };
260+
const utilSpy = jest.spyOn(util, "deprecate");
256261
const server = new Server(compiler, devServerOptions);
257262

258263
await server.start();
@@ -274,17 +279,21 @@ describe("API", () => {
274279
waitUntil: "networkidle0",
275280
});
276281

282+
expect(utilSpy.mock.calls[0][1]).toMatchSnapshot("deprecation log");
283+
277284
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
278285
"console messages"
279286
);
280287
expect(pageErrors).toMatchSnapshot("page errors");
281288

289+
utilSpy.mockRestore();
282290
await browser.close();
283291
await server.stop();
284292
});
285293

286294
it(`should work with deprecated API (only compiler in constructor)`, async () => {
287295
const compiler = webpack(config);
296+
const utilSpy = jest.spyOn(util, "deprecate");
288297
const server = new Server(compiler);
289298

290299
server.options.port = port;
@@ -308,11 +317,13 @@ describe("API", () => {
308317
waitUntil: "networkidle0",
309318
});
310319

320+
expect(utilSpy.mock.calls[0][1]).toMatchSnapshot("deprecation log");
311321
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
312322
"console messages"
313323
);
314324
expect(pageErrors).toMatchSnapshot("page errors");
315325

326+
utilSpy.mockRestore();
316327
await browser.close();
317328
await server.stop();
318329
});

0 commit comments

Comments
 (0)