From fdbe98154eb66af42c34467d7f755c47d4e846a8 Mon Sep 17 00:00:00 2001 From: "M.Schirmer" Date: Fri, 12 Jun 2026 17:59:09 +0200 Subject: [PATCH] catch output and show them within the detail view --- reporter/test_samurai_vitest_reporter.mjs | 27 +++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/reporter/test_samurai_vitest_reporter.mjs b/reporter/test_samurai_vitest_reporter.mjs index 32e172c..8b3e197 100644 --- a/reporter/test_samurai_vitest_reporter.mjs +++ b/reporter/test_samurai_vitest_reporter.mjs @@ -19,12 +19,30 @@ const RESULT_PREFIX = 'TSAMURAI_RESULT '; export default class TestSamuraiVitestReporter { + constructor() { + this._consoleLogs = new Map(); + } + + onUserConsoleLog(log) { + if (!log.taskId) return; + if (!this._consoleLogs.has(log.taskId)) { + this._consoleLogs.set(log.taskId, []); + } + const lines = log.content.split('\n'); + for (const line of lines) { + if (line !== '') { + this._consoleLogs.get(log.taskId).push(line); + } + } + } + onTestCaseResult(testCase) { const name = buildListingName(testCase); const status = mapStatus(testCase.task); if (!status) return; - const output = buildOutput(testCase.task); + const consoleLogs = this._consoleLogs.get(testCase.task?.id) ?? []; + const output = buildOutput(testCase.task, consoleLogs); const payload = { name, @@ -69,10 +87,11 @@ function mapStatus(task) { } /** - * Collects error messages and stack traces for failed tests. + * Collects console logs and error messages/stack traces for tests. + * Console logs appear first, then error details. */ -function buildOutput(task) { - const lines = []; +function buildOutput(task, consoleLogs = []) { + const lines = [...consoleLogs]; if (!task) return lines; const errors = task.result?.errors ?? []; for (const err of errors) {