(pad, summary, symbol, color, table)
| 558 | } |
| 559 | |
| 560 | function getCoverageReport(pad, summary, symbol, color, table) { |
| 561 | const prefix = `${pad}${symbol}`; |
| 562 | let report = `${color}${prefix}start of coverage report\n`; |
| 563 | |
| 564 | let filePadLength; |
| 565 | let columnPadLengths = []; |
| 566 | let uncoveredLinesPadLength; |
| 567 | let tableWidth; |
| 568 | |
| 569 | // Create a tree of file paths |
| 570 | const { tree, treeDepth, longestFile } = buildFileTree(summary); |
| 571 | if (table) { |
| 572 | // Calculate expected column sizes based on the tree |
| 573 | filePadLength = table && longestFile; |
| 574 | filePadLength += (treeDepth - 1); |
| 575 | if (color) { |
| 576 | filePadLength += 2; |
| 577 | } |
| 578 | filePadLength = MathMax(filePadLength, 'all files'.length); |
| 579 | if (filePadLength > (process.stdout.columns / 2)) { |
| 580 | filePadLength = MathFloor(process.stdout.columns / 2); |
| 581 | } |
| 582 | const fileWidth = filePadLength + 2; |
| 583 | |
| 584 | columnPadLengths = ArrayPrototypeMap(kColumns, (column) => (table ? MathMax(column.length, 6) : 0)); |
| 585 | const columnsWidth = ArrayPrototypeReduce(columnPadLengths, (acc, columnPadLength) => acc + columnPadLength + 3, 0); |
| 586 | |
| 587 | uncoveredLinesPadLength = table && ArrayPrototypeReduce(summary.files, (acc, file) => |
| 588 | MathMax(acc, formatUncoveredLines(getUncoveredLines(file.lines), table).length), 0); |
| 589 | uncoveredLinesPadLength = MathMax(uncoveredLinesPadLength, 'uncovered lines'.length); |
| 590 | const uncoveredLinesWidth = uncoveredLinesPadLength + 2; |
| 591 | |
| 592 | tableWidth = fileWidth + columnsWidth + uncoveredLinesWidth; |
| 593 | |
| 594 | const availableWidth = (process.stdout.columns || Infinity) - prefix.length; |
| 595 | const columnsExtras = tableWidth - availableWidth; |
| 596 | if (table && columnsExtras > 0) { |
| 597 | filePadLength = MathMin(availableWidth * 0.5, filePadLength); |
| 598 | uncoveredLinesPadLength = MathMax(availableWidth - columnsWidth - (filePadLength + 2) - 2, 1); |
| 599 | tableWidth = availableWidth; |
| 600 | } else { |
| 601 | uncoveredLinesPadLength = Infinity; |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | function getCell(string, width, pad, truncate, coverage) { |
| 606 | if (!table) return string; |
| 607 | |
| 608 | let result = string; |
| 609 | if (pad) result = pad(result, width); |
| 610 | if (truncate) result = truncate(result, width); |
| 611 | if (color && coverage !== undefined) { |
| 612 | if (coverage > 90) return `${coverageColors.high}${result}${color}`; |
| 613 | if (coverage > 50) return `${coverageColors.medium}${result}${color}`; |
| 614 | return `${coverageColors.low}${result}${color}`; |
| 615 | } |
| 616 | return result; |
| 617 | } |
no test coverage detected
searching dependent graphs…