From 50776da09a2fc4394a0810a526a38331bbac7713 Mon Sep 17 00:00:00 2001 From: Max Thirouin Date: Fri, 9 Oct 2026 09:46:31 +0200 Subject: [PATCH] fix: only throw on warnings or errors with throwError Since 7.1.0, throwError made the reporter throw as soon as any message was logged, including messages that are neither warnings nor errors (e.g. a filter letting dependency messages through). Fixes #77 --- CHANGELOG.md | 2 ++ lib/reporter.js | 2 +- lib/reporter.test.js | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) 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( {},