From 7f1c5f2378ee6a8a44d2a8fa7ecd38fe89e88ca9 Mon Sep 17 00:00:00 2001 From: Bart Veneman Date: Mon, 3 Nov 2025 21:05:54 +0100 Subject: [PATCH] fix: make sure errors get logged to `stderr` --- src/cli/cli.ts | 4 ++-- src/cli/reporters/pretty.ts | 4 +++- src/cli/reporters/tap.ts | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cli/cli.ts b/src/cli/cli.ts index 30f189d..a4a10e8 100644 --- a/src/cli/cli.ts +++ b/src/cli/cli.ts @@ -25,8 +25,8 @@ async function cli(cli_args: string[]) { return tap(report, params) } if (params.reporter === 'json') { - // oxlint-disable-next-line no-null - return console.log(JSON.stringify(report)) + let log = JSON.stringify(report) + return report.report.ok ? console.log(log) : console.error(log) } return pretty(report, params) } diff --git a/src/cli/reporters/pretty.ts b/src/cli/reporters/pretty.ts index 85cac63..d38f081 100644 --- a/src/cli/reporters/pretty.ts +++ b/src/cli/reporters/pretty.ts @@ -109,7 +109,9 @@ export function print_lines({ report, context }: Report, params: CliArguments, { } export function print(report: Report, params: CliArguments): void { + let logger = report.report.ok ? console.log : console.error + for (let line of print_lines(report, params, { styleText, print_width: process.stdout.columns })) { - console.log(line) + logger(line) } } diff --git a/src/cli/reporters/tap.ts b/src/cli/reporters/tap.ts index 1b6288b..173a1c1 100644 --- a/src/cli/reporters/tap.ts +++ b/src/cli/reporters/tap.ts @@ -14,7 +14,7 @@ function ok(n: number, description?: string) { } function not_ok(n: number, description?: string) { - console.log(`not ok ${n} ${description ? `- ${description}` : ''}`) + console.error(`not ok ${n} ${description ? `- ${description}` : ''}`) } function meta(data: Record) {