@allurereport/plugin-api
Advanced tools
@@ -16,3 +16,4 @@ import { type Comparator, type DefaultTreeGroup, type DefaultTreeLeaf, type TestResult, type TreeData, type TreeGroup, type TreeLeaf } from "@allurereport/core-api"; | ||
| export declare const transformTree: <L, G>(tree: TreeData<L, G>, transformer: (leaf: TreeLeaf<L>, idx: number) => TreeLeaf<L>) => TreeData<L, G>; | ||
| export declare const collapseTreeGroups: <L, G extends DefaultTreeGroup>(tree: TreeData<L, G>, separator?: string) => TreeData<L, G>; | ||
| export declare const createTreeByTitlePath: <T = TestResult, L = DefaultTreeLeaf, G = DefaultTreeGroup>(data: T[], leafFactory?: (item: T) => TreeLeaf<L>, groupFactory?: (parentGroup: string | undefined, groupClassifier: string) => TreeGroup<G>, addLeafToGroup?: (group: TreeGroup<G>, leaf: TreeLeaf<L>) => void) => TreeData<L, G>; | ||
| export declare const createTreeByLabelsAndTitlePath: <T = TestResult, L = DefaultTreeLeaf, G = DefaultTreeGroup>(data: T[], labelNames?: string[], leafFactory?: (item: T) => TreeLeaf<L>, groupFactory?: (parentGroup: string | undefined, groupClassifier: string) => TreeGroup<G>, addLeafToGroup?: (group: TreeGroup<G>, leaf: TreeLeaf<L>) => void) => TreeData<L, G>; |
+33
-0
@@ -232,2 +232,35 @@ import { emptyStatistic } from "@allurereport/core-api"; | ||
| }; | ||
| const DEFAULT_GROUP_PATH_SEPARATOR = " > "; | ||
| export const collapseTreeGroups = (tree, separator = DEFAULT_GROUP_PATH_SEPARATOR) => { | ||
| const { root } = tree; | ||
| const groupsById = tree.groupsById; | ||
| const visited = new Set(); | ||
| const collapseChildren = (node) => { | ||
| node.groups?.forEach((groupId) => { | ||
| if (visited.has(groupId)) { | ||
| return; | ||
| } | ||
| visited.add(groupId); | ||
| const group = groupsById[groupId]; | ||
| if (!group) { | ||
| return; | ||
| } | ||
| while (!group.leaves?.length && group.groups?.length === 1) { | ||
| const child = groupsById[group.groups[0]]; | ||
| if (!child) { | ||
| break; | ||
| } | ||
| group.name = `${group.name}${separator}${child.name}`; | ||
| group.groups = child.groups; | ||
| group.leaves = child.leaves; | ||
| group.statistic = child.statistic; | ||
| delete groupsById[child.nodeId]; | ||
| visited.delete(child.nodeId); | ||
| } | ||
| collapseChildren(group); | ||
| }); | ||
| }; | ||
| collapseChildren(root); | ||
| return tree; | ||
| }; | ||
| export const createTreeByTitlePath = (data, leafFactory, groupFactory, addLeafToGroup = () => { }) => { | ||
@@ -234,0 +267,0 @@ const leafFactoryFn = leafFactory ?? |
+2
-2
| { | ||
| "name": "@allurereport/plugin-api", | ||
| "version": "3.14.0", | ||
| "version": "3.14.1", | ||
| "description": "Allure Plugin API", | ||
@@ -29,3 +29,3 @@ "keywords": [ | ||
| "dependencies": { | ||
| "@allurereport/core-api": "3.14.0" | ||
| "@allurereport/core-api": "3.14.1" | ||
| }, | ||
@@ -32,0 +32,0 @@ "devDependencies": { |
33934
4%736
4.84%+ Added
- Removed