From 58ab314bb56bc0aae19d592dc16691041a2edaf8 Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Sat, 1 Jun 2024 11:06:37 +0200 Subject: [PATCH] feat: improve markdown output --- packages/compare/src/output/markdown.ts | 37 ++++++++++++++++++------- packages/compare/src/utils/markdown.ts | 4 +++ 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/packages/compare/src/output/markdown.ts b/packages/compare/src/output/markdown.ts index 8b2dec70..8d5dd25f 100644 --- a/packages/compare/src/output/markdown.ts +++ b/packages/compare/src/output/markdown.ts @@ -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; @@ -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)}`; @@ -169,10 +176,20 @@ function buildCountDetails(title: string, entry: MeasureEntry) { .join(`
`); } -export function collapsibleSection(title: string, content: string) { - return `
\n${title}\n\n${content}\n
\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) { + 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]); } diff --git a/packages/compare/src/utils/markdown.ts b/packages/compare/src/utils/markdown.ts index 0f04cd49..cdd9200e 100644 --- a/packages/compare/src/utils/markdown.ts +++ b/packages/compare/src/utils/markdown.ts @@ -17,3 +17,7 @@ export function bold(text: string) { export function italic(text: string) { return `*${text}*`; } + +export function collapsibleSection(title: string, content: string) { + return `
\n${title}\n\n${content}\n
\n\n`; +}