11import type { SnapshotNode } from '../utils/snapshot.ts' ;
2- import { buildSnapshotDisplayLines , displayLabel , formatRole } from '../utils/snapshot-lines.ts' ;
2+ import { buildSnapshotDisplayLines , displayLabel , formatRole , formatSnapshotLine } from '../utils/snapshot-lines.ts' ;
33
44export type SnapshotDiffLine = {
55 kind : 'added' | 'removed' | 'unchanged' ;
@@ -17,6 +17,10 @@ export type SnapshotDiffResult = {
1717 lines : SnapshotDiffLine [ ] ;
1818} ;
1919
20+ export type SnapshotDiffOptions = {
21+ flatten ?: boolean ;
22+ } ;
23+
2024type SnapshotComparableLine = {
2125 text : string ;
2226 comparable : string ;
@@ -32,9 +36,13 @@ export function snapshotNodeToComparableLine(node: SnapshotNode, depthOverride?:
3236 return [ depthPart , role , textPart , enabledPart , selectedPart , hittablePart ] . join ( '|' ) ;
3337}
3438
35- export function buildSnapshotDiff ( previousNodes : SnapshotNode [ ] , currentNodes : SnapshotNode [ ] ) : SnapshotDiffResult {
36- const previous = snapshotNodesToLines ( previousNodes ) ;
37- const current = snapshotNodesToLines ( currentNodes ) ;
39+ export function buildSnapshotDiff (
40+ previousNodes : SnapshotNode [ ] ,
41+ currentNodes : SnapshotNode [ ] ,
42+ options : SnapshotDiffOptions = { } ,
43+ ) : SnapshotDiffResult {
44+ const previous = snapshotNodesToLines ( previousNodes , options ) ;
45+ const current = snapshotNodesToLines ( currentNodes , options ) ;
3846 const lines = diffComparableLinesMyers ( previous , current ) ;
3947 const summary : SnapshotDiffSummary = { additions : 0 , removals : 0 , unchanged : 0 } ;
4048 for ( const line of lines ) {
@@ -45,11 +53,20 @@ export function buildSnapshotDiff(previousNodes: SnapshotNode[], currentNodes: S
4553 return { summary, lines } ;
4654}
4755
48- export function countSnapshotComparableLines ( nodes : SnapshotNode [ ] ) : number {
49- return snapshotNodesToLines ( nodes ) . length ;
56+ export function countSnapshotComparableLines (
57+ nodes : SnapshotNode [ ] ,
58+ options : SnapshotDiffOptions = { } ,
59+ ) : number {
60+ return snapshotNodesToLines ( nodes , options ) . length ;
5061}
5162
52- function snapshotNodesToLines ( nodes : SnapshotNode [ ] ) : SnapshotComparableLine [ ] {
63+ function snapshotNodesToLines ( nodes : SnapshotNode [ ] , options : SnapshotDiffOptions ) : SnapshotComparableLine [ ] {
64+ if ( options . flatten ) {
65+ return nodes . map ( ( node ) => ( {
66+ text : formatSnapshotLine ( node , 0 , false ) ,
67+ comparable : snapshotNodeToComparableLine ( node , 0 ) ,
68+ } ) ) ;
69+ }
5370 return buildSnapshotDisplayLines ( nodes ) . map ( ( line ) => ( {
5471 text : line . text ,
5572 comparable : snapshotNodeToComparableLine ( line . node , line . depth ) ,
0 commit comments