Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Stats): recursively get warnings or errors of a stats and its children #11438

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions lib/Stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"use strict";

/** @typedef {import("./Compilation")} Compilation */
/** @typedef {import("./WebpackError")} WebpackError */

class Stats {
/**
Expand Down Expand Up @@ -37,6 +38,18 @@ class Stats {
);
}

/**
* @returns {WebpackError[]} array of warnings occurred in this stats or its children
*/
getWarnings() {
return [].concat(
...this.compilation.warnings,
...this.compilation.children
.filter(child => child.getStats().hasWarnings())
.map(child => child.getStats().getWarnings())
);
}

/**
* @returns {boolean} true if the compilation encountered an error
*/
Expand All @@ -47,6 +60,18 @@ class Stats {
);
}

/**
* @returns {WebpackError[]} array of errors occurred in this stats or its children
*/
getErrors() {
return [].concat(
...this.compilation.errors,
...this.compilation.children
.filter(child => child.getStats().hasErrors())
.map(child => child.getStats().getErrors())
);
}

toJson(options) {
options = this.compilation.createStatsOptions(options, {
forToString: false
Expand Down
8 changes: 7 additions & 1 deletion test/StatsTestCases.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,14 @@ describe("StatsTestCases", () => {
});
c.run((err, stats) => {
if (err) return done(err);
if (/error$/.test(testName)) {
// the number at the end is the count of errors occurred in the test case
// it's ok if the number is not given
if (/error$/.test(testName) || /(error-)(\d+)$/.test(testName)) {
expect(stats.hasErrors()).toBe(true);
const found = testName.match(/(error-)(\d+)$/);
if (found) {
expect(stats.getErrors().length).toEqual(parseInt(found[2], 10));
}
} else if (stats.hasErrors()) {
return done(
new Error(
Expand Down
File renamed without changes.
File renamed without changes.