@allurereport/web-commons 3.0.0-beta.14 → 3.0.0-beta.16

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.
@@ -35,6 +35,7 @@ export const getSeverityTrendData = (testResults, reportName, historyPoints, cha
35
35
  }, {
36
36
  type: chartOptions.type,
37
37
  dataType: chartOptions.dataType,
38
+ mode: chartOptions.mode,
38
39
  title: chartOptions.title,
39
40
  points: {},
40
41
  slices: {},
@@ -1,5 +1,5 @@
1
1
  import { statusesList } from "@allurereport/core-api";
2
- import { createEmptySeries, createEmptyStats, getTrendDataGeneric, mergeTrendDataGeneric, normalizeStatistic } from "../charts.js";
2
+ import { createEmptySeries, createEmptyStats, getTrendDataGeneric, mergeTrendDataGeneric, normalizeStatistic, } from "../charts.js";
3
3
  export const getStatusTrendData = (currentStatistic, reportName, historyPoints, chartOptions) => {
4
4
  const { limit } = chartOptions;
5
5
  const historyLimit = limit && limit > 0 ? Math.max(0, limit - 1) : undefined;
@@ -26,6 +26,7 @@ export const getStatusTrendData = (currentStatistic, reportName, historyPoints,
26
26
  }, {
27
27
  type: chartOptions.type,
28
28
  dataType: chartOptions.dataType,
29
+ mode: chartOptions.mode,
29
30
  title: chartOptions.title,
30
31
  points: {},
31
32
  slices: {},
package/dist/charts.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { SeverityLevel, TestResult, TestStatus } from "@allurereport/core-api";
2
2
  import type { PieArcDatum } from "d3-shape";
3
3
  export type BasePieSlice = Pick<PieSlice, "status" | "count">;
4
+ export declare const DEFAULT_CHART_HISTORY_LIMIT = 10;
4
5
  export declare const d3Arc: import("d3-shape").Arc<any, PieArcDatum<BasePieSlice>>;
5
6
  export declare const d3Pie: import("d3-shape").Pie<any, BasePieSlice>;
6
7
  export declare const getPercentage: (value: number, total: number) => number;
@@ -8,11 +9,14 @@ export declare enum ChartType {
8
9
  Trend = "trend",
9
10
  Pie = "pie"
10
11
  }
11
- export declare enum ChartData {
12
+ export declare enum ChartDataType {
12
13
  Status = "status",
13
14
  Severity = "severity"
14
15
  }
15
- export type ChartMode = "raw" | "percent";
16
+ export declare enum ChartMode {
17
+ Raw = "raw",
18
+ Percent = "percent"
19
+ }
16
20
  export type ChartId = string;
17
21
  export type ExecutionIdFn = (executionOrder: number) => string;
18
22
  export type ExecutionNameFn = (executionOrder: number) => string;
@@ -22,7 +26,7 @@ export type TrendMetadataFnOverrides = {
22
26
  };
23
27
  export type TrendChartOptions = {
24
28
  type: ChartType.Trend;
25
- dataType: ChartData;
29
+ dataType: ChartDataType;
26
30
  mode?: ChartMode;
27
31
  title?: string;
28
32
  limit?: number;
@@ -47,7 +51,8 @@ export type TrendSlice<Metadata extends BaseMetadata> = {
47
51
  };
48
52
  export type GenericTrendChartData<Metadata extends BaseMetadata, SeriesType extends string> = {
49
53
  type: ChartType.Trend;
50
- dataType: ChartData;
54
+ dataType: ChartDataType;
55
+ mode: ChartMode;
51
56
  title?: string;
52
57
  points: Record<TrendPointId, TrendPoint>;
53
58
  slices: Record<TrendSliceId, TrendSlice<Metadata>>;
package/dist/charts.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { arc, pie } from "d3-shape";
2
+ export const DEFAULT_CHART_HISTORY_LIMIT = 10;
2
3
  export const d3Arc = arc().innerRadius(40).outerRadius(50).cornerRadius(2).padAngle(0.03);
3
4
  export const d3Pie = pie()
4
5
  .value((d) => d.count)
@@ -10,11 +11,16 @@ export var ChartType;
10
11
  ChartType["Trend"] = "trend";
11
12
  ChartType["Pie"] = "pie";
12
13
  })(ChartType || (ChartType = {}));
13
- export var ChartData;
14
- (function (ChartData) {
15
- ChartData["Status"] = "status";
16
- ChartData["Severity"] = "severity";
17
- })(ChartData || (ChartData = {}));
14
+ export var ChartDataType;
15
+ (function (ChartDataType) {
16
+ ChartDataType["Status"] = "status";
17
+ ChartDataType["Severity"] = "severity";
18
+ })(ChartDataType || (ChartDataType = {}));
19
+ export var ChartMode;
20
+ (function (ChartMode) {
21
+ ChartMode["Raw"] = "raw";
22
+ ChartMode["Percent"] = "percent";
23
+ })(ChartMode || (ChartMode = {}));
18
24
  export const createEmptyStats = (items) => items.reduce((acc, item) => ({ ...acc, [item]: 0 }), {});
19
25
  export const createEmptySeries = (items) => items.reduce((acc, item) => ({ ...acc, [item]: [] }), {});
20
26
  export const normalizeStatistic = (statistic, itemType) => {
@@ -50,7 +56,7 @@ const calculatePercentValues = (stats, executionId, itemType) => {
50
56
  const value = stats[item] ?? 0;
51
57
  points[pointId] = {
52
58
  x: executionId,
53
- y: (value / total) * 100,
59
+ y: value / total,
54
60
  };
55
61
  series[item].push(pointId);
56
62
  });
@@ -81,10 +87,10 @@ export const mergeTrendDataGeneric = (trendData, trendDataPart, itemType) => {
81
87
  };
82
88
  };
83
89
  export const getTrendDataGeneric = (stats, reportName, executionOrder, itemType, chartOptions) => {
84
- const { type, dataType, title, mode = "raw", metadata = {} } = chartOptions;
90
+ const { type, dataType, title, mode = ChartMode.Raw, metadata = {} } = chartOptions;
85
91
  const { executionIdAccessor, executionNameAccessor } = metadata;
86
92
  const executionId = executionIdAccessor ? executionIdAccessor(executionOrder) : `execution-${executionOrder}`;
87
- const { points, series } = mode === "percent"
93
+ const { points, series } = mode === ChartMode.Percent
88
94
  ? calculatePercentValues(stats, executionId, itemType)
89
95
  : calculateRawValues(stats, executionId, itemType);
90
96
  const slices = {};
@@ -107,6 +113,7 @@ export const getTrendDataGeneric = (stats, reportName, executionOrder, itemType,
107
113
  return {
108
114
  type,
109
115
  dataType,
116
+ mode,
110
117
  title,
111
118
  points,
112
119
  slices,
package/dist/data.d.ts CHANGED
@@ -5,7 +5,11 @@ export declare const createReportDataScript: (reportFiles?: {
5
5
  }[]) => string;
6
6
  export declare const ensureReportDataReady: () => Promise<unknown>;
7
7
  export declare const loadReportData: (name: string) => Promise<string>;
8
- export declare const reportDataUrl: (path: string, contentType?: string) => Promise<string>;
9
- export declare const fetchReportJsonData: <T>(path: string) => Promise<T>;
8
+ export declare const reportDataUrl: (path: string, contentType?: string, params?: {
9
+ bustCache: boolean;
10
+ }) => Promise<string>;
11
+ export declare const fetchReportJsonData: <T>(path: string, params?: {
12
+ bustCache: boolean;
13
+ }) => Promise<T>;
10
14
  export declare const fetchReportAttachment: (path: string, contentType?: string) => Promise<Response>;
11
15
  export declare const getReportOptions: <T>() => T;
package/dist/data.js CHANGED
@@ -49,22 +49,26 @@ export const loadReportData = async (name) => {
49
49
  }
50
50
  });
51
51
  };
52
- export const reportDataUrl = async (path, contentType = "application/octet-stream") => {
52
+ export const reportDataUrl = async (path, contentType = "application/octet-stream", params) => {
53
53
  if (globalThis.allureReportData) {
54
- const dataKey = path.replace(/\?attachment$/, "");
54
+ const [dataKey] = path.split("?");
55
55
  const value = await loadReportData(dataKey);
56
56
  return `data:${contentType};base64,${value}`;
57
57
  }
58
58
  const baseEl = globalThis.document.head.querySelector("base")?.href ?? "https://localhost";
59
59
  const url = new URL(path, baseEl);
60
60
  const liveReloadHash = globalThis.localStorage.getItem(ALLURE_LIVE_RELOAD_HASH_STORAGE_KEY);
61
+ const cacheKey = globalThis.allureReportOptions?.cacheKey;
61
62
  if (liveReloadHash) {
62
63
  url.searchParams.set("live_reload_hash", liveReloadHash);
63
64
  }
64
- return url.pathname + url.search + url.hash;
65
+ if (params?.bustCache && cacheKey) {
66
+ url.searchParams.set("v", cacheKey);
67
+ }
68
+ return url.toString();
65
69
  };
66
- export const fetchReportJsonData = async (path) => {
67
- const url = await reportDataUrl(path);
70
+ export const fetchReportJsonData = async (path, params) => {
71
+ const url = await reportDataUrl(path, undefined, params);
68
72
  const res = await globalThis.fetch(url);
69
73
  if (!res.ok) {
70
74
  throw new Error(`Failed to fetch ${url}, response status: ${res.status}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allurereport/web-commons",
3
- "version": "3.0.0-beta.14",
3
+ "version": "3.0.0-beta.16",
4
4
  "description": "Collection of utilities used across the web Allure reports",
5
5
  "keywords": [
6
6
  "allure",
@@ -23,7 +23,7 @@
23
23
  "clean": "rimraf ./dist"
24
24
  },
25
25
  "dependencies": {
26
- "@allurereport/core-api": "3.0.0-beta.14"
26
+ "@allurereport/core-api": "3.0.0-beta.16"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@stylistic/eslint-plugin": "^2.6.1",
@@ -31,7 +31,7 @@
31
31
  "@types/eslint": "^8.56.11",
32
32
  "@typescript-eslint/eslint-plugin": "^8.0.0",
33
33
  "@typescript-eslint/parser": "^8.0.0",
34
- "@vitest/runner": "^2.1.8",
34
+ "@vitest/runner": "^2.1.9",
35
35
  "allure-js-commons": "^3.0.9",
36
36
  "allure-vitest": "^3.0.9",
37
37
  "d3-shape": "^3.2.0",
@@ -45,6 +45,6 @@
45
45
  "rimraf": "^6.0.1",
46
46
  "tslib": "^2.7.0",
47
47
  "typescript": "^5.6.3",
48
- "vitest": "^2.1.8"
48
+ "vitest": "^2.1.9"
49
49
  }
50
50
  }