UNPKG

@90poe/jest-performant-warnings-stats-reporter

Version:

A flexible jest reporter that provides ability to show statistics of warnings and group them

43 lines (32 loc) 1.1 kB
import { AssertionResult } from '@jest/test-result'; import { bold, grey } from 'chalk'; import { formatResult } from './utils'; const recursiveLogger = ( prevTitle: string, testResults: AssertionResult[], resultsIndex: number, titlesIndex: number, ): void => { const testResult = testResults[resultsIndex]; if (!testResult) { return; } const { ancestorTitles, status, title } = testResult; const currentTitle = ancestorTitles[titlesIndex]; if (!currentTitle && ancestorTitles.length) { recursiveLogger(prevTitle, testResults, resultsIndex, titlesIndex - 1); return; } if (!currentTitle && ancestorTitles.length === 0) { console.log(formatResult(status, title)); return; } if (prevTitle !== currentTitle && titlesIndex < ancestorTitles.length) { console.log(bold(grey(currentTitle))); recursiveLogger(currentTitle, testResults, resultsIndex, titlesIndex + 1); } else { console.log(formatResult(status, title)); recursiveLogger(currentTitle, testResults, resultsIndex + 1, titlesIndex); } }; export { recursiveLogger };