From 68f871ae41ea8646be3fa2071fa6ea18eb2600e5 Mon Sep 17 00:00:00 2001 From: Roman Kuznetsov Date: Wed, 9 Sep 2026 21:57:05 +0300 Subject: [PATCH] fix: print profiler reports to stderr --- src/profiler/output/console.ts | 2 +- test/src/profiler/output/console.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/profiler/output/console.ts b/src/profiler/output/console.ts index ae150b333..d2d81ed0e 100644 --- a/src/profiler/output/console.ts +++ b/src/profiler/output/console.ts @@ -8,7 +8,7 @@ export interface ProfilerConsole { } const defaultConsole: ProfilerConsole = { - log: message => console.log(message), + log: message => console.error(message), warn: message => console.warn(message), }; diff --git a/test/src/profiler/output/console.ts b/test/src/profiler/output/console.ts index 0ed44635b..f29e74245 100644 --- a/test/src/profiler/output/console.ts +++ b/test/src/profiler/output/console.ts @@ -1,12 +1,16 @@ import chalk from "chalk"; +import sinon from "sinon"; import { printProfilerResult } from "src/profiler/output/console"; import type { Finding, ProcessRef, ProfilerConfidence, ProfilerResultV1, RetainedOperation } from "src/profiler/schema"; describe("profiler/output/console", () => { + const sandbox = sinon.createSandbox(); const ansiPattern = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g"); const withoutColors = (value: string): string => value.replace(ansiPattern, ""); + afterEach(() => sandbox.restore()); + const finding = ( analyzerId: string, confidence: ProfilerConfidence, @@ -135,6 +139,17 @@ describe("profiler/output/console", () => { } }; + it("should print the default report to stderr", () => { + const stdout = sandbox.stub(console, "log"); + const stderr = sandbox.stub(console, "error"); + + printProfilerResult(makeResult()); + + assert.notCalled(stdout); + assert.calledOnce(stderr); + assert.match(stderr.firstCall.args[0], /^\[profiler] Test run profile/); + }); + it("should print one aligned report with phase and slow-test tables", () => { const durationMs = 246_000; const session = finding("session-concurrency-v1", "high", 183_000, "chrome", 194);