Skip to content

Commit 387729d

Browse files
committed
chore: switch from terminal-table to cli-table
It is better maintained, and has already pinned the `colors` library to v1.4.0. It also seems that they will move away from colors in the near future: cli-table/cli-table3#250.
1 parent 6a8684f commit 387729d

File tree

4 files changed

+8884
-49
lines changed

4 files changed

+8884
-49
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
"license": "MIT",
1212
"private": false,
1313
"dependencies": {
14-
"chalk": "^5.0.0",
14+
"chalk": "^4.0.0",
15+
"cli-table3": "^0.6.1",
1516
"commander": "^5.0.0",
1617
"ncp": "^2.0.0",
1718
"react": "^16.13.1",
1819
"react-dom": "^16.13.1",
1920
"rimraf": "^3.0.2",
2021
"semantic-ui-react": "^0.88.2",
21-
"terminal-table": "^0.0.12",
2222
"type-coverage-core": "^2.17.2"
2323
},
2424
"scripts": {

src/lib/reporters/text.ts

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import Table from "terminal-table";
1+
import Table, { Cell } from "cli-table3";
22
import { CoverageData } from "../getCoverage";
33
import chalk from "chalk";
44

55
const coverageTable = new Table({
6-
leftPadding: 1,
7-
rightPadding: 1,
8-
borderStyle: 2
6+
chars: { mid: "", "left-mid": "", "mid-mid": "", "right-mid": "" },
7+
colAligns: ["left", "right", "right", "right", "right"],
8+
style: { "padding-left": 1, "padding-right": 1 }
99
});
1010

1111
const calculatePercantage = (correct: number, total: number): number => {
@@ -27,7 +27,6 @@ export const generate = (
2727
{ fileCounts, percentage, total, covered, uncovered }: CoverageData,
2828
threshold: number
2929
): string => {
30-
let row = 1;
3130
const headers = [
3231
"filenames" + chalk.gray(` (${fileCounts.size})`),
3332
"percent" + chalk.gray(` (${percentage.toFixed(2)}%)`),
@@ -41,13 +40,6 @@ export const generate = (
4140
headers.map(() => chalk.gray("---"))
4241
);
4342

44-
coverageTable.attrRange(
45-
{ column: [1, 5] },
46-
{
47-
align: "right"
48-
}
49-
);
50-
5143
fileCounts.forEach(
5244
(
5345
{
@@ -56,25 +48,26 @@ export const generate = (
5648
}: { totalCount: number; correctCount: number },
5749
filename: string
5850
) => {
59-
row++;
51+
const colorCell = (cell: Cell): Cell => {
52+
const color =
53+
Math.floor(calculatePercantage(correctCount, totalCount)) >= threshold
54+
? chalk.green
55+
: chalk.red;
56+
if (typeof cell === "object" && "content" in cell) {
57+
return { ...cell, content: color(cell.content) };
58+
}
6059

61-
coverageTable.push([
62-
filename,
63-
calculatePercantageWithString(correctCount, totalCount),
64-
totalCount,
65-
correctCount,
66-
totalCount - correctCount
67-
]);
60+
return color(cell);
61+
};
6862

69-
coverageTable.attrRange(
70-
{ row: [row] },
71-
{
72-
color:
73-
Math.floor(calculatePercantage(correctCount, totalCount)) >=
74-
threshold
75-
? "green"
76-
: "red"
77-
}
63+
coverageTable.push(
64+
[
65+
filename,
66+
calculatePercantageWithString(correctCount, totalCount),
67+
totalCount,
68+
correctCount,
69+
totalCount - correctCount
70+
].map((val) => colorCell(val))
7871
);
7972
}
8073
);

0 commit comments

Comments
 (0)