@allurereport/plugin-api
Advanced tools
+1
-1
@@ -11,2 +11,2 @@ import type { PluginDescriptor } from "./plugin.js"; | ||
| } | ||
| export declare const defineConfig: (allureConfig: Config) => Promise<Config>; | ||
| export declare const defineConfig: (allureConfig: Config) => Config; |
+1
-1
@@ -1,3 +0,3 @@ | ||
| export const defineConfig = async (allureConfig) => { | ||
| export const defineConfig = (allureConfig) => { | ||
| return allureConfig; | ||
| }; |
@@ -1,2 +0,7 @@ | ||
| import type { DefaultTreeGroup, DefaultTreeLeaf, TestResult, TreeData } from "@allurereport/core-api"; | ||
| export declare const createTreeByLabels: (data: TestResult[], labelNames: string[]) => TreeData<DefaultTreeLeaf, DefaultTreeGroup>; | ||
| import { type Comparator, type DefaultTreeGroup, type DefaultTreeLeaf, type TestResult, type TreeData, type TreeGroup, type TreeLeaf } from "@allurereport/core-api"; | ||
| export declare const byLabels: (item: TestResult, labelNames: string[]) => string[][]; | ||
| export declare const filterTreeLabels: (data: TestResult[], labelNames: string[]) => string[]; | ||
| 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>; | ||
| export declare const filterTree: <L, G>(tree: TreeData<L, G>, predicate: (leaf: TreeLeaf<L>) => boolean) => TreeData<L, G>; | ||
| export declare const sortTree: <L, G>(tree: TreeData<L, G>, comparator: Comparator<TreeLeaf<L>>) => TreeData<L, G>; | ||
| export declare const transformTree: <L, G>(tree: TreeData<L, G>, transformer: (leaf: TreeLeaf<L>, idx: number) => TreeLeaf<L>) => TreeData<L, G>; |
+106
-16
@@ -1,2 +0,3 @@ | ||
| import { emptyStatistic, incrementStatistic } from "@allurereport/core-api"; | ||
| import { findByLabelName, } from "@allurereport/core-api"; | ||
| import { emptyStatistic } from "@allurereport/core-api"; | ||
| import { md5 } from "./misc.js"; | ||
@@ -61,19 +62,108 @@ const addLeaf = (node, nodeId) => { | ||
| }; | ||
| const byLabels = (item, labelNames) => { | ||
| export const byLabels = (item, labelNames) => { | ||
| return labelNames.map((labelName) => item.labels.filter((label) => labelName === label.name).map((label) => label.value ?? "__unknown") ?? []); | ||
| }; | ||
| export const createTreeByLabels = (data, labelNames) => { | ||
| return createTree(data, (item) => byLabels(item, labelNames), ({ id, name, status, duration, flaky }) => ({ | ||
| nodeId: id, | ||
| name, | ||
| status, | ||
| duration, | ||
| flaky, | ||
| }), (parentId, groupClassifier) => ({ | ||
| nodeId: md5((parentId ? `${parentId}.` : "") + groupClassifier), | ||
| name: groupClassifier, | ||
| statistic: emptyStatistic(), | ||
| }), (group, leaf) => { | ||
| incrementStatistic(group.statistic, leaf.status); | ||
| }); | ||
| export const filterTreeLabels = (data, labelNames) => { | ||
| return [...labelNames] | ||
| .reverse() | ||
| .filter((labelName) => data.find((item) => findByLabelName(item.labels, labelName))) | ||
| .reverse(); | ||
| }; | ||
| export const createTreeByLabels = (data, labelNames, leafFactory, groupFactory, addLeafToGroup = () => { }) => { | ||
| const leafFactoryFn = leafFactory ?? | ||
| ((tr) => { | ||
| const { id, name, status, duration } = tr; | ||
| return { | ||
| nodeId: id, | ||
| name, | ||
| status, | ||
| duration, | ||
| }; | ||
| }); | ||
| const groupFactoryFn = groupFactory ?? | ||
| ((parentId, groupClassifier) => ({ | ||
| nodeId: md5((parentId ? `${parentId}.` : "") + groupClassifier), | ||
| name: groupClassifier, | ||
| statistic: emptyStatistic(), | ||
| })); | ||
| return createTree(data, (item) => byLabels(item, labelNames), leafFactoryFn, groupFactoryFn, addLeafToGroup); | ||
| }; | ||
| export const filterTree = (tree, predicate) => { | ||
| const visitedGroups = new Set(); | ||
| const { root, leavesById, groupsById } = tree; | ||
| const filterGroupLeaves = (group) => { | ||
| if (!predicate) { | ||
| return group; | ||
| } | ||
| if (group.groups?.length) { | ||
| group.groups.forEach((groupId) => { | ||
| const subGroup = groupsById[groupId]; | ||
| if (!subGroup || visitedGroups.has(groupId)) { | ||
| return; | ||
| } | ||
| filterGroupLeaves(subGroup); | ||
| visitedGroups.add(groupId); | ||
| }); | ||
| } | ||
| if (group.leaves?.length) { | ||
| group.leaves = group.leaves.filter((leaveId) => predicate(leavesById[leaveId])); | ||
| } | ||
| return group; | ||
| }; | ||
| filterGroupLeaves(root); | ||
| return tree; | ||
| }; | ||
| export const sortTree = (tree, comparator) => { | ||
| const visitedGroups = new Set(); | ||
| const { root, leavesById, groupsById } = tree; | ||
| const sortGroupLeaves = (group) => { | ||
| if (!comparator) { | ||
| return group; | ||
| } | ||
| if (group.groups?.length) { | ||
| group.groups.forEach((groupId) => { | ||
| if (visitedGroups.has(groupId)) { | ||
| return; | ||
| } | ||
| sortGroupLeaves(groupsById[groupId]); | ||
| visitedGroups.add(groupId); | ||
| }); | ||
| } | ||
| if (group.leaves?.length) { | ||
| group.leaves = group.leaves.sort((a, b) => { | ||
| const leafA = leavesById[a]; | ||
| const leafB = leavesById[b]; | ||
| return comparator(leafA, leafB); | ||
| }); | ||
| } | ||
| return group; | ||
| }; | ||
| sortGroupLeaves(root); | ||
| return tree; | ||
| }; | ||
| export const transformTree = (tree, transformer) => { | ||
| const visitedGroups = new Set(); | ||
| const { root, leavesById, groupsById } = tree; | ||
| const transformGroupLeaves = (group) => { | ||
| if (!transformer) { | ||
| return group; | ||
| } | ||
| if (group.groups?.length) { | ||
| group.groups.forEach((groupId) => { | ||
| if (visitedGroups.has(groupId)) { | ||
| return; | ||
| } | ||
| transformGroupLeaves(groupsById[groupId]); | ||
| visitedGroups.add(groupId); | ||
| }); | ||
| } | ||
| if (group.leaves?.length) { | ||
| group.leaves.forEach((leaf, i) => { | ||
| leavesById[leaf] = transformer(leavesById[leaf], i); | ||
| }); | ||
| } | ||
| return group; | ||
| }; | ||
| transformGroupLeaves(root); | ||
| return tree; | ||
| }; |
+3
-2
| { | ||
| "name": "@allurereport/plugin-api", | ||
| "version": "3.0.0-beta.4", | ||
| "version": "3.0.0-beta.5", | ||
| "description": "Allure Plugin API", | ||
@@ -29,3 +29,3 @@ "keywords": [ | ||
| "dependencies": { | ||
| "@allurereport/core-api": "3.0.0-beta.4" | ||
| "@allurereport/core-api": "3.0.0-beta.5" | ||
| }, | ||
@@ -39,2 +39,3 @@ "devDependencies": { | ||
| "@vitest/runner": "^2.1.8", | ||
| "@vitest/snapshot": "^2.1.8", | ||
| "allure-vitest": "^3.0.7", | ||
@@ -41,0 +42,0 @@ "eslint": "^8.57.0", |
15579
33.01%326
41.74%18
5.88%+ Added
- Removed