Files
portal/tools/enforce-verify-record.test.mjs
T
Дмитрий 64e962e330 fix(hooks): parse Pest JSON reporter in verify-record + escape dot in tdd-real-test regex
enforce-verify-record extractTestMetrics now recognises the project Pest JSON reporter ({"result":"passed/failed",...}); previously every Pest run was recorded as a failed sentinel, blocking all Pest-verified commits (mirrors enforce-tdd-gate fix 1d2d43a6). enforce-tdd-real-test-verifier TEST_FILE_RE second dot escaped so .env.testing is no longer false-matched as a test file.
2026-06-03 18:51:02 +03:00

65 lines
2.6 KiB
JavaScript

import { describe, it, expect } from 'vitest';
import { extractTestMetrics, decideRecord } from './enforce-verify-record.mjs';
describe('enforce-verify-record / extractTestMetrics — Vitest skipped formats', () => {
it('parses vitest passed-only with skipped', () => {
// Vitest 4.x summary when some tests are .skip()'ed:
// "Tests 924 passed | 3 skipped (927)"
// Pre-fix all three regexes fell through → result=fail (false negative).
expect(extractTestMetrics('Tests 924 passed | 3 skipped (927)')).toMatchObject({
tests_passed: 924, tests_failed: 0, tests_total: 927,
});
});
it('parses vitest failed+passed+skipped triplet', () => {
expect(extractTestMetrics('Tests 1 failed | 920 passed | 3 skipped (924)')).toMatchObject({
tests_failed: 1, tests_passed: 920, tests_total: 924,
});
});
});
describe('enforce-verify-record / extractTestMetrics — Pest JSON reporter', () => {
it('parses Pest JSON passed line: tests_passed=14, tests_failed=0, tests_total=14', () => {
const stdout = '{"tool":"pest","result":"passed","tests":14,"passed":14,"assertions":22,"duration_ms":2034}';
expect(extractTestMetrics(stdout)).toMatchObject({
tests_passed: 14,
tests_failed: 0,
tests_total: 14,
});
});
it('parses Pest JSON failed line: tests_failed >= 1', () => {
const stdout = '{"tool":"pest","result":"failed","tests":15,"passed":14,"assertions":22,"errors":1,"duration_ms":3000}';
const m = extractTestMetrics(stdout);
expect(m.tests_failed).toBeGreaterThanOrEqual(1);
});
it('Pest JSON result=failed with no explicit failed/errors count → forced fail (>=1)', () => {
const m = extractTestMetrics('{"tool":"pest","result":"failed","tests":3,"passed":2}');
expect(m.tests_failed).toBeGreaterThanOrEqual(1);
});
});
describe('enforce-verify-record / decideRecord — Pest JSON reporter', () => {
it('decideRecord with passed JSON + exitCode null → result pass', () => {
const result = decideRecord({
toolName: 'Bash',
command: 'php artisan test --filter=X',
exitCode: null,
stdout: '{"tool":"pest","result":"passed","tests":14,"passed":14,"assertions":22}',
});
expect(result).not.toBeNull();
expect(result.result).toBe('pass');
});
it('decideRecord with failed JSON → result fail', () => {
const result = decideRecord({
toolName: 'Bash',
command: 'php artisan test --filter=X',
exitCode: 1,
stdout: '{"tool":"pest","result":"failed","tests":15,"passed":14,"assertions":22,"errors":1}',
});
expect(result).not.toBeNull();
expect(result.result).toBe('fail');
});
});