Skip to content

Commit

Permalink
Merge pull request #15389 from webpack/refactor/use-infrastructure-lo…
Browse files Browse the repository at this point in the history
…g-file

refactoring: use infrastructure-log file
  • Loading branch information
sokra committed Feb 22, 2022
2 parents 378d8c8 + 500c74a commit 8d509e3
Show file tree
Hide file tree
Showing 16 changed files with 150 additions and 181 deletions.
19 changes: 0 additions & 19 deletions test/ConfigCacheTestCases.longtest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
97 changes: 58 additions & 39 deletions test/ConfigTestCases.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -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;
Expand Down
91 changes: 52 additions & 39 deletions test/TestCases.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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();
});
Expand All @@ -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();
});
Expand All @@ -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);
Expand Down
27 changes: 0 additions & 27 deletions test/TestCasesCachePack.longtest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +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$/
},
parsing: {
// Module parse failed
context:
/^Pack got invalid because of write to: Compilation\/modules|.+dump-file\.txt/
}
},
cache: {
type: "filesystem",
buildDependencies: {
Expand Down
3 changes: 3 additions & 0 deletions test/cases/compile/error-hide-stack/infrastructure-log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = [
/^Pack got invalid because of write to: Compilation\/modules.+loader\.js!$/
];
3 changes: 3 additions & 0 deletions test/cases/errors/load-module-error/infrastructure-log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = [
/^Pack got invalid because of write to: Compilation\/modules|json.+error-loader\.js!/
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = [
/^Pack got invalid because of write to: Compilation\/modules|json.+json\/data\/poison$/
];
3 changes: 3 additions & 0 deletions test/cases/large/big-assets/infrastructure-log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = [
/^Pack got invalid because of write to: ResolverCachePlugin|normal|dependencyType=|esm|path=|.+|request=|\.\/large\/big-assets\/$/
];
3 changes: 3 additions & 0 deletions test/cases/loaders/no-string/infrastructure-log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = [
/^Pack got invalid because of write to: Compilation\/modules.+no-string[/\\]loader\.js!.+no-string[/\\]file\.js$/
];
3 changes: 3 additions & 0 deletions test/cases/parsing/context/infrastructure-log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = [
/^Pack got invalid because of write to: Compilation\/modules|.+dump-file\.txt/
];
3 changes: 3 additions & 0 deletions test/configCases/assets/delete-asset/infrastructure-log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = [
/^Pack got invalid because of write to: TerserWebpackPlugin|bundle0\.js$/
];
3 changes: 3 additions & 0 deletions test/configCases/loaders/options/infrastructure-log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = [
/^Pack got invalid because of write to: Compilation\/modules.+loaders[/\\]options[/\\]error1\.js$/
];
3 changes: 3 additions & 0 deletions test/configCases/parsing/context/infrastructure-log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = [
/^Pack got invalid because of write to: Compilation\/modules|.+dump-file\.txt/
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = [
/^Pack got invalid because of write to: RealContentHashPlugin|analyse|index\.html$/
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = [
/^Pack got invalid because of write to: Compilation\/modules.+wasm.wasm$/
];

0 comments on commit 8d509e3

Please sign in to comment.