Skip to content

Commit

Permalink
test: add assertion for deprecation warning message (#4095)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 authored Dec 10, 2021
1 parent f97c9e2 commit 2e85dd1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/e2e/__snapshots__/api.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -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`] = `
Expand All @@ -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`] = `
Expand All @@ -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 []`;
6 changes: 6 additions & 0 deletions test/e2e/__snapshots__/api.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -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`] = `
Expand All @@ -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`] = `
Expand All @@ -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 []`;
11 changes: 11 additions & 0 deletions test/e2e/api.test.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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(() => {
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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();
});
Expand Down

0 comments on commit 2e85dd1

Please sign in to comment.