@@ -3,15 +3,15 @@ import YAML from 'yamljs'
33import  {  loadComponentIntoPage  }  from  './component' 
44import  ComponentElement  from  './types/component-element' 
55
6- const  flattenContainers  =  ( nodes : AXNode [ ] )  => 
6+ const  flattenContainers  =  ( nodes : AXNode [ ] ) :  AXNode [ ]  => 
77  nodes . reduce ( ( acc : AXNode [ ] ,  node : AXNode )  =>  { 
88    const  {  role,  children =  [ ] ,  name,  ...properties  }  =  node 
99    if  ( 
1010      role  ===  'GenericContainer'  && 
1111      Object . keys ( properties ) . length  ===  0  && 
1212      ! name 
1313    )  { 
14-       return  [ ...acc ,  ...children ] 
14+       return  [ ...acc ,  ...flattenContainers ( children ) ] 
1515    } 
1616
1717    return  [ ...acc ,  node ] 
@@ -25,12 +25,10 @@ const removeEmpty = ({ children = [], ...node }: AXNode): AXNode => {
2525    return  value  ===  ''  ? acc  : {  ...acc ,  [ key ] : value  } 
2626  } ,  initialNode ) 
2727
28-   const  flattenedChildren  =  flattenContainers ( children ) 
29- 
30-   return  flattenedChildren . length  >  0 
28+   return  children . length  >  0 
3129    ? { 
3230        ...newNode , 
33-         children : flattenedChildren . map ( removeEmpty ) , 
31+         children : children . map ( removeEmpty ) , 
3432      } 
3533    : newNode 
3634} 
@@ -44,7 +42,10 @@ const a11ySnapshot = async (element: ComponentElement) => {
4442
4543  await  teardown ( ) 
4644
47-   return  YAML . stringify ( removeEmpty ( snapshot ) ,  Infinity ,  2 ) 
45+   const  {  children =  [ ] ,  ...rootNode  }  =  snapshot 
46+   const  flattenedNode  =  {  ...rootNode ,  children : flattenContainers ( children )  } 
47+ 
48+   return  YAML . stringify ( removeEmpty ( flattenedNode ) ,  Infinity ,  2 ) 
4849} 
4950
5051export  {  a11ySnapshot  } 
0 commit comments