fix false detecting skipped tests
tests / test (push) Failing after 6s

This commit is contained in:
2026-06-12 12:13:29 +02:00
parent 770e49d98a
commit 279fc56ee5
3 changed files with 156 additions and 47 deletions
@@ -1,5 +1,5 @@
/**
* test_samurai_vitest_reporter.js
* test_samurai_vitest_reporter.mjs
*
* Custom Vitest 2.x reporter for test-samurai.
*
@@ -21,8 +21,10 @@ const RESULT_PREFIX = 'TSAMURAI_RESULT ';
export default class TestSamuraiVitestReporter {
onTestCaseResult(testCase) {
const name = buildListingName(testCase);
const status = mapStatus(testCase.result?.state);
const output = buildOutput(testCase);
const status = mapStatus(testCase.task);
if (!status) return;
const output = buildOutput(testCase.task);
const payload = {
name,
@@ -52,24 +54,27 @@ function buildListingName(testCase) {
}
/**
* Maps Vitest result states to test-samurai status strings.
* Maps Vitest task result states to test-samurai status strings.
* Falls back to task.mode if result.state is missing.
*/
function mapStatus(state) {
const map = {
pass: 'passed',
fail: 'failed',
skip: 'skipped',
todo: 'skipped',
};
return map[state] ?? 'skipped';
function mapStatus(task) {
if (!task) return null;
const state = task.result?.state;
if (state === 'pass') return 'passed';
if (state === 'fail') return 'failed';
if (state === 'skip') return 'skipped';
const mode = task.mode;
if (mode === 'skip' || mode === 'todo') return 'skipped';
return null;
}
/**
* Collects error messages and stack traces for failed tests.
*/
function buildOutput(testCase) {
function buildOutput(task) {
const lines = [];
const errors = testCase.result?.errors ?? [];
if (!task) return lines;
const errors = task.result?.errors ?? [];
for (const err of errors) {
if (typeof err.message === 'string' && err.message.length > 0) {
err.message.split('\n').forEach((line) => {