@allurereport/plugin-api 3.0.0-beta.3 → 3.0.0-beta.5

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 CHANGED
@@ -8,4 +8,4 @@ export interface Config {
8
8
  qualityGate?: QualityGateConfig;
9
9
  plugins?: Record<string, PluginDescriptor>;
10
10
  }
11
- export declare const defineConfig: (allureConfig: Config) => Promise<Config>;
11
+ export declare const defineConfig: (allureConfig: Config) => Config;
package/dist/config.js CHANGED
@@ -1,3 +1,3 @@
1
- export const defineConfig = async (allureConfig) => {
1
+ export const defineConfig = (allureConfig) => {
2
2
  return allureConfig;
3
3
  };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export * from "./config.js";
2
- export * from "./plugin.js";
3
- export * from "./qualityGate.js";
4
- export * from "./store.js";
5
- export * from "./resultFile.js";
2
+ export type * from "./plugin.js";
3
+ export type * from "./qualityGate.js";
4
+ export type * from "./store.js";
5
+ export type * from "./resultFile.js";
6
6
  export * from "./utils/misc.js";
7
7
  export * from "./utils/tree.js";
package/dist/index.js CHANGED
@@ -1,7 +1,3 @@
1
1
  export * from "./config.js";
2
- export * from "./plugin.js";
3
- export * from "./qualityGate.js";
4
- export * from "./store.js";
5
- export * from "./resultFile.js";
6
2
  export * from "./utils/misc.js";
7
3
  export * from "./utils/tree.js";
package/dist/plugin.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AllureStore } from "./store.js";
1
+ import type { AllureStore } from "./store.js";
2
2
  export interface PluginDescriptor {
3
3
  import?: string;
4
4
  enabled?: boolean;
@@ -1,5 +1,4 @@
1
- import "node:fs/promises";
2
- import { Readable } from "node:stream";
1
+ import type { Readable } from "node:stream";
3
2
  export interface ResultFile {
4
3
  readContent: <T>(transform: (stream: Readable) => Promise<T | undefined>) => Promise<T | undefined>;
5
4
  getOriginalFileName: () => string;
@@ -1 +1 @@
1
- import "node:fs/promises";
1
+ export {};
package/dist/store.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { AttachmentLink, HistoryDataPoint, HistoryTestResult, KnownTestFailure, Statistic, TestCase, TestFixtureResult, TestResult } from "@allurereport/core-api";
2
- import { ResultFile } from "./resultFile.js";
2
+ import type { ResultFile } from "./resultFile.js";
3
3
  export interface AllureStore {
4
4
  allTestCases: () => Promise<TestCase[]>;
5
5
  allTestResults: (options?: {
@@ -1,2 +1,7 @@
1
- import type { DefaultTreeGroup, DefaultTreeLeaf, TestResult, TreeData } from "@allurereport/core-api";
2
- export declare const createTreeByLabels: (data: TestResult[], labelNames: string[]) => TreeData<DefaultTreeLeaf, DefaultTreeGroup>;
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>;
@@ -1,4 +1,5 @@
1
- import { emptyStatistic, incrementStatistic } from "@allurereport/core-api";
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 createTreeByLabels = (data, labelNames) => {
65
- return createTree(data, (item) => byLabels(item, labelNames), ({ id, name, status, duration, flaky, retries }) => ({
66
- nodeId: id,
67
- name,
68
- status,
69
- duration,
70
- flaky,
71
- }), (parentId, groupClassifier) => ({
72
- nodeId: md5((parentId ? `${parentId}.` : "") + groupClassifier),
73
- name: groupClassifier,
74
- statistic: emptyStatistic(),
75
- }), (group, leaf) => {
76
- incrementStatistic(group.statistic, leaf.status);
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",
3
+ "version": "3.0.0-beta.5",
4
4
  "description": "Allure Plugin API",
5
5
  "keywords": [
6
6
  "allure"
@@ -21,10 +21,12 @@
21
21
  "scripts": {
22
22
  "build": "run clean && tsc --project ./tsconfig.json",
23
23
  "clean": "rimraf ./dist",
24
+ "eslint": "eslint ./src/**/*.{js,jsx,ts,tsx}",
25
+ "eslint:format": "eslint --fix ./src/**/*.{js,jsx,ts,tsx}",
24
26
  "test": "rimraf ./out && vitest run"
25
27
  },
26
28
  "dependencies": {
27
- "@allurereport/core-api": "3.0.0-beta.3"
29
+ "@allurereport/core-api": "3.0.0-beta.5"
28
30
  },
29
31
  "devDependencies": {
30
32
  "@stylistic/eslint-plugin": "^2.6.1",
@@ -33,6 +35,7 @@
33
35
  "@typescript-eslint/eslint-plugin": "^8.0.0",
34
36
  "@typescript-eslint/parser": "^8.0.0",
35
37
  "@vitest/runner": "^2.1.8",
38
+ "@vitest/snapshot": "^2.1.8",
36
39
  "allure-vitest": "^3.0.7",
37
40
  "eslint": "^8.57.0",
38
41
  "eslint-config-prettier": "^9.1.0",