(
data: Record<string, unknown>,
options: SnapshotTextOptions = {},
)
| 64 | }; |
| 65 | |
| 66 | export function formatSnapshotText( |
| 67 | data: Record<string, unknown>, |
| 68 | options: SnapshotTextOptions = {}, |
| 69 | ): string { |
| 70 | const rawNodes = data.nodes; |
| 71 | const nodes = Array.isArray(rawNodes) ? (rawNodes as SnapshotNode[]) : []; |
| 72 | const backend = isSnapshotBackend(data.backend) ? data.backend : undefined; |
| 73 | const useMobilePresentation = usesMobileSnapshotPresentation(backend); |
| 74 | const helperPresentation = buildAndroidHelperPresentationInput(data, nodes, options); |
| 75 | const prefix = formatSnapshotMetaPrefix(data); |
| 76 | const notices = buildSnapshotNotices(data, nodes, options, helperPresentation); |
| 77 | const noticesBlock = notices.length > 0 ? `${notices.join('\n')}\n` : ''; |
| 78 | const unchanged = options.raw ? null : readUnchangedSnapshot(data); |
| 79 | if (unchanged) { |
| 80 | return `${prefix}${noticesBlock}${formatUnchangedSnapshotText(unchanged)}\n`; |
| 81 | } |
| 82 | const visiblePresentation = |
| 83 | options.raw || !useMobilePresentation |
| 84 | ? null |
| 85 | : buildMobileSnapshotPresentation(helperPresentation.nodes); |
| 86 | const truncated = Boolean(data.truncated); |
| 87 | const displayedNodes = visiblePresentation?.nodes ?? nodes; |
| 88 | const visibility = |
| 89 | options.raw || !useMobilePresentation |
| 90 | ? null |
| 91 | : readSnapshotVisibility( |
| 92 | data, |
| 93 | visiblePresentation, |
| 94 | displayedNodes.length, |
| 95 | nodes.length, |
| 96 | helperPresentation.filteredCount, |
| 97 | ); |
| 98 | const header = formatSnapshotHeader(nodes.length, visibility, truncated); |
| 99 | if (nodes.length === 0) { |
| 100 | return `${prefix}${header}\n${noticesBlock}`; |
| 101 | } |
| 102 | if (options.raw) { |
| 103 | return `${prefix}${header}\n${noticesBlock}${formatRawSnapshotLines(nodes)}\n`; |
| 104 | } |
| 105 | if (options.flatten) { |
| 106 | return `${prefix}${header}\n${noticesBlock}${formatFlattenedSnapshotLines(displayedNodes)}${formatSnapshotSummaryBlock(visiblePresentation)}\n`; |
| 107 | } |
| 108 | return `${prefix}${header}\n${noticesBlock}${formatStructuredSnapshotLines(displayedNodes)}${formatSnapshotSummaryBlock(visiblePresentation)}\n`; |
| 109 | } |
| 110 | |
| 111 | function readUnchangedSnapshot(data: Record<string, unknown>): SnapshotUnchanged | null { |
| 112 | const raw = data.unchanged; |
no test coverage detected