@allurereport/plugin-api 3.0.0-beta.4 → 3.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config.d.ts +1 -1
- package/dist/config.js +1 -1
- package/dist/resultFile.d.ts +1 -0
- package/dist/utils/tree.d.ts +7 -2
- package/dist/utils/tree.js +106 -16
- package/package.json +3 -2
package/dist/config.d.ts
CHANGED
package/dist/config.js
CHANGED
package/dist/resultFile.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Readable } from "node:stream";
|
|
|
2
2
|
export interface ResultFile {
|
|
3
3
|
readContent: <T>(transform: (stream: Readable) => Promise<T | undefined>) => Promise<T | undefined>;
|
|
4
4
|
getOriginalFileName: () => string;
|
|
5
|
+
getExtension: () => string;
|
|
5
6
|
getContentType: () => string | undefined;
|
|
6
7
|
getContentLength: () => number | undefined;
|
|
7
8
|
asJson: <T>() => Promise<T | undefined>;
|
package/dist/utils/tree.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export declare const
|
|
1
|
+
import { type Comparator, type DefaultTreeGroup, type DefaultTreeLeaf, type TestResult, type TreeData, type TreeGroup, type TreeLeaf } from "@allurereport/core-api";
|
|
2
|
+
export declare const byLabels: (item: TestResult, labelNames: string[]) => string[][];
|
|
3
|
+
export declare const filterTreeLabels: (data: TestResult[], labelNames: string[]) => string[];
|
|
4
|
+
export declare const createTreeByLabels: <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>;
|
|
5
|
+
export declare const filterTree: <L, G>(tree: TreeData<L, G>, predicate: (leaf: TreeLeaf<L>) => boolean) => TreeData<L, G>;
|
|
6
|
+
export declare const sortTree: <L, G>(tree: TreeData<L, G>, comparator: Comparator<TreeLeaf<L>>) => TreeData<L, G>;
|
|
7
|
+
export declare const transformTree: <L, G>(tree: TreeData<L, G>, transformer: (leaf: TreeLeaf<L>, idx: number) => TreeLeaf<L>) => TreeData<L, G>;
|
package/dist/utils/tree.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { findByLabelName, } from "@allurereport/core-api";
|
|
2
|
+
import { emptyStatistic } from "@allurereport/core-api";
|
|
2
3
|
import { md5 } from "./misc.js";
|
|
3
4
|
const addLeaf = (node, nodeId) => {
|
|
4
5
|
if (node.leaves === undefined) {
|
|
@@ -58,21 +59,110 @@ const createTree = (data, classifier, leafFactory, groupFactory, addLeafToGroup
|
|
|
58
59
|
leavesById,
|
|
59
60
|
};
|
|
60
61
|
};
|
|
61
|
-
const byLabels = (item, labelNames) => {
|
|
62
|
+
export const byLabels = (item, labelNames) => {
|
|
62
63
|
return labelNames.map((labelName) => item.labels.filter((label) => labelName === label.name).map((label) => label.value ?? "__unknown") ?? []);
|
|
63
64
|
};
|
|
64
|
-
export const
|
|
65
|
-
return
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
65
|
+
export const filterTreeLabels = (data, labelNames) => {
|
|
66
|
+
return [...labelNames]
|
|
67
|
+
.reverse()
|
|
68
|
+
.filter((labelName) => data.find((item) => findByLabelName(item.labels, labelName)))
|
|
69
|
+
.reverse();
|
|
70
|
+
};
|
|
71
|
+
export const createTreeByLabels = (data, labelNames, leafFactory, groupFactory, addLeafToGroup = () => { }) => {
|
|
72
|
+
const leafFactoryFn = leafFactory ??
|
|
73
|
+
((tr) => {
|
|
74
|
+
const { id, name, status, duration } = tr;
|
|
75
|
+
return {
|
|
76
|
+
nodeId: id,
|
|
77
|
+
name,
|
|
78
|
+
status,
|
|
79
|
+
duration,
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
const groupFactoryFn = groupFactory ??
|
|
83
|
+
((parentId, groupClassifier) => ({
|
|
84
|
+
nodeId: md5((parentId ? `${parentId}.` : "") + groupClassifier),
|
|
85
|
+
name: groupClassifier,
|
|
86
|
+
statistic: emptyStatistic(),
|
|
87
|
+
}));
|
|
88
|
+
return createTree(data, (item) => byLabels(item, labelNames), leafFactoryFn, groupFactoryFn, addLeafToGroup);
|
|
89
|
+
};
|
|
90
|
+
export const filterTree = (tree, predicate) => {
|
|
91
|
+
const visitedGroups = new Set();
|
|
92
|
+
const { root, leavesById, groupsById } = tree;
|
|
93
|
+
const filterGroupLeaves = (group) => {
|
|
94
|
+
if (!predicate) {
|
|
95
|
+
return group;
|
|
96
|
+
}
|
|
97
|
+
if (group.groups?.length) {
|
|
98
|
+
group.groups.forEach((groupId) => {
|
|
99
|
+
const subGroup = groupsById[groupId];
|
|
100
|
+
if (!subGroup || visitedGroups.has(groupId)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
filterGroupLeaves(subGroup);
|
|
104
|
+
visitedGroups.add(groupId);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (group.leaves?.length) {
|
|
108
|
+
group.leaves = group.leaves.filter((leaveId) => predicate(leavesById[leaveId]));
|
|
109
|
+
}
|
|
110
|
+
return group;
|
|
111
|
+
};
|
|
112
|
+
filterGroupLeaves(root);
|
|
113
|
+
return tree;
|
|
114
|
+
};
|
|
115
|
+
export const sortTree = (tree, comparator) => {
|
|
116
|
+
const visitedGroups = new Set();
|
|
117
|
+
const { root, leavesById, groupsById } = tree;
|
|
118
|
+
const sortGroupLeaves = (group) => {
|
|
119
|
+
if (!comparator) {
|
|
120
|
+
return group;
|
|
121
|
+
}
|
|
122
|
+
if (group.groups?.length) {
|
|
123
|
+
group.groups.forEach((groupId) => {
|
|
124
|
+
if (visitedGroups.has(groupId)) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
sortGroupLeaves(groupsById[groupId]);
|
|
128
|
+
visitedGroups.add(groupId);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (group.leaves?.length) {
|
|
132
|
+
group.leaves = group.leaves.sort((a, b) => {
|
|
133
|
+
const leafA = leavesById[a];
|
|
134
|
+
const leafB = leavesById[b];
|
|
135
|
+
return comparator(leafA, leafB);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return group;
|
|
139
|
+
};
|
|
140
|
+
sortGroupLeaves(root);
|
|
141
|
+
return tree;
|
|
142
|
+
};
|
|
143
|
+
export const transformTree = (tree, transformer) => {
|
|
144
|
+
const visitedGroups = new Set();
|
|
145
|
+
const { root, leavesById, groupsById } = tree;
|
|
146
|
+
const transformGroupLeaves = (group) => {
|
|
147
|
+
if (!transformer) {
|
|
148
|
+
return group;
|
|
149
|
+
}
|
|
150
|
+
if (group.groups?.length) {
|
|
151
|
+
group.groups.forEach((groupId) => {
|
|
152
|
+
if (visitedGroups.has(groupId)) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
transformGroupLeaves(groupsById[groupId]);
|
|
156
|
+
visitedGroups.add(groupId);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
if (group.leaves?.length) {
|
|
160
|
+
group.leaves.forEach((leaf, i) => {
|
|
161
|
+
leavesById[leaf] = transformer(leavesById[leaf], i);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return group;
|
|
165
|
+
};
|
|
166
|
+
transformGroupLeaves(root);
|
|
167
|
+
return tree;
|
|
78
168
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allurereport/plugin-api",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.6",
|
|
4
4
|
"description": "Allure Plugin API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"allure"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"test": "rimraf ./out && vitest run"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@allurereport/core-api": "3.0.0-beta.
|
|
29
|
+
"@allurereport/core-api": "3.0.0-beta.6"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@stylistic/eslint-plugin": "^2.6.1",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
36
36
|
"@typescript-eslint/parser": "^8.0.0",
|
|
37
37
|
"@vitest/runner": "^2.1.8",
|
|
38
|
+
"@vitest/snapshot": "^2.1.8",
|
|
38
39
|
"allure-vitest": "^3.0.7",
|
|
39
40
|
"eslint": "^8.57.0",
|
|
40
41
|
"eslint-config-prettier": "^9.1.0",
|