UNPKG

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

Version:

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

64 lines (63 loc) 2.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.prepareWarnings = exports.prepareTableRow = exports.prepareGreetingMessage = exports.omitWarningsData = exports.log = exports.getFileName = exports.formatResult = exports.addFilesSetToWarningConfig = void 0; const chalk_1 = require("chalk"); const constants_1 = require("./constants"); const types_1 = require("./types"); const log = ({ message, type, origin }) => { const colors = { warn: chalk_1.yellow, error: chalk_1.red, log: chalk_1.grey, debug: chalk_1.cyan, }; if (Object.values(types_1.CustomLogType).includes(type)) { console[type](colors[type](message)); console[type](origin); } }; exports.log = log; const formatResult = (status, title) => status === 'failed' ? (0, chalk_1.bold)((0, chalk_1.red)(`${status.toUpperCase()} - ${title}`)) : (0, chalk_1.green)(`${status.toUpperCase()} - ${title}`); exports.formatResult = formatResult; const getFileName = (filePath) => { const filePathAsArray = filePath.split('/'); return filePathAsArray[filePathAsArray.length - 1].split('.')[0]; }; exports.getFileName = getFileName; const convertToSeconds = (milliseconds) => milliseconds / 1000; const omitWarningsData = (globalConfig) => globalConfig.verbose || globalConfig.silent; exports.omitWarningsData = omitWarningsData; const prepareWarningRow = (acc, curr) => { const warningRow = [` > ${curr[0]}`, curr[1], '']; acc.push(warningRow); return acc; }; const prepareWarnings = (warningsPerTest) => Object.entries(warningsPerTest) .sort((a, b) => { if (a[0] === constants_1.OTHER) return 1; if (b[0] === constants_1.OTHER) return -1; return b[1] - a[1]; }) .reduce(prepareWarningRow, []); exports.prepareWarnings = prepareWarnings; const addFilesSetToWarningConfig = (config) => (Object.assign(Object.assign({}, config), { files: new Set() })); exports.addFilesSetToWarningConfig = addFilesSetToWarningConfig; const isHighlighted = (limit, testDuration) => testDuration ? testDuration > limit : false; const prepareTableRow = (testResult, limit, globalConfig) => { const { testFilePath, console, perfStats } = testResult; const filePath = testFilePath.split('/').slice(-1); const numberOfWarnings = console ? console.length : 0; const testDuration = isHighlighted(limit, perfStats.runtime) ? (0, chalk_1.red)(`${convertToSeconds(perfStats.runtime)}`) : convertToSeconds(perfStats.runtime); return omitWarningsData(globalConfig) ? [`${filePath}`, `${testDuration}s`] : [`${filePath}`, `${numberOfWarnings}`, `${testDuration}s`]; }; exports.prepareTableRow = prepareTableRow; const prepareGreetingMessage = (numTotalTestSuites) => (0, chalk_1.cyan)(`\nRunning ${numTotalTestSuites} test suites, quietly for speed 🏎️ `); exports.prepareGreetingMessage = prepareGreetingMessage;