MCPcopy
hub / github.com/callstack/agent-device / formatSnapshotDiffText

Function formatSnapshotDiffText

src/utils/output.ts:270–306  ·  view source on GitHub ↗
(data: Record<string, unknown>)

Source from the content-addressed store, hash-verified

268}
269
270export function formatSnapshotDiffText(data: Record<string, unknown>): string {
271 const baselineInitialized = data.baselineInitialized === true;
272 const summaryRaw = (data.summary ?? {}) as Record<string, unknown>;
273 const additions = toNumber(summaryRaw.additions);
274 const removals = toNumber(summaryRaw.removals);
275 const unchanged = toNumber(summaryRaw.unchanged);
276 const useColor = supportsColor();
277 const notices = readSnapshotWarnings(data);
278 const noticesBlock = notices.length > 0 ? `${notices.join('\n')}\n` : '';
279 if (baselineInitialized) {
280 return `${noticesBlock}Baseline initialized (${unchanged} lines).\n`;
281 }
282 const rawLines = Array.isArray(data.lines) ? (data.lines as SnapshotDiffLine[]) : [];
283 const contextLines = applyContextWindow(rawLines, 1);
284 const lines = contextLines.map((line) => {
285 const text = typeof line.text === 'string' ? line.text : '';
286 if (line.kind === 'added') {
287 const prefix = text.startsWith(' ') ? `+${text}` : `+ ${text}`;
288 return useColor ? colorize(prefix, 'green') : prefix;
289 }
290 if (line.kind === 'removed') {
291 const prefix = text.startsWith(' ') ? `-${text}` : `- ${text}`;
292 return useColor ? colorize(prefix, 'red') : prefix;
293 }
294 return useColor ? colorize(text, 'dim') : text;
295 });
296 const body = lines.length > 0 ? `${lines.join('\n')}\n` : '';
297 if (!useColor) {
298 return `${noticesBlock}${body}${additions} additions, ${removals} removals, ${unchanged} unchanged\n`;
299 }
300 const summary = [
301 `${colorize(String(additions), 'green')} additions`,
302 `${colorize(String(removals), 'red')} removals`,
303 `${colorize(String(unchanged), 'dim')} unchanged`,
304 ].join(', ');
305 return `${noticesBlock}${body}${summary}\n`;
306}
307
308export function formatScreenshotDiffText(data: ScreenshotDiffResult): string {
309 const useColor = supportsColor();

Callers 2

output.test.tsFile · 0.90
diffCommandFunction · 0.90

Calls 6

toNumberFunction · 0.85
supportsColorFunction · 0.85
readSnapshotWarningsFunction · 0.85
applyContextWindowFunction · 0.85
colorizeFunction · 0.85
startsWithMethod · 0.80

Tested by

no test coverage detected