Skip to content

Commit 5ae8df8

Browse files
committed
fix: a11y snapshot remove generic containers
1 parent 867232d commit 5ae8df8

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/a11y-snapshot.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import YAML from 'yamljs'
33
import { loadComponentIntoPage } from './component'
44
import 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

5051
export { a11ySnapshot }

0 commit comments

Comments
 (0)