Skip to content

Commit 9890a76

Browse files
committed
chore: more tests
1 parent 31535d1 commit 9890a76

File tree

2 files changed

+171
-0
lines changed

2 files changed

+171
-0
lines changed

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,55 @@
11
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

3+
exports[`logging plugin mode should work and do not log messages about hot and live reloading is enabled 1`] = `
4+
[
5+
"[webpack-dev-server] Server started: Hot Module Replacement disabled, Live Reloading disabled, Progress disabled, Overlay enabled.",
6+
"Hey.",
7+
]
8+
`;
9+
10+
exports[`logging plugin mode should work and log errors by default 1`] = `
11+
[
12+
"[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.",
13+
"[HMR] Waiting for update signal from WDS...",
14+
"Hey.",
15+
"[webpack-dev-server] Errors while compiling. Reload prevented.",
16+
"[webpack-dev-server] ERROR
17+
Error from compilation",
18+
]
19+
`;
20+
21+
exports[`logging plugin mode should work and log message about live reloading is enabled 1`] = `
22+
[
23+
"[webpack-dev-server] Server started: Hot Module Replacement disabled, Live Reloading enabled, Progress disabled, Overlay enabled.",
24+
"Hey.",
25+
]
26+
`;
27+
28+
exports[`logging plugin mode should work and log messages about hot and live reloading is enabled 1`] = `
29+
[
30+
"[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.",
31+
"[HMR] Waiting for update signal from WDS...",
32+
"Hey.",
33+
]
34+
`;
35+
36+
exports[`logging plugin mode should work and log warnings by default 1`] = `
37+
[
38+
"[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.",
39+
"[HMR] Waiting for update signal from WDS...",
40+
"Hey.",
41+
"[webpack-dev-server] Warnings while compiling.",
42+
"[webpack-dev-server] WARNING
43+
Warning from compilation",
44+
]
45+
`;
46+
47+
exports[`logging plugin mode should work when the "client.logging" is "none" 1`] = `
48+
[
49+
"Hey.",
50+
]
51+
`;
52+
353
exports[`logging should work and do not log messages about hot and live reloading is enabled (ws) 1`] = `
454
[
555
"[webpack-dev-server] Server started: Hot Module Replacement disabled, Live Reloading disabled, Progress disabled, Overlay enabled.",

test/e2e/logging.test.js

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const fs = require("graceful-fs");
55
const webpack = require("webpack");
66
const Server = require("../../lib/Server");
77
const config = require("../fixtures/client-config/webpack.config");
8+
const compile = require("../helpers/compile");
89
const HTMLGeneratorPlugin = require("../helpers/html-generator-plugin");
910
const runBrowser = require("../helpers/run-browser");
1011
const port = require("../ports-map").logging;
@@ -241,4 +242,124 @@ describe("logging", () => {
241242
});
242243
}
243244
}
245+
246+
describe("plugin mode", () => {
247+
const pluginCases = [
248+
{
249+
title:
250+
"should work and log messages about hot and live reloading is enabled",
251+
devServerOptions: {
252+
hot: true,
253+
},
254+
},
255+
{
256+
title: "should work and log message about live reloading is enabled",
257+
devServerOptions: {
258+
hot: false,
259+
},
260+
},
261+
{
262+
title:
263+
"should work and do not log messages about hot and live reloading is enabled",
264+
devServerOptions: {
265+
liveReload: false,
266+
hot: false,
267+
},
268+
},
269+
{
270+
title: "should work and log warnings by default",
271+
webpackOptions: {
272+
plugins: [
273+
{
274+
apply(compiler) {
275+
compiler.hooks.thisCompilation.tap(
276+
"warnings-webpack-plugin",
277+
(compilation) => {
278+
compilation.warnings.push(
279+
new Error("Warning from compilation"),
280+
);
281+
},
282+
);
283+
},
284+
},
285+
new HTMLGeneratorPlugin(),
286+
],
287+
},
288+
},
289+
{
290+
title: "should work and log errors by default",
291+
webpackOptions: {
292+
plugins: [
293+
{
294+
apply(compiler) {
295+
compiler.hooks.thisCompilation.tap(
296+
"warnings-webpack-plugin",
297+
(compilation) => {
298+
compilation.errors.push(
299+
new Error("Error from compilation"),
300+
);
301+
},
302+
);
303+
},
304+
},
305+
new HTMLGeneratorPlugin(),
306+
],
307+
},
308+
},
309+
{
310+
title: 'should work when the "client.logging" is "none"',
311+
devServerOptions: {
312+
client: {
313+
logging: "none",
314+
},
315+
},
316+
},
317+
];
318+
319+
for (const testCase of pluginCases) {
320+
it(`${testCase.title}`, async () => {
321+
const compiler = webpack({ ...config, ...testCase.webpackOptions });
322+
const devServerOptions = {
323+
port,
324+
...testCase.devServerOptions,
325+
};
326+
const server = new Server(devServerOptions);
327+
328+
server.apply(compiler);
329+
330+
await compile(compiler, port);
331+
332+
const { page, browser } = await runBrowser();
333+
334+
try {
335+
const consoleMessages = [];
336+
337+
page.on("console", (message) => {
338+
consoleMessages.push(message);
339+
});
340+
341+
await page.goto(`http://127.0.0.1:${port}/`, {
342+
waitUntil: "networkidle0",
343+
});
344+
345+
expect(
346+
consoleMessages.map((message) =>
347+
message
348+
.text()
349+
.replaceAll("\\", "/")
350+
.replaceAll(
351+
new RegExp(process.cwd().replaceAll("\\", "/"), "g"),
352+
"<cwd>",
353+
),
354+
),
355+
).toMatchSnapshot();
356+
} finally {
357+
await browser.close();
358+
await new Promise((resolve) => {
359+
compiler.close(resolve);
360+
});
361+
}
362+
});
363+
}
364+
});
244365
});

0 commit comments

Comments
 (0)