-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathstats.test.js
More file actions
143 lines (133 loc) · 3.81 KB
/
Copy pathstats.test.js
File metadata and controls
143 lines (133 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
const webpack = require('@rspack/core');
const { RspackDevServer: Server } = require('@rspack/dev-server');
const config = require('../fixtures/client-config/webpack.config');
const HTMLGeneratorPlugin = require('../helpers/html-generator-plugin');
const runBrowser = require('../helpers/run-browser');
const port = require('../helpers/ports-map').stats;
global.console.log = rs.fn();
describe('stats', () => {
const cases = [
{
title: 'should work when "stats" is not specified',
webpackOptions: {},
},
{
title: 'should work using "{}" value for the "stats" option',
webpackOptions: {
stats: {},
},
},
{
title: 'should work using "undefined" value for the "stats" option',
webpackOptions: {
// eslint-disable-next-line no-undefined
stats: undefined,
},
},
{
title: 'should work using "false" value for the "stats" option',
webpackOptions: {
stats: false,
},
},
{
title: 'should work using "errors-only" value for the "stats" option',
webpackOptions: {
stats: 'errors-only',
},
},
{
title:
'should work using "{ assets: false }" value for the "stats" option',
webpackOptions: {
stats: {
assets: false,
},
},
},
// TODO: support object `config.stats.colors`
// {
// title:
// 'should work using "{ assets: false }" value for the "stats" option',
// webpackOptions: {
// stats: {
// colors: {
// green: "\u001b[32m",
// },
// },
// },
// },
// `config.stats.warningsFilter` is deprecated in favor of config.ignoreWarnings
// {
// title:
// 'should work using "{ warningsFilter: \'test\' }" value for the "stats" option',
// webpackOptions: {
// plugins: [
// {
// apply(compiler) {
// compiler.hooks.thisCompilation.tap(
// "warnings-webpack-plugin",
// (compilation) => {
// compilation.warnings.push(
// new Error("Warning from compilation"),
// );
// },
// );
// },
// },
// new HTMLGeneratorPlugin(),
// ],
// stats: { warningsFilter: /Warning from compilation/ },
// },
// },
];
if (webpack.version.startsWith('5')) {
cases.push({
title: 'should work and respect the "ignoreWarnings" option',
webpackOptions: {
plugins: [
{
apply(compiler) {
compiler.hooks.thisCompilation.tap(
'warnings-webpack-plugin',
(compilation) => {
compilation.warnings.push(
new Error('Warning from compilation'),
);
},
);
},
},
new HTMLGeneratorPlugin(),
],
ignoreWarnings: [/Warning from compilation/],
},
});
}
for (const testCase of cases) {
it(testCase.title, async () => {
const compiler = webpack({ ...config, ...testCase.webpackOptions });
const devServerOptions = {
port,
};
const server = new Server(devServerOptions, compiler);
await server.start();
const { page, browser } = await runBrowser();
try {
const consoleMessages = [];
page.on('console', (message) => {
consoleMessages.push(message);
});
await page.goto(`http://localhost:${port}/`, {
waitUntil: 'networkidle0',
});
expect(
consoleMessages.map((message) => message.text()),
).toMatchSnapshot();
} finally {
await browser.close();
await server.stop();
}
});
}
});