diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e7c49a..c1c7cfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Fixed: `throwError` no longer throws when the logged messages are neither + warnings nor errors, as before 7.1.0 (#77). - Changed: dropped support for Node.js below 18. - Fixed: the summary now uses the singular form for a single error or warning (`1 error`, not `1 errors`). diff --git a/lib/reporter.js b/lib/reporter.js index 2de7040..106b81c 100644 --- a/lib/reporter.js +++ b/lib/reporter.js @@ -101,7 +101,7 @@ module.exports = function (opts = {}) { } function shouldThrowError() { - return opts.throwError || errorCount > 0; + return errorCount > 0 || (opts.throwError && warningCount > 0); } }, }; diff --git a/lib/reporter.test.js b/lib/reporter.test.js index 333ed79..fa7a2c4 100644 --- a/lib/reporter.test.js +++ b/lib/reporter.test.js @@ -136,6 +136,17 @@ test("reporter with throwError", () => { run({ throwError: true }, clone(simpleResult), { expectError: true }); }); +test("reporter with throwError does not throw on messages that are neither warnings nor errors", () => { + const { calls } = run( + { throwError: true, filter: () => true }, + { + messages: [{ type: "dependency", plugin: "foo", text: "foo dependency" }], + root: {}, + }, + ); + assert.equal(calls.length, 1); +}); + test("reporter with a file as source", () => { const { calls } = run( {},