@allurereport/core-api 3.0.0-beta.17 → 3.0.0-beta.19

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.
@@ -0,0 +1,80 @@
1
+ import type { TestStatus } from "../model.js";
2
+ export declare enum ChartType {
3
+ Trend = "trend",
4
+ Pie = "pie",
5
+ TreeMap = "treemap",
6
+ HeatMap = "heatmap",
7
+ Bar = "bar",
8
+ Funnel = "funnel",
9
+ ComingSoon = "coming-soon"
10
+ }
11
+ export declare enum ChartDataType {
12
+ Status = "status",
13
+ Severity = "severity"
14
+ }
15
+ export declare enum BarChartType {
16
+ StatusBySeverity = "statusBySeverity",
17
+ StatusTrend = "statusTrend",
18
+ StatusChangeTrend = "statusChangeTrend"
19
+ }
20
+ export declare enum TreeMapChartType {
21
+ SuccessRateDistribution = "successRateDistribution",
22
+ CoverageDiff = "coverageDiff"
23
+ }
24
+ export declare enum ChartMode {
25
+ Raw = "raw",
26
+ Percent = "percent"
27
+ }
28
+ export type ChartId = string;
29
+ export type TrendPointId = string;
30
+ export type TrendSliceId = string;
31
+ export type BaseMetadata = Record<string, unknown>;
32
+ export interface BaseTrendSliceMetadata extends BaseMetadata {
33
+ executionId: string;
34
+ executionName?: string;
35
+ }
36
+ export interface TrendPoint {
37
+ x: string;
38
+ y: number;
39
+ }
40
+ export type TrendSliceMetadata<Metadata extends BaseMetadata> = BaseTrendSliceMetadata & Metadata;
41
+ export interface TrendSlice<Metadata extends BaseTrendSliceMetadata = BaseTrendSliceMetadata> {
42
+ min: number;
43
+ max: number;
44
+ metadata: TrendSliceMetadata<Metadata>;
45
+ }
46
+ export interface BasePieSlice {
47
+ status: TestStatus;
48
+ count: number;
49
+ }
50
+ export interface PieSlice extends BasePieSlice {
51
+ d: string | null;
52
+ }
53
+ export type PieChartValues = {
54
+ percentage: number;
55
+ slices: PieSlice[];
56
+ };
57
+ export type BarGroupValues<T extends string = string> = Record<T, number>;
58
+ export type BarGroup<G extends string, T extends string = string> = {
59
+ groupId: G;
60
+ } & BarGroupValues<T>;
61
+ export declare enum BarGroupMode {
62
+ Grouped = "grouped",
63
+ Stacked = "stacked"
64
+ }
65
+ export type NewKey<T extends string> = `new${Capitalize<T>}`;
66
+ export type RemovedKey<T extends string> = `removed${Capitalize<T>}`;
67
+ export type TreeMapNode<T extends Record<string, any> = {}> = T & {
68
+ id: string;
69
+ value?: number;
70
+ colorValue?: number;
71
+ children?: TreeMapNode<T>[];
72
+ };
73
+ export type HeatMapPoint = {
74
+ x: string;
75
+ y?: number;
76
+ };
77
+ export type HeatMapSerie<T extends Record<string, any> = Record<string, any>> = {
78
+ id: string;
79
+ data: HeatMapPoint[];
80
+ } & T;
@@ -0,0 +1,36 @@
1
+ export var ChartType;
2
+ (function (ChartType) {
3
+ ChartType["Trend"] = "trend";
4
+ ChartType["Pie"] = "pie";
5
+ ChartType["TreeMap"] = "treemap";
6
+ ChartType["HeatMap"] = "heatmap";
7
+ ChartType["Bar"] = "bar";
8
+ ChartType["Funnel"] = "funnel";
9
+ ChartType["ComingSoon"] = "coming-soon";
10
+ })(ChartType || (ChartType = {}));
11
+ export var ChartDataType;
12
+ (function (ChartDataType) {
13
+ ChartDataType["Status"] = "status";
14
+ ChartDataType["Severity"] = "severity";
15
+ })(ChartDataType || (ChartDataType = {}));
16
+ export var BarChartType;
17
+ (function (BarChartType) {
18
+ BarChartType["StatusBySeverity"] = "statusBySeverity";
19
+ BarChartType["StatusTrend"] = "statusTrend";
20
+ BarChartType["StatusChangeTrend"] = "statusChangeTrend";
21
+ })(BarChartType || (BarChartType = {}));
22
+ export var TreeMapChartType;
23
+ (function (TreeMapChartType) {
24
+ TreeMapChartType["SuccessRateDistribution"] = "successRateDistribution";
25
+ TreeMapChartType["CoverageDiff"] = "coverageDiff";
26
+ })(TreeMapChartType || (TreeMapChartType = {}));
27
+ export var ChartMode;
28
+ (function (ChartMode) {
29
+ ChartMode["Raw"] = "raw";
30
+ ChartMode["Percent"] = "percent";
31
+ })(ChartMode || (ChartMode = {}));
32
+ export var BarGroupMode;
33
+ (function (BarGroupMode) {
34
+ BarGroupMode["Grouped"] = "grouped";
35
+ BarGroupMode["Stacked"] = "stacked";
36
+ })(BarGroupMode || (BarGroupMode = {}));
@@ -0,0 +1,6 @@
1
+ import type { PieArcDatum } from "d3-shape";
2
+ import type { BasePieSlice, PieChartValues, Statistic } from "../index.js";
3
+ export declare const getPercentage: (value: number, total: number) => number;
4
+ export declare const d3Arc: import("d3-shape").Arc<any, PieArcDatum<BasePieSlice>>;
5
+ export declare const d3Pie: import("d3-shape").Pie<any, BasePieSlice>;
6
+ export declare const getPieChartValues: (stats: Statistic) => PieChartValues;
@@ -0,0 +1,34 @@
1
+ import { arc, pie } from "d3-shape";
2
+ import { statusesList } from "../constants.js";
3
+ export const getPercentage = (value, total) => Math.floor((value / total) * 10000) / 100;
4
+ export const d3Arc = arc().innerRadius(40).outerRadius(50).cornerRadius(2).padAngle(0.03);
5
+ export const d3Pie = pie()
6
+ .value((d) => d.count)
7
+ .padAngle(0.03)
8
+ .sortValues((a, b) => a - b);
9
+ export const getPieChartValues = (stats) => {
10
+ const convertedStatuses = statusesList
11
+ .filter((status) => !!stats?.[status])
12
+ .map((status) => ({
13
+ status,
14
+ count: stats[status],
15
+ }));
16
+ const arcsData = d3Pie(convertedStatuses);
17
+ const slices = arcsData
18
+ .map((arcData) => {
19
+ const d = d3Arc(arcData);
20
+ if (!d) {
21
+ return null;
22
+ }
23
+ return {
24
+ d,
25
+ ...arcData.data,
26
+ };
27
+ })
28
+ .filter((item) => item !== null);
29
+ const percentage = getPercentage(stats.passed ?? 0, stats.total);
30
+ return {
31
+ slices,
32
+ percentage,
33
+ };
34
+ };
package/dist/history.d.ts CHANGED
@@ -11,6 +11,8 @@ export interface HistoryTestResult {
11
11
  duration?: number;
12
12
  labels?: TestLabel[];
13
13
  url: string;
14
+ historyId?: string;
15
+ reportLinks?: any[];
14
16
  }
15
17
  export interface HistoryDataPoint {
16
18
  uuid: string;
package/dist/index.d.ts CHANGED
@@ -9,6 +9,7 @@ export type * from "./model.js";
9
9
  export type * from "./testCase.js";
10
10
  export type * from "./testPlan.js";
11
11
  export type * from "./config.js";
12
+ export * from "./static.js";
12
13
  export * from "./utils/step.js";
13
14
  export type * from "./utils/tree.js";
14
15
  export * from "./utils/time.js";
@@ -18,3 +19,7 @@ export * from "./utils/label.js";
18
19
  export * from "./utils/testplan.js";
19
20
  export * from "./utils/status.js";
20
21
  export * from "./utils/environment.js";
22
+ export * from "./utils/history.js";
23
+ export * from "./utils/strings.js";
24
+ export * from "./charts/types.js";
25
+ export * from "./charts/utils.js";
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./constants.js";
2
2
  export * from "./ci.js";
3
+ export * from "./static.js";
3
4
  export * from "./utils/step.js";
4
5
  export * from "./utils/time.js";
5
6
  export * from "./utils/comparator.js";
@@ -8,3 +9,7 @@ export * from "./utils/label.js";
8
9
  export * from "./utils/testplan.js";
9
10
  export * from "./utils/status.js";
10
11
  export * from "./utils/environment.js";
12
+ export * from "./utils/history.js";
13
+ export * from "./utils/strings.js";
14
+ export * from "./charts/types.js";
15
+ export * from "./charts/utils.js";
@@ -0,0 +1,12 @@
1
+ export declare const createScriptTag: (src: string, options?: {
2
+ async?: false;
3
+ defer?: false;
4
+ }) => string;
5
+ export declare const createStylesLinkTag: (src: string) => string;
6
+ export declare const createFontLinkTag: (src: string) => string;
7
+ export declare const createFaviconLinkTag: (src: string) => string;
8
+ export declare const createBaseUrlScript: () => string;
9
+ export declare const createReportDataScript: (reportFiles?: {
10
+ name: string;
11
+ value: string;
12
+ }[]) => string;
package/dist/static.js ADDED
@@ -0,0 +1,55 @@
1
+ export const createScriptTag = (src, options) => {
2
+ return `<script ${options?.async ? "async" : ""} ${options?.defer ? "defer" : ""} src="${src}"></script>`;
3
+ };
4
+ export const createStylesLinkTag = (src) => {
5
+ return `<link rel="stylesheet" type="text/css" href="${src}">`;
6
+ };
7
+ export const createFontLinkTag = (src) => {
8
+ return `<link rel="preload" href="${src}" as="font" type="font/woff" crossorigin /> `;
9
+ };
10
+ export const createFaviconLinkTag = (src) => {
11
+ return `<link rel="icon" href="${src}">`;
12
+ };
13
+ export const createBaseUrlScript = () => {
14
+ return `
15
+ <script>
16
+ const { origin, pathname } = window.location;
17
+ const url = new URL(pathname, origin);
18
+ const baseEl = document.createElement("base");
19
+
20
+ baseEl.href = url.toString();
21
+
22
+ window.document.head.appendChild(baseEl);
23
+ </script>
24
+ `;
25
+ };
26
+ export const createReportDataScript = (reportFiles = []) => {
27
+ if (!reportFiles?.length) {
28
+ return `
29
+ <script async>
30
+ window.allureReportDataReady = true;
31
+ </script>
32
+ `;
33
+ }
34
+ const reportFilesDeclaration = reportFiles.map(({ name, value }) => `d('${name}','${value}')`).join(",");
35
+ return `
36
+ <script async>
37
+ window.allureReportDataReady = false;
38
+ window.allureReportData = window.allureReportData || {};
39
+
40
+ function d(name, value){
41
+ return new Promise(function (resolve) {
42
+ window.allureReportData[name] = value;
43
+
44
+ return resolve(true);
45
+ });
46
+ }
47
+ </script>
48
+ <script defer>
49
+ Promise.allSettled([${reportFilesDeclaration}])
50
+ .then(function(){
51
+ window.allureReportDataReady = true;
52
+ })
53
+ </script>
54
+ `;
55
+ };
@@ -0,0 +1,3 @@
1
+ import type { HistoryDataPoint, HistoryTestResult } from "../history.js";
2
+ import type { TestResult } from "../model.js";
3
+ export declare const htrsByTr: (hdps: HistoryDataPoint[], tr: TestResult | HistoryTestResult) => HistoryTestResult[];
@@ -0,0 +1,22 @@
1
+ export const htrsByTr = (hdps, tr) => {
2
+ if (!tr?.historyId) {
3
+ return [];
4
+ }
5
+ return hdps.reduce((acc, dp) => {
6
+ const htr = dp.testResults[tr.historyId];
7
+ if (htr) {
8
+ if (dp.url) {
9
+ const url = new URL(dp.url);
10
+ url.hash = tr.id;
11
+ acc.push({
12
+ ...htr,
13
+ url: url.toString(),
14
+ });
15
+ }
16
+ else {
17
+ acc.push(htr);
18
+ }
19
+ }
20
+ return acc;
21
+ }, []);
22
+ };
@@ -0,0 +1 @@
1
+ export declare const capitalize: <T extends string>(str: T) => Capitalize<T> | undefined;
@@ -0,0 +1,6 @@
1
+ export const capitalize = (str) => {
2
+ if (!str) {
3
+ return;
4
+ }
5
+ return (str.charAt(0).toLocaleUpperCase() + str.slice(1));
6
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allurereport/core-api",
3
- "version": "3.0.0-beta.17",
3
+ "version": "3.0.0-beta.19",
4
4
  "description": "Allure Core API",
5
5
  "keywords": [
6
6
  "allure"
@@ -25,15 +25,19 @@
25
25
  "eslint:format": "eslint --fix ./src/**/*.{js,jsx,ts,tsx}",
26
26
  "test": "rimraf ./out && vitest run"
27
27
  },
28
+ "dependencies": {
29
+ "d3-shape": "^3.2.0"
30
+ },
28
31
  "devDependencies": {
29
32
  "@stylistic/eslint-plugin": "^2.6.1",
33
+ "@types/d3-shape": "^3.1.6",
30
34
  "@types/eslint": "^8.56.11",
31
35
  "@types/node": "^20.17.9",
32
36
  "@typescript-eslint/eslint-plugin": "^8.0.0",
33
37
  "@typescript-eslint/parser": "^8.0.0",
34
38
  "@vitest/runner": "^2.1.9",
35
39
  "@vitest/snapshot": "^2.1.9",
36
- "allure-vitest": "^3.3.0",
40
+ "allure-vitest": "^3.3.3",
37
41
  "eslint": "^8.57.0",
38
42
  "eslint-config-prettier": "^9.1.0",
39
43
  "eslint-plugin-import": "^2.29.1",