Skip to content

Commit 9c655d5

Browse files
committed
chore(utils): extract constants, add unit tests
1 parent d530ab9 commit 9c655d5

6 files changed

Lines changed: 343 additions & 79 deletions

File tree

packages/utils/src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,18 @@ export {
5252
export { logMultipleResults } from './lib/log-results';
5353
export { link } from './lib/logging';
5454
export { ProgressBar, getProgressBar } from './lib/progress';
55-
export { TERMINAL_WIDTH } from './lib/reports/constants';
55+
export {
56+
CODE_PUSHUP_DOMAIN,
57+
FOOTER_PREFIX,
58+
README_LINK,
59+
TERMINAL_WIDTH,
60+
} from './lib/reports/constants';
5661
export { generateMdReport } from './lib/reports/generate-md-report';
5762
export { generateStdoutSummary } from './lib/reports/generate-stdout-summary';
5863
export { scoreReport } from './lib/reports/scoring';
5964
export { sortReport } from './lib/reports/sorting';
6065
export { ScoredReport } from './lib/reports/types';
6166
export {
62-
CODE_PUSHUP_DOMAIN,
63-
FOOTER_PREFIX,
64-
README_LINK,
6567
calcDuration,
6668
compareIssueSeverity,
6769
loadReport,

packages/utils/src/lib/reports/constants.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,39 @@ export const SCORE_COLOR_RANGE = {
88
YELLOW_MIN: 0.5,
99
};
1010
/* eslint-enable no-magic-numbers */
11+
12+
export const FOOTER_PREFIX = 'Made with ❤ by'; // replace ❤️ with ❤, because of ❤️ has output issues
13+
export const CODE_PUSHUP_DOMAIN = 'code-pushup.dev';
14+
export const README_LINK =
15+
'https://github.com/flowup/quality-metrics-cli#readme';
16+
export const reportHeadlineText = 'Code PushUp Report';
17+
export const reportOverviewTableHeaders = [
18+
'🏷 Category',
19+
'⭐ Score',
20+
'🛡 Audits',
21+
];
22+
export const reportRawOverviewTableHeaders = ['Category', 'Score', 'Audits'];
23+
export const reportMetaTableHeaders: string[] = [
24+
'Commit',
25+
'Version',
26+
'Duration',
27+
'Plugins',
28+
'Categories',
29+
'Audits',
30+
];
31+
32+
export const pluginMetaTableHeaders: string[] = [
33+
'Plugin',
34+
'Audits',
35+
'Version',
36+
'Duration',
37+
];
38+
39+
// details headers
40+
41+
export const detailsTableHeaders: string[] = [
42+
'Severity',
43+
'Message',
44+
'Source file',
45+
'Line(s)',
46+
];

packages/utils/src/lib/reports/generate-md-report.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import { AuditReport, CategoryConfig, Issue } from '@code-pushup/models';
22
import { formatDate, formatDuration, slugify } from '../formatting';
33
import { CommitData } from '../git';
4-
import { NEW_LINE } from './constants';
4+
import {
5+
FOOTER_PREFIX,
6+
NEW_LINE,
7+
README_LINK,
8+
detailsTableHeaders,
9+
pluginMetaTableHeaders,
10+
reportHeadlineText,
11+
reportMetaTableHeaders,
12+
reportOverviewTableHeaders,
13+
} from './constants';
514
import {
615
details,
716
h2,
@@ -15,21 +24,14 @@ import {
1524
} from './md';
1625
import { ScoredGroup, ScoredReport } from './types';
1726
import {
18-
FOOTER_PREFIX,
19-
README_LINK,
2027
countCategoryAudits,
21-
detailsTableHeaders,
2228
formatReportScore,
2329
getPluginNameFromSlug,
2430
getRoundScoreMarker,
2531
getSeverityIcon,
2632
getSortableAuditByRef,
2733
getSortableGroupByRef,
2834
getSquaredScoreMarker,
29-
pluginMetaTableHeaders,
30-
reportHeadlineText,
31-
reportMetaTableHeaders,
32-
reportOverviewTableHeaders,
3335
} from './utils';
3436

3537
export function generateMdReport(

packages/utils/src/lib/reports/generate-stdout-summary.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import cliui from '@isaacs/cliui';
22
import chalk from 'chalk';
33
import CliTable3 from 'cli-table3';
4-
import { NEW_LINE, SCORE_COLOR_RANGE, TERMINAL_WIDTH } from './constants';
5-
import { ScoredReport } from './types';
64
import {
75
CODE_PUSHUP_DOMAIN,
86
FOOTER_PREFIX,
9-
countCategoryAudits,
10-
formatReportScore,
7+
NEW_LINE,
8+
SCORE_COLOR_RANGE,
9+
TERMINAL_WIDTH,
1110
reportHeadlineText,
1211
reportRawOverviewTableHeaders,
13-
} from './utils';
12+
} from './constants';
13+
import { ScoredReport } from './types';
14+
import { countCategoryAudits, formatReportScore } from './utils';
1415

1516
function addLine(line = ''): string {
1617
return line + NEW_LINE;

packages/utils/src/lib/reports/utils.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,6 @@ import {
1818
import { SCORE_COLOR_RANGE } from './constants';
1919
import { ScoredReport, SortableAuditReport, SortableGroup } from './types';
2020

21-
export const FOOTER_PREFIX = 'Made with ❤ by'; // replace ❤️ with ❤, because of ❤️ has output issues
22-
export const CODE_PUSHUP_DOMAIN = 'code-pushup.dev';
23-
export const README_LINK =
24-
'https://github.com/flowup/quality-metrics-cli#readme';
25-
export const reportHeadlineText = 'Code PushUp Report';
26-
export const reportOverviewTableHeaders = [
27-
'🏷 Category',
28-
'⭐ Score',
29-
'🛡 Audits',
30-
];
31-
export const reportRawOverviewTableHeaders = ['Category', 'Score', 'Audits'];
32-
export const reportMetaTableHeaders: string[] = [
33-
'Commit',
34-
'Version',
35-
'Duration',
36-
'Plugins',
37-
'Categories',
38-
'Audits',
39-
];
40-
41-
export const pluginMetaTableHeaders: string[] = [
42-
'Plugin',
43-
'Audits',
44-
'Version',
45-
'Duration',
46-
];
47-
48-
// details headers
49-
50-
export const detailsTableHeaders: string[] = [
51-
'Severity',
52-
'Message',
53-
'Source file',
54-
'Line(s)',
55-
];
56-
5721
export function formatReportScore(score: number): string {
5822
return Math.round(score * 100).toString();
5923
}

0 commit comments

Comments
 (0)