use infrastructure-log file
This commit is contained in:
parent
18c3590b28
commit
157b420a1e
|
@ -2,25 +2,6 @@ const { describeCases } = require("./ConfigTestCases.template");
|
|||
|
||||
describeCases({
|
||||
name: "ConfigCacheTestCases",
|
||||
infrastructureLogErrors: {
|
||||
wasm: {
|
||||
// Can not compile wasm module
|
||||
["missing-wasm-experiment"]:
|
||||
/^Pack got invalid because of write to: Compilation\/modules.+wasm.wasm$/
|
||||
},
|
||||
parsing: {
|
||||
// Module parse failed
|
||||
context:
|
||||
/^Pack got invalid because of write to: Compilation\/modules|.+dump-file\.txt/
|
||||
},
|
||||
loaders: {
|
||||
// Error in loader
|
||||
options: [
|
||||
/^Pack got invalid because of write to: Compilation\/modules.+loaders[/\\]options[/\\]error1\.js$/,
|
||||
/^Pack got invalid because of write to: Compilation\/modules.+loaders[/\\]options[/\\]error2\.js$/
|
||||
]
|
||||
}
|
||||
},
|
||||
cache: {
|
||||
type: "filesystem",
|
||||
buildDependencies: {
|
||||
|
|
|
@ -17,7 +17,7 @@ const prepareOptions = require("./helpers/prepareOptions");
|
|||
const { parseResource } = require("../lib/util/identifier");
|
||||
const captureStdio = require("./helpers/captureStdio");
|
||||
const asModule = require("./helpers/asModule");
|
||||
const createInfrastructureLogErrorsChecker = require("./helpers/infrastructureLogErrors");
|
||||
const filterInfraStructureErrors = require("./helpers/infrastructureLogErrors");
|
||||
|
||||
const casesPath = path.join(__dirname, "configCases");
|
||||
const categories = fs.readdirSync(casesPath).map(cat => {
|
||||
|
@ -64,11 +64,6 @@ const describeCases = config => {
|
|||
// eslint-disable-next-line no-loop-func
|
||||
describe(category.name, () => {
|
||||
for (const testName of category.tests) {
|
||||
const infrastructureLogChecker = config.infrastructureLogErrors
|
||||
? createInfrastructureLogErrorsChecker(
|
||||
config.infrastructureLogErrors
|
||||
)
|
||||
: undefined;
|
||||
// eslint-disable-next-line no-loop-func
|
||||
describe(testName, function () {
|
||||
const testDirectory = path.join(casesPath, category.name, testName);
|
||||
|
@ -211,17 +206,25 @@ const describeCases = config => {
|
|||
)
|
||||
);
|
||||
}
|
||||
if (infrastructureLogChecker) {
|
||||
const error = infrastructureLogChecker.check(
|
||||
category.name,
|
||||
testName,
|
||||
infraStructureLog,
|
||||
{
|
||||
run: 1,
|
||||
options
|
||||
}
|
||||
);
|
||||
if (error) return done(error);
|
||||
const infrastructureLogErrors = filterInfraStructureErrors(
|
||||
infraStructureLog,
|
||||
{
|
||||
run: 1,
|
||||
options
|
||||
}
|
||||
);
|
||||
if (
|
||||
infrastructureLogErrors.length &&
|
||||
checkArrayExpectation(
|
||||
testDirectory,
|
||||
{ infrastructureLogs: infrastructureLogErrors },
|
||||
"infrastructureLog",
|
||||
"infrastructure-log",
|
||||
"InfrastructureLog",
|
||||
done
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (err) return handleFatalError(err, done);
|
||||
done();
|
||||
|
@ -272,17 +275,25 @@ const describeCases = config => {
|
|||
);
|
||||
}
|
||||
}
|
||||
if (infrastructureLogChecker) {
|
||||
const error = infrastructureLogChecker.check(
|
||||
category.name,
|
||||
testName,
|
||||
infraStructureLog,
|
||||
{
|
||||
run: 2,
|
||||
options
|
||||
}
|
||||
);
|
||||
if (error) return done(error);
|
||||
const infrastructureLogErrors = filterInfraStructureErrors(
|
||||
infraStructureLog,
|
||||
{
|
||||
run: 2,
|
||||
options
|
||||
}
|
||||
);
|
||||
if (
|
||||
infrastructureLogErrors.length &&
|
||||
checkArrayExpectation(
|
||||
testDirectory,
|
||||
{ infrastructureLogs: infrastructureLogErrors },
|
||||
"infrastructureLog",
|
||||
"infrastructure-log",
|
||||
"InfrastructureLog",
|
||||
done
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
done();
|
||||
});
|
||||
|
@ -355,17 +366,25 @@ const describeCases = config => {
|
|||
) {
|
||||
return;
|
||||
}
|
||||
if (infrastructureLogChecker) {
|
||||
const error = infrastructureLogChecker.check(
|
||||
category.name,
|
||||
testName,
|
||||
infraStructureLog,
|
||||
{
|
||||
run: 1,
|
||||
options
|
||||
}
|
||||
);
|
||||
if (error) return done(error);
|
||||
const infrastructureLogErrors = filterInfraStructureErrors(
|
||||
infraStructureLog,
|
||||
{
|
||||
run: 3,
|
||||
options
|
||||
}
|
||||
);
|
||||
if (
|
||||
infrastructureLogErrors.length &&
|
||||
checkArrayExpectation(
|
||||
testDirectory,
|
||||
{ infrastructureLogs: infrastructureLogErrors },
|
||||
"infrastructureLog",
|
||||
"infrastructure-log",
|
||||
"InfrastructureLog",
|
||||
done
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
let filesCount = 0;
|
||||
|
|
|
@ -11,7 +11,7 @@ const createLazyTestEnv = require("./helpers/createLazyTestEnv");
|
|||
const deprecationTracking = require("./helpers/deprecationTracking");
|
||||
const captureStdio = require("./helpers/captureStdio");
|
||||
const asModule = require("./helpers/asModule");
|
||||
const createInfrastructureLogErrorsChecker = require("./helpers/infrastructureLogErrors");
|
||||
const filterInfraStructureErrors = require("./helpers/infrastructureLogErrors");
|
||||
|
||||
const casesPath = path.join(__dirname, "cases");
|
||||
let categories = fs.readdirSync(casesPath);
|
||||
|
@ -70,11 +70,6 @@ const describeCases = config => {
|
|||
})
|
||||
.forEach(testName => {
|
||||
let infraStructureLog = [];
|
||||
const infrastructureLogChecker = config.infrastructureLogErrors
|
||||
? createInfrastructureLogErrorsChecker(
|
||||
config.infrastructureLogErrors
|
||||
)
|
||||
: undefined;
|
||||
|
||||
describe(testName, () => {
|
||||
const testDirectory = path.join(
|
||||
|
@ -245,17 +240,23 @@ const describeCases = config => {
|
|||
deprecationTracker();
|
||||
options.output.path = oldPath;
|
||||
if (err) return done(err);
|
||||
if (infrastructureLogChecker) {
|
||||
const error = infrastructureLogChecker.check(
|
||||
category.name,
|
||||
testName,
|
||||
infraStructureLog,
|
||||
{
|
||||
run: 1,
|
||||
options
|
||||
}
|
||||
);
|
||||
if (error) return done(error);
|
||||
const infrastructureLogErrors =
|
||||
filterInfraStructureErrors(infraStructureLog, {
|
||||
run: 1,
|
||||
options
|
||||
});
|
||||
if (
|
||||
infrastructureLogErrors.length &&
|
||||
checkArrayExpectation(
|
||||
testDirectory,
|
||||
{ infrastructureLogs: infrastructureLogErrors },
|
||||
"infrastructureLog",
|
||||
"infrastructure-log",
|
||||
"InfrastructureLog",
|
||||
done
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
done();
|
||||
});
|
||||
|
@ -277,17 +278,23 @@ const describeCases = config => {
|
|||
deprecationTracker();
|
||||
options.output.path = oldPath;
|
||||
if (err) return done(err);
|
||||
if (infrastructureLogChecker) {
|
||||
const error = infrastructureLogChecker.check(
|
||||
category.name,
|
||||
testName,
|
||||
infraStructureLog,
|
||||
{
|
||||
run: 2,
|
||||
options
|
||||
}
|
||||
);
|
||||
if (error) return done(error);
|
||||
const infrastructureLogErrors =
|
||||
filterInfraStructureErrors(infraStructureLog, {
|
||||
run: 2,
|
||||
options
|
||||
});
|
||||
if (
|
||||
infrastructureLogErrors.length &&
|
||||
checkArrayExpectation(
|
||||
testDirectory,
|
||||
{ infrastructureLogs: infrastructureLogErrors },
|
||||
"infrastructureLog",
|
||||
"infrastructure-log",
|
||||
"InfrastructureLog",
|
||||
done
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
done();
|
||||
});
|
||||
|
@ -306,17 +313,23 @@ const describeCases = config => {
|
|||
compiler.run((err, stats) => {
|
||||
const deprecations = deprecationTracker();
|
||||
if (err) return done(err);
|
||||
if (infrastructureLogChecker) {
|
||||
const error = infrastructureLogChecker.check(
|
||||
category.name,
|
||||
testName,
|
||||
infraStructureLog,
|
||||
{
|
||||
run: 3,
|
||||
options
|
||||
}
|
||||
);
|
||||
if (error) return done(error);
|
||||
const infrastructureLogErrors =
|
||||
filterInfraStructureErrors(infraStructureLog, {
|
||||
run: 3,
|
||||
options
|
||||
});
|
||||
if (
|
||||
infrastructureLogErrors.length &&
|
||||
checkArrayExpectation(
|
||||
testDirectory,
|
||||
{ infrastructureLogs: infrastructureLogErrors },
|
||||
"infrastructureLog",
|
||||
"infrastructure-log",
|
||||
"InfrastructureLog",
|
||||
done
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
compiler.close(err => {
|
||||
if (err) return done(err);
|
||||
|
|
|
@ -4,37 +4,6 @@ const { describeCases } = require("./TestCases.template");
|
|||
describe("TestCases", () => {
|
||||
describeCases({
|
||||
name: "cache pack",
|
||||
infrastructureLogErrors: {
|
||||
compile: {
|
||||
// Module build failed
|
||||
["error-hide-stack"]:
|
||||
/^Pack got invalid because of write to: Compilation\/modules.+loader\.js!$/
|
||||
},
|
||||
errors: {
|
||||
// load module failed, error in loader
|
||||
["load-module-error"]:
|
||||
/^Pack got invalid because of write to: Compilation\/modules|json.+error-loader\.js!/
|
||||
},
|
||||
json: {
|
||||
// Module build failed, not a valid JSON
|
||||
["import-assertions-type-json"]:
|
||||
/^Pack got invalid because of write to: Compilation\/modules|json.+json\/data\/poison$/
|
||||
},
|
||||
loaders: {
|
||||
// Module build failed
|
||||
["no-string"]:
|
||||
/^Pack got invalid because of write to: Compilation\/modules.+no-string[/\\]loader\.js!.+no-string[/\\]file\.js$/
|
||||
},
|
||||
large: {
|
||||
["big-assets"]:
|
||||
/^Pack got invalid because of write to: ResolverCachePlugin|normal|dependencyType=|esm|path=|.+|request=|\.\/large\/big-assets\/$/
|
||||
},
|
||||
parsing: {
|
||||
// Module parse failed
|
||||
context:
|
||||
/^Pack got invalid because of write to: Compilation\/modules|.+dump-file\.txt/
|
||||
}
|
||||
},
|
||||
cache: {
|
||||
type: "filesystem",
|
||||
buildDependencies: {
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = [
|
||||
/^Pack got invalid because of write to: Compilation\/modules.+loader\.js!$/
|
||||
];
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = [
|
||||
/^Pack got invalid because of write to: Compilation\/modules|json.+error-loader\.js!/
|
||||
];
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = [
|
||||
/^Pack got invalid because of write to: Compilation\/modules|json.+json\/data\/poison$/
|
||||
];
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = [
|
||||
/^Pack got invalid because of write to: ResolverCachePlugin|normal|dependencyType=|esm|path=|.+|request=|\.\/large\/big-assets\/$/
|
||||
];
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = [
|
||||
/^Pack got invalid because of write to: Compilation\/modules.+no-string[/\\]loader\.js!.+no-string[/\\]file\.js$/
|
||||
];
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = [
|
||||
/^Pack got invalid because of write to: Compilation\/modules|.+dump-file\.txt/
|
||||
];
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = [
|
||||
/^Pack got invalid because of write to: TerserWebpackPlugin|bundle0\.js$/
|
||||
];
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = [
|
||||
/^Pack got invalid because of write to: Compilation\/modules.+loaders[/\\]options[/\\]error1\.js$/
|
||||
];
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = [
|
||||
/^Pack got invalid because of write to: Compilation\/modules|.+dump-file\.txt/
|
||||
];
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = [
|
||||
/^Pack got invalid because of write to: RealContentHashPlugin|analyse|index\.html$/
|
||||
];
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = [
|
||||
/^Pack got invalid because of write to: Compilation\/modules.+wasm.wasm$/
|
||||
];
|
|
@ -12,68 +12,18 @@ const PERSISTENCE_CACHE_INVALIDATE_ERROR = (log, config) => {
|
|||
};
|
||||
const errorsFilter = [PERSISTENCE_CACHE_INVALIDATE_ERROR];
|
||||
|
||||
const checkErrors = (logs, config) => {
|
||||
/**
|
||||
* @param {string[]} logs logs
|
||||
* @param {object} config config
|
||||
* @returns {string[]} errors
|
||||
*/
|
||||
module.exports = function filterInfraStructureErrors(logs, config) {
|
||||
const results = [];
|
||||
for (const log of logs) {
|
||||
for (const filter of errorsFilter) {
|
||||
const result = filter(log, config);
|
||||
if (result) results.push(result);
|
||||
if (result) results.push({ message: result });
|
||||
}
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {{[k: string]: {[k: string]: RegExp|RegExp[]}}} config config
|
||||
* @returns {{check(category: string, test: string, log: string[], config: Object): Error|void, restErrors(): string[]}} checker
|
||||
*/
|
||||
module.exports = function createInfrastructureLogErrorsChecker(config) {
|
||||
const expectedInfrastructureErrorsMap = new Map();
|
||||
const restRegexps = new Set();
|
||||
for (const category of Object.keys(config)) {
|
||||
for (const testName of Object.keys(config[category])) {
|
||||
let byCategory = expectedInfrastructureErrorsMap.get(category);
|
||||
if (!byCategory) {
|
||||
byCategory = new Map();
|
||||
expectedInfrastructureErrorsMap.set(category, byCategory);
|
||||
}
|
||||
const regexps = config[category][testName];
|
||||
if (Array.isArray(regexps)) {
|
||||
for (const reg of regexps) restRegexps.add(reg);
|
||||
byCategory.set(testName, regexps.slice());
|
||||
} else {
|
||||
restRegexps.add(regexps);
|
||||
byCategory.set(testName, [regexps]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function check(category, testName, log, config) {
|
||||
let results = checkErrors(log, config);
|
||||
if (results.length === 0) return;
|
||||
|
||||
const byCategory = expectedInfrastructureErrorsMap.get(category);
|
||||
if (!byCategory) return new Error(results[0]);
|
||||
const filters = byCategory.get(testName);
|
||||
if (!filters) return new Error(results[0]);
|
||||
|
||||
for (const filter of filters) {
|
||||
let n = results.length;
|
||||
results = results.filter(r => !filter.test(r));
|
||||
if (n !== results.length) restRegexps.delete(filter);
|
||||
}
|
||||
|
||||
if (results.length !== 0) return new Error(results[0]);
|
||||
}
|
||||
|
||||
function restErrors() {
|
||||
if (restRegexps.size === 0) return [];
|
||||
// make deterministic result based on remaining regexps
|
||||
// not on config key order
|
||||
return Array.from(restRegexps)
|
||||
.map(r => r.toString())
|
||||
.sort()[0];
|
||||
}
|
||||
|
||||
return { check, restErrors };
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue