Skip to content

Commit 1e7acc5

Browse files
committed
refactor infrastructure log functionality
1 parent 26a1916 commit 1e7acc5

5 files changed

Lines changed: 215 additions & 244 deletions

File tree

test/ConfigCacheTestCases.longtest.js

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,35 @@
1-
const { describeCases, logErrors } = require("./ConfigTestCases.template");
1+
const { describeCases } = require("./ConfigTestCases.template");
22

33
describeCases({
44
name: "ConfigCacheTestCases",
55
infrastructureLogErrors: {
6-
allowList: [
7-
{
8-
// Pack got invalid because of write to: Compilation/modules|/home/runner/work/webpack/webpack/test/configCases/wasm/missing-wasm-experiment/wasm.wasm
9-
category: "wasm",
10-
test: "missing-wasm-experiment"
11-
},
12-
{
13-
// Pack got invalid because of write to: RealContentHashPlugin|analyse|index.html
14-
category: "process-assets",
15-
test: "html-plugin"
16-
},
17-
{
18-
// Pack got invalid because of write to: Compilation/modules|/home/runner/work/webpack/webpack/test/cases/parsing/context/templates/dump-file.txt
19-
category: "parsing",
20-
test: "context"
21-
},
22-
{
23-
// Pack got invalid because of write to: Compilation/modules|/home/runner/work/webpack/webpack/test/configCases/loaders/options/loader-1.js??ruleSet[1].rules[9]!/home/runner/work/webpack/webpack/test/configCases/loaders/options/error1.js
24-
category: "loaders",
25-
test: "options"
26-
},
27-
{
28-
// Pack got invalid because of write to: TerserWebpackPlugin|bundle0.js
29-
category: "assets",
30-
test: "delete-asset"
31-
},
32-
{
33-
// Pack got invalid because of write to: webpack.HttpUriPlugin|https://raw.githubusercontent.com//webpack//webpack//main/CODE_OF_CONDUCT.md
34-
category: "asset-modules",
35-
test: "http-url"
36-
}
37-
],
38-
filter: [logErrors.PERSISTENCE_CACHE_INVALIDATE_ERROR]
6+
wasm: {
7+
// Can not compile wasm module
8+
["missing-wasm-experiment"]:
9+
/^Pack got invalid because of write to: Compilation\/modules.+wasm.wasm$/
10+
},
11+
["process-assets"]: {
12+
["html-plugin"]:
13+
/^Pack got invalid because of write to: RealContentHashPlugin|analyse|index.html$/
14+
},
15+
parsing: {
16+
// Module parse failed
17+
context:
18+
/^Pack got invalid because of write to: Compilation\/modules|.+dump-file\.txt/
19+
},
20+
loaders: {
21+
// Error in loader
22+
options:
23+
/^Pack got invalid because of write to: Compilation\/modules.+loaders\/options\/error1\.js$/
24+
},
25+
assets: {
26+
["delete-asset"]:
27+
/^Pack got invalid because of write to: TerserWebpackPlugin|bundle0.js$/
28+
},
29+
["asset-modules"]: {
30+
["http-url"]:
31+
/^Pack got invalid because of write to: webpack\.HttpUriPlugin|https:\/\/raw.githubusercontent.com\/\/webpack\/\/webpack\/\/main\/CODE_OF_CONDUCT\.md$/
32+
}
3933
},
4034
cache: {
4135
type: "filesystem",

test/ConfigTestCases.template.js

Lines changed: 39 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,7 @@ const prepareOptions = require("./helpers/prepareOptions");
1717
const { parseResource } = require("../lib/util/identifier");
1818
const captureStdio = require("./helpers/captureStdio");
1919
const asModule = require("./helpers/asModule");
20-
21-
const PERSISTENCE_CACHE_INVALIDATE_ERROR = (log, config) => {
22-
if (config.run < 2) return;
23-
const match =
24-
/^\[webpack\.cache\.PackFileCacheStrategy\] Pack got invalid because of write to:(.+)$/.exec(
25-
log
26-
);
27-
if (match) {
28-
return `Pack got invalid because of write to: ${match[1].trim()}`;
29-
}
30-
};
20+
const createInfrastructureLogErrorsChecker = require("./helpers/infrastructureLogErrors");
3121

3222
const casesPath = path.join(__dirname, "configCases");
3323
const categories = fs.readdirSync(casesPath).map(cat => {
@@ -59,34 +49,7 @@ const createLogger = appendTarget => {
5949
};
6050
};
6151

62-
const returnLogError = (logs, errorsFilter, config) => {
63-
for (const log of logs) {
64-
for (const filter of errorsFilter) {
65-
const result = filter(log, config);
66-
if (result) {
67-
return new Error(result);
68-
}
69-
}
70-
}
71-
};
72-
7352
const describeCases = config => {
74-
let allowErrorsMap;
75-
if (config.infrastructureLogErrors) {
76-
allowErrorsMap = new Map();
77-
if (config.infrastructureLogErrors.allowList) {
78-
for (const { category, test } of config.infrastructureLogErrors
79-
.allowList) {
80-
let byCategory = allowErrorsMap.get(category);
81-
if (!byCategory) {
82-
byCategory = new Set();
83-
allowErrorsMap.set(category, byCategory);
84-
}
85-
byCategory.add(test);
86-
}
87-
}
88-
}
89-
9053
describe(config.name, () => {
9154
let stderr;
9255
beforeEach(() => {
@@ -101,11 +64,11 @@ const describeCases = config => {
10164
// eslint-disable-next-line no-loop-func
10265
describe(category.name, () => {
10366
for (const testName of category.tests) {
104-
const inAllowErrorsList = () => {
105-
const byCategory = allowErrorsMap.get(category.name);
106-
if (!byCategory) return false;
107-
return byCategory.has(testName);
108-
};
67+
const infrastructureLogChecker = config.infrastructureLogErrors
68+
? createInfrastructureLogErrorsChecker(
69+
config.infrastructureLogErrors
70+
)
71+
: undefined;
10972
// eslint-disable-next-line no-loop-func
11073
describe(testName, function () {
11174
const testDirectory = path.join(casesPath, category.name, testName);
@@ -248,20 +211,17 @@ const describeCases = config => {
248211
)
249212
);
250213
}
251-
if (config.infrastructureLogErrors) {
252-
if (!inAllowErrorsList()) {
253-
const error = returnLogError(
254-
infraStructureLog,
255-
Array.isArray(config.infrastructureLogErrors.filter)
256-
? config.infrastructureLogErrors.filter
257-
: [config.infrastructureLogErrors.filter],
258-
{
259-
run: 1,
260-
options
261-
}
262-
);
263-
if (error) return done(error);
264-
}
214+
if (infrastructureLogChecker) {
215+
const error = infrastructureLogChecker.check(
216+
category.name,
217+
testName,
218+
infraStructureLog,
219+
{
220+
run: 1,
221+
options
222+
}
223+
);
224+
if (error) return done(error);
265225
}
266226
if (err) return handleFatalError(err, done);
267227
done();
@@ -312,20 +272,17 @@ const describeCases = config => {
312272
);
313273
}
314274
}
315-
if (config.infrastructureLogErrors) {
316-
if (!inAllowErrorsList()) {
317-
const error = returnLogError(
318-
infraStructureLog,
319-
Array.isArray(config.infrastructureLogErrors.filter)
320-
? config.infrastructureLogErrors.filter
321-
: [config.infrastructureLogErrors.filter],
322-
{
323-
run: 2,
324-
options
325-
}
326-
);
327-
if (error) return done(error);
328-
}
275+
if (infrastructureLogChecker) {
276+
const error = infrastructureLogChecker.check(
277+
category.name,
278+
testName,
279+
infraStructureLog,
280+
{
281+
run: 2,
282+
options
283+
}
284+
);
285+
if (error) return done(error);
329286
}
330287
done();
331288
});
@@ -398,20 +355,17 @@ const describeCases = config => {
398355
) {
399356
return;
400357
}
401-
if (config.infrastructureLogErrors) {
402-
if (!inAllowErrorsList()) {
403-
const error = returnLogError(
404-
infraStructureLog,
405-
Array.isArray(config.infrastructureLogErrors.filter)
406-
? config.infrastructureLogErrors.filter
407-
: [config.infrastructureLogErrors.filter],
408-
{
409-
run: 3,
410-
options
411-
}
412-
);
413-
if (error) return done(error);
414-
}
358+
if (infrastructureLogChecker) {
359+
const error = infrastructureLogChecker.check(
360+
category.name,
361+
testName,
362+
infraStructureLog,
363+
{
364+
run: 1,
365+
options
366+
}
367+
);
368+
if (error) return done(error);
415369
}
416370

417371
let filesCount = 0;
@@ -738,6 +692,3 @@ const describeCases = config => {
738692
};
739693

740694
exports.describeCases = describeCases;
741-
exports.logErrors = {
742-
PERSISTENCE_CACHE_INVALIDATE_ERROR
743-
};

0 commit comments

Comments
 (0)