Skip to content

Commit

Permalink
feat: improve markdown output
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjastrzebski committed Jun 1, 2024
1 parent d76b0b4 commit f96ac6c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 28 deletions.
27 changes: 9 additions & 18 deletions packages/compare/src/output/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,37 @@ export function printToConsole(data: CompareResult) {
printMetadata('Current', data.metadata.current);
printMetadata('Baseline', data.metadata.baseline);

logger.log('\n➡️ Significant changes to duration');
logger.log('\n➡️ Significant changes to duration (duration | count)');
data.significant.forEach(printRegularLine);
if (data.significant.length === 0) {
logger.log(' - (none)');
}

logger.log('\n➡️ Meaningless changes to duration');
logger.log('\n➡️ Meaningless changes to duration (duration | count)');
data.meaningless.forEach(printRegularLine);
if (data.meaningless.length === 0) {
logger.log(' - (none)');
}

logger.log('\n➡️ Render count changes');
logger.log('\n➡️ Render count changes (duration | count)');
data.countChanged.forEach(printRegularLine);
if (data.countChanged.length === 0) {
logger.log(' - (none)');
}

logger.log('\n➡️ Redundant Renders');
logger.log('\n➡️ Redundant Render (Initial | Updates)');
data.redundantRenders.forEach(printRenderLine);
if (data.redundantRenders.length === 0) {
logger.log(' - (none)');
}

logger.log('\n➡️ Added scenarios');
logger.log('\n➡️ Added scenarios (duration | count)');
data.added.forEach(printAddedLine);
if (data.added.length === 0) {
logger.log(' - (none)');
}

logger.log('\n➡️ Removed scenarios');
logger.log('\n➡️ Removed scenarios (duration | count)');
data.removed.forEach(printRemovedLine);
if (data.removed.length === 0) {
logger.log(' - (none)');
Expand All @@ -63,21 +63,12 @@ function printRegularLine(entry: CompareEntry) {
}

function printRenderLine(entry: CompareEntry | AddedEntry) {
if (entry.current.redundantRenders?.initial !== 0) {
if (entry.current.redundantRenders?.initial !== 0 || entry.current.redundantRenders?.update !== 0) {
logger.log(
` - ${entry.name} [render:initial]: | ${formatCountChange(
` - ${entry.name} [render]: | ${formatCountChange(
entry.current.redundantRenders?.initial,
entry.baseline?.redundantRenders?.initial
)}`
);
}

if (entry.current.redundantRenders?.update !== 0) {
logger.log(
` - ${entry.name} [render:update]: | ${formatCountChange(
entry.current.redundantRenders?.update,
entry.baseline?.redundantRenders?.update
)}`
)} | ${formatCountChange(entry.current.redundantRenders?.update, entry.baseline?.redundantRenders?.update)}`
);
}
}
Expand Down
37 changes: 27 additions & 10 deletions packages/compare/src/output/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '../utils/format';
import * as md from '../utils/markdown';
import type { AddedEntry, CompareEntry, CompareResult, RemovedEntry, MeasureEntry, MeasureMetadata } from '../types';
import { collapsibleSection } from '../utils/markdown';

const tableHeader = ['Name', 'Type', 'Duration', 'Count'] as const;

Expand Down Expand Up @@ -66,12 +67,18 @@ function buildMarkdown(data: CompareResult) {
result += `\n\n${md.heading3('Meaningless Changes To Duration')}`;
result += `\n${buildSummaryTable(data.meaningless, true)}`;
result += `\n${buildDetailsTable(data.meaningless)}`;
result += `\n\n${md.heading3('Changes To Count')}`;
result += `\n${buildSummaryTable(data.countChanged)}`;
result += `\n${buildDetailsTable(data.countChanged)}`;
result += `\n\n${md.heading3('Redundant Render(s)')}`;
result += `\n${buildSummaryTable(data.redundantRenders)}`;
result += `\n${buildDetailsTable(data.redundantRenders)}`;

// Skip renders counts if user only has function measurements
const allEntries = [...data.significant, ...data.meaningless, ...data.added, ...data.removed];
const hasRenderEntries = allEntries.some((e) => e.type === 'render');
if (hasRenderEntries) {
result += `\n\n${md.heading3('Render Count Changes')}`;
result += `\n${buildSummaryTable(data.countChanged)}`;
result += `\n${buildDetailsTable(data.countChanged)}`;
result += `\n\n${md.heading3('Redundant Renders')}`;
result += `\n${buildRedundantRendersTable(data.redundantRenders)}`;
}

result += `\n\n${md.heading3('Added Scenarios')}`;
result += `\n${buildSummaryTable(data.added)}`;
result += `\n${buildDetailsTable(data.added)}`;
Expand Down Expand Up @@ -169,10 +176,20 @@ function buildCountDetails(title: string, entry: MeasureEntry) {
.join(`<br/>`);
}

export function collapsibleSection(title: string, content: string) {
return `<details>\n<summary>${title}</summary>\n\n${content}\n</details>\n\n`;
function formatRunDurations(values: number[]) {
return values.map((v) => (Number.isInteger(v) ? `${v}` : `${v.toFixed(1)}`)).join(' ');
}

export function formatRunDurations(values: number[]) {
return values.map((v) => (Number.isInteger(v) ? `${v}` : `${v.toFixed(1)}`)).join(' ');
function buildRedundantRendersTable(entries: Array<CompareEntry | AddedEntry>) {
if (!entries.length) return md.italic('There are no entries');

const tableHeader = ['Name', 'Type', 'Initial', 'Update'] as const;
const rows = entries.map((entry) => [
entry.name,
entry.type,
entry.current.redundantRenders?.initial ?? '?',
entry.current.redundantRenders?.update ?? '?',
]);

return markdownTable([tableHeader, ...rows]);
}
4 changes: 4 additions & 0 deletions packages/compare/src/utils/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ export function bold(text: string) {
export function italic(text: string) {
return `*${text}*`;
}

export function collapsibleSection(title: string, content: string) {
return `<details>\n<summary>${title}</summary>\n\n${content}\n</details>\n\n`;
}

0 comments on commit f96ac6c

Please sign in to comment.