Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(utils): improve report folder structure, report function naming #408

Merged
merged 3 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/core/src/lib/implementation/persist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { join } from 'node:path';
import { PersistConfig, Report } from '@code-pushup/models';
import {
MultipleFileResults,
generateMdReport,
generateStdoutSummary,
getLatestCommit,
logMultipleFileResults,
reportToMd,
reportToStdout,
scoreReport,
sortReport,
} from '@code-pushup/utils';
Expand All @@ -31,7 +31,7 @@ export async function persistReport(
const { outputDir, filename, format } = options;

const sortedScoredReport = sortReport(scoreReport(report));
console.info(reportToStdout(sortedScoredReport));
console.info(generateStdoutSummary(sortedScoredReport));

// collect physical format outputs
const results: { format: string; content: string }[] = [];
Expand All @@ -49,7 +49,7 @@ export async function persistReport(

results.push({
format: 'md',
content: reportToMd(sortedScoredReport, commitData),
content: generateMdReport(sortedScoredReport, commitData),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
readProjectConfiguration,
} from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { join } from 'path';
import { join } from 'node:path';
import { describe, expect, it } from 'vitest';
import { addToProjectGenerator } from './generator';

Expand Down
2 changes: 1 addition & 1 deletion packages/utils/perf/score-report/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Benchmark from 'benchmark';
import { Report } from '@code-pushup/models';
import { scoreReport } from '../../src/lib/scoring';
import { scoreReport } from '../../src/lib/reports/scoring';
import { scoreReportOptimized0 } from './optimized0';
import { scoreReportOptimized1 } from './optimized1';
import { scoreReportOptimized2 } from './optimized2';
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/perf/score-report/optimized0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ScoredReport } from '../../src';
import {
EnrichedAuditReport,
EnrichedScoredGroup,
} from '../../src/lib/scoring';
} from '../../src/lib/reports/scoring';

function groupRefToScore(audits: EnrichedAuditReport[]) {
return (ref: GroupRef) => {
Expand Down
11 changes: 5 additions & 6 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ export {
isPromiseRejectedResult,
} from './lib/guards';
export { logMultipleResults } from './lib/log-results';
export { NEW_LINE } from './lib/md';
export { ProgressBar, getProgressBar } from './lib/progress';
export { generateMdReport } from './lib/reports/generate-md-report';
export { generateStdoutSummary } from './lib/reports/generate-stdout-summary';
export { ScoredReport, scoreReport } from './lib/reports/scoring';
export { sortReport } from './lib/reports/sorting';
export {
CODE_PUSHUP_DOMAIN,
FOOTER_PREFIX,
README_LINK,
calcDuration,
compareIssueSeverity,
loadReport,
} from './lib/report';
export { reportToMd } from './lib/report-to-md';
export { reportToStdout } from './lib/report-to-stdout';
export { ScoredReport, scoreReport } from './lib/scoring';
} from './lib/reports/utils';
export {
CliArgsObject,
countOccurrences,
Expand All @@ -62,4 +62,3 @@ export {
toUnixPath,
} from './lib/transform';
export { verboseUtils } from './lib/verbose-utils';
export { sortReport } from './lib/sort-report';
2 changes: 1 addition & 1 deletion packages/utils/src/lib/execute-process.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { spawn } from 'node:child_process';
import { calcDuration } from './report';
import { calcDuration } from './reports/utils';

/**
* Represents the process result.
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/lib/formatting.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('pluralize', () => {
describe('formatBytes', () => {
it.each([
[0, '0 B'],
[1_000, '1000 B'],
[1000, '1000 B'],
[10_000, '9.77 kB'],
[10_000_000, '9.54 MB'],
[10_000_000_000, '9.31 GB'],
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/lib/log-results.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('logMultipleResults', () => {
[
{
status: 'fulfilled',
value: ['out.json', 10000],
value: ['out.json', 10_000],
} as PromiseFulfilledResult<FileResult>,
],
'Generated reports',
Expand Down Expand Up @@ -40,7 +40,7 @@ describe('logMultipleResults', () => {
[
{
status: 'fulfilled',
value: ['out.json', 10000],
value: ['out.json', 10_000],
} as PromiseFulfilledResult<FileResult>,
{ status: 'rejected', reason: 'fail' } as PromiseRejectedResult,
],
Expand Down
1 change: 0 additions & 1 deletion packages/utils/src/lib/md/constants.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/utils/src/lib/progress.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('getSingletonMultiProgressBars', () => {
const taskAName = 'a';
const bars = getSingletonProgressBars({ progressWidth: 1 });
const tasks = bars['tasks'];
const progressBuffer = bars['logger'].progressBuffer;
const progressBuffer: string[] = bars['logger'].progressBuffer;

describe('getProgressBar', () => {
it('should init task', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const NEW_LINE = '\n';

export const SCORE_COLOR_RANGE = {
GREEN_MIN: 0.9,
YELLOW_MIN: 0.5,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe } from 'vitest';
import { reportMock } from '@code-pushup/testing-utils';
import { reportToMd } from './report-to-md';
import { generateMdReport } from './generate-md-report';
import { scoreReport } from './scoring';
import { sortReport } from './sort-report';
import { sortReport } from './sorting';

describe('report-to-md', () => {
beforeEach(() => {
Expand All @@ -22,7 +22,10 @@ describe('report-to-md', () => {
author: 'BioPhoton',
date: 'Sat Sep 10 12:00:00 2021 +0200',
};
const mdReport = reportToMd(sortReport(scoreReport(reportMock())), commit);
const mdReport = generateMdReport(
sortReport(scoreReport(reportMock())),
commit,
);
expect(mdReport).toContain(
`${commit.message} (${commit.hash.slice(0, 7)})`,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AuditReport, CategoryConfig, Issue } from '@code-pushup/models';
import { formatDuration, slugify } from './formatting';
import { CommitData } from './git';
import { formatDuration, slugify } from '../formatting';
import { CommitData } from '../git';
import { NEW_LINE } from './constants';
import {
NEW_LINE,
details,
h2,
h3,
Expand All @@ -12,7 +12,12 @@ import {
style,
tableHtml,
tableMd,
} from './md/';
} from './md';
import {
EnrichedScoredGroupWithAudits,
ScoredReport,
WeighedAuditReport,
} from './scoring';
import {
FOOTER_PREFIX,
README_LINK,
Expand All @@ -29,14 +34,9 @@ import {
reportHeadlineText,
reportMetaTableHeaders,
reportOverviewTableHeaders,
} from './report';
import {
EnrichedScoredGroupWithAudits,
ScoredReport,
WeighedAuditReport,
} from './scoring';
} from './utils';

export function reportToMd(
export function generateMdReport(
report: ScoredReport,
commitData: CommitData | null,
): string {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { describe } from 'vitest';
import { reportMock } from '@code-pushup/testing-utils';
import { reportToStdout } from './report-to-stdout';
import { generateStdoutSummary } from './generate-stdout-summary';
import { scoreReport } from './scoring';
import { sortReport } from './sort-report';
import { sortReport } from './sorting';

describe('report-to-stdout', () => {
it('should contain all sections when using the fixture report', () => {
const logOutput = reportToStdout(sortReport(scoreReport(reportMock())));
const logOutput = generateStdoutSummary(
sortReport(scoreReport(reportMock())),
);
// logOutput.replace(/\u001B\[\d+m/g, '') removes all color codes from the output
// for snapshot readability
// eslint-disable-next-line no-control-regex
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import cliui from '@isaacs/cliui';
import chalk from 'chalk';
import Table from 'cli-table3';
import { SCORE_COLOR_RANGE } from './constants';
import { NEW_LINE } from './md';
import { NEW_LINE, SCORE_COLOR_RANGE } from './constants';
import { ScoredReport } from './scoring';
import {
CODE_PUSHUP_DOMAIN,
FOOTER_PREFIX,
countCategoryAudits,
formatReportScore,
reportHeadlineText,
reportRawOverviewTableHeaders,
} from './report';
import { ScoredReport } from './scoring';
} from './utils';

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

export function reportToStdout(report: ScoredReport): string {
export function generateStdoutSummary(report: ScoredReport): string {
let output = '';

output += addLine(reportToHeaderSection(report));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from './details';
export * from './headline';
export * from './table';
export * from './constants';
export * from './font-style';
export * from './headline';
export * from './link';
export * from './list';
export * from './table';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NEW_LINE } from './constants';
import { NEW_LINE } from '../constants';

export type Alignment = 'l' | 'c' | 'r';
const alignString = new Map<Alignment, string>([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NEW_LINE } from './constants';
import { NEW_LINE } from '../constants';
import { Alignment, tableMd } from './table';

describe('table function', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
PluginReport,
Report,
} from '@code-pushup/models';
import { deepClone } from './transform';
import { deepClone } from '../transform';

export type EnrichedAuditReport = AuditReport & { plugin: string };
export type WeighedAuditReport = EnrichedAuditReport & { weight: number };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { REPORT_MOCK } from '@code-pushup/testing-utils';
import { scoreReport } from './scoring';
import { sortReport } from './sort-report';
import { sortReport } from './sorting';

describe('sortReport', () => {
it('should sort the audits and audit groups in categories, plugin audits and audit issues', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { CategoryRef } from '@code-pushup/models';
import {
EnrichedScoredGroupWithAudits,
ScoredReport,
WeighedAuditReport,
} from './scoring';
import {
compareAudits,
compareCategoryAudits,
compareIssues,
getAuditByRef,
getGroupWithAudits,
} from './report';
import {
EnrichedScoredGroupWithAudits,
ScoredReport,
WeighedAuditReport,
} from './scoring';
} from './utils';

export function sortReport(report: ScoredReport): ScoredReport {
const { categories, plugins } = report;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import {
Report,
reportSchema,
} from '@code-pushup/models';
import { SCORE_COLOR_RANGE } from './constants';
import {
ensureDirectoryExists,
readJsonFile,
readTextFile,
} from './file-system';
} from '../file-system';
import { SCORE_COLOR_RANGE } from './constants';
import {
EnrichedAuditReport,
EnrichedScoredGroupWithAudits,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import {
REPORT_MOCK,
reportMock,
} from '@code-pushup/testing-utils';
import {
EnrichedAuditReport,
ScoredReport,
WeighedAuditReport,
} from './scoring';
import {
calcDuration,
compareAudits,
Expand All @@ -15,12 +20,7 @@ import {
countWeightedRefs,
getPluginNameFromSlug,
loadReport,
} from './report';
import {
EnrichedAuditReport,
ScoredReport,
WeighedAuditReport,
} from './scoring';
} from './utils';

describe('calcDuration', () => {
it('should calculate the duration correctly if start and stop are given', () => {
Expand Down