Skip to content

Commit f371ae6

Browse files
committed
test: refactor test/e2e/states.test.js
WIP: will rename the test and clean it up after i received a feedback from maintainers
1 parent e690789 commit f371ae6

10 files changed

+152
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.","[HMR] Waiting for update signal from WDS...","Hey."]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.","[HMR] Waiting for update signal from WDS...","Hey."]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.","[HMR] Waiting for update signal from WDS...","Hey."]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.","[HMR] Waiting for update signal from WDS...","Hey."]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.","[HMR] Waiting for update signal from WDS...","Hey."]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.","[HMR] Waiting for update signal from WDS...","Hey."]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.","[HMR] Waiting for update signal from WDS...","Hey."]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.","[HMR] Waiting for update signal from WDS...","Hey."]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["[webpack-dev-server] Server started: Hot Module Replacement enabled, Live Reloading enabled, Progress disabled, Overlay enabled.","[HMR] Waiting for update signal from WDS...","Hey."]
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
"use strict";
2+
3+
const webpack = require("webpack");
4+
const Server = require("../../lib/Server");
5+
const config = require("../fixtures/client-config/webpack.config");
6+
const HTMLGeneratorPlugin = require("../helpers/html-generator-plugin");
7+
const port = require("../ports-map").stats;
8+
const { test } = require("@playwright/test");
9+
const { describe } = require("@playwright/test");
10+
const { expect } = require("@playwright/test");
11+
12+
describe("stats", () => {
13+
const cases = [
14+
{
15+
title: 'should work when "stats" is not specified',
16+
webpackOptions: {},
17+
},
18+
{
19+
title: 'should work using "{}" value for the "stats" option',
20+
webpackOptions: {
21+
stats: {},
22+
},
23+
},
24+
{
25+
title: 'should work using "undefined" value for the "stats" option',
26+
webpackOptions: {
27+
// eslint-disable-next-line no-undefined
28+
stats: undefined,
29+
},
30+
},
31+
{
32+
title: 'should work using "false" value for the "stats" option',
33+
webpackOptions: {
34+
stats: false,
35+
},
36+
},
37+
{
38+
title: 'should work using "errors-only" value for the "stats" option',
39+
webpackOptions: {
40+
stats: "errors-only",
41+
},
42+
},
43+
{
44+
title:
45+
'should work using "{ assets: false }" value for the "stats" option',
46+
webpackOptions: {
47+
stats: {
48+
assets: false,
49+
},
50+
},
51+
},
52+
{
53+
title:
54+
'should work using "{ colors: { green: "\u001b[32m" }}" value for the "stats" option',
55+
webpackOptions: {
56+
stats: {
57+
colors: {
58+
green: "\u001b[32m",
59+
},
60+
},
61+
},
62+
},
63+
{
64+
title:
65+
'should work using "{ warningsFilter: \'test\' }" value for the "stats" option',
66+
webpackOptions: {
67+
plugins: [
68+
{
69+
apply(compiler) {
70+
compiler.hooks.thisCompilation.tap(
71+
"warnings-webpack-plugin",
72+
(compilation) => {
73+
compilation.warnings.push(
74+
new Error("Warning from compilation"),
75+
);
76+
},
77+
);
78+
},
79+
},
80+
new HTMLGeneratorPlugin(),
81+
],
82+
stats: { warningsFilter: /Warning from compilation/ },
83+
},
84+
},
85+
];
86+
87+
if (webpack.version.startsWith("5")) {
88+
cases.push({
89+
title: 'should work and respect the "ignoreWarnings" option',
90+
webpackOptions: {
91+
plugins: [
92+
{
93+
apply(compiler) {
94+
compiler.hooks.thisCompilation.tap(
95+
"warnings-webpack-plugin",
96+
(compilation) => {
97+
compilation.warnings.push(
98+
new Error("Warning from compilation"),
99+
);
100+
},
101+
);
102+
},
103+
},
104+
new HTMLGeneratorPlugin(),
105+
],
106+
ignoreWarnings: [/Warning from compilation/],
107+
},
108+
});
109+
}
110+
111+
cases.forEach((testCase) => {
112+
test(testCase.title, async ({ page }) => {
113+
const compiler = webpack({ ...config, ...testCase.webpackOptions });
114+
const devServerOptions = {
115+
port,
116+
};
117+
const server = new Server(devServerOptions, compiler);
118+
119+
await server.start();
120+
121+
try {
122+
const consoleMessages = [];
123+
124+
page.on("console", (message) => {
125+
consoleMessages.push(message);
126+
});
127+
128+
await page.goto(`http://localhost:${port}/`, {
129+
waitUntil: "networkidle0",
130+
});
131+
132+
expect(
133+
JSON.stringify(consoleMessages.map((message) => message.text())),
134+
).toMatchSnapshot();
135+
} catch (error) {
136+
throw error;
137+
} finally {
138+
await server.stop();
139+
}
140+
})
141+
})
142+
143+
});

0 commit comments

Comments
 (0)