@@ -44,6 +44,12 @@ const REPEATED_CHAIN: RawSnapshotNode[] = [
4444 } ,
4545] ;
4646
47+ const SCOPED_SUBTREE : RawSnapshotNode [ ] = [
48+ { index : 0 , type : 'Other' , label : 'Checkout' , depth : 0 } ,
49+ { index : 1 , type : 'Button' , label : 'Pay now' , depth : 1 , parentIndex : 0 } ,
50+ { index : 2 , type : 'TextField' , label : 'Card number' , depth : 1 , parentIndex : 0 } ,
51+ ] ;
52+
4753test ( 'default (non-raw) output dedups repeated ancestor labels in both text and json' , async ( ) => {
4854 const output = await snapshotCliOutput ( { result : buildResult ( REPEATED_CHAIN ) } ) ;
4955
@@ -218,15 +224,23 @@ test('settings renders response warnings after the message', async () => {
218224// through the production ref grammar to the same node and refs generation.
219225test ( '--scope output prints refs a caller can paste back as the same ref and generation' , async ( ) => {
220226 const output = await snapshotCliOutput ( {
221- result : { ...buildResult ( REPEATED_CHAIN . slice ( 0 , 1 ) ) , refsGeneration : 752890 } ,
227+ result : { ...buildResult ( SCOPED_SUBTREE ) , refsGeneration : 752890 } ,
222228 scope : '@e1' ,
223229 } ) ;
224230
225- const pin = / ( @ e \d + ~ s \d + ) \[ / . exec ( output . text ! ) ?. [ 1 ] ;
226- assert . equal ( pin , '@e1~s752890' ) ;
227- assert . deepEqual ( splitRefGenerationSuffix ( pin ! ) , { base : '@e1' , generation : 752890 } ) ;
228- assert . equal ( normalizeRef ( pin ! ) , 'e1' ) ;
229- assert . equal ( ( output . jsonData as { nodes : Array < { ref : string } > } ) . nodes [ 0 ] ! . ref , 'e1' ) ;
231+ const printed = [ ...output . text ! . matchAll ( / @ e \d + \S * / g) ] . map ( ( match ) => match [ 0 ] ) ;
232+ const jsonRefs = ( output . jsonData as { nodes : Array < { ref : string } > } ) . nodes . map (
233+ ( node ) => node . ref ,
234+ ) ;
235+ assert . deepEqual ( jsonRefs , [ 'e1' , 'e2' , 'e3' ] ) ;
236+ assert . deepEqual ( printed , [ '@e1~s752890' , '@e2~s752890' , '@e3~s752890' ] ) ;
237+ for ( const [ i , pin ] of printed . entries ( ) ) {
238+ assert . deepEqual ( splitRefGenerationSuffix ( pin ) , {
239+ base : `@${ jsonRefs [ i ] } ` ,
240+ generation : 752890 ,
241+ } ) ;
242+ assert . equal ( normalizeRef ( pin ) , jsonRefs [ i ] ) ;
243+ }
230244} ) ;
231245
232246test ( 'output without --scope keeps plain refs even when a refs generation is present' , async ( ) => {
0 commit comments