@allurereport/web-commons 3.20.1 → 3.21.0

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.
@@ -31,8 +31,9 @@ export declare const fetchAttachment: (id: string, ext: string, contentType?: st
31
31
  export declare const blobAttachment: (id: string, ext: string, contentType: string) => Promise<Blob>;
32
32
  export declare const downloadAttachment: (id: string, ext: string, contentType: string) => Promise<void>;
33
33
  export declare const openAttachmentInNewTab: (id: string, ext: string, contentType: string) => Promise<void>;
34
- export type AttachmentType = "css" | "json" | "image" | "svg" | "code" | "text" | "markdown" | "html" | "table" | "video" | "uri" | "archive" | "image-diff" | "http";
35
- export declare const PREVIEWABLE_CONTENT_TYPES: readonly ["text/html", "text/csv", "text/markdown", "text/tab-separated-values", "text/uri-list"];
34
+ export type AttachmentType = "css" | "json" | "image" | "svg" | "code" | "text" | "markdown" | "html" | "table" | "video" | "uri" | "archive" | "image-diff" | "http" | "mermaid";
35
+ export declare const MERMAID_CONTENT_TYPE = "application/vnd.allure.diagrams.mermaid";
36
+ export declare const PREVIEWABLE_CONTENT_TYPES: readonly ["application/vnd.allure.diagrams.mermaid", "text/html", "text/csv", "text/markdown", "text/tab-separated-values", "text/uri-list"];
36
37
  export declare const isPreviewableContentType: (type?: string) => boolean;
37
38
  export declare const extname: (str: string) => string | undefined;
38
39
  export declare const isSyntaxHighlightSupported: (payload?: {
@@ -30,6 +30,7 @@ export const fetchAttachment = async (id, ext, contentType) => {
30
30
  case "code":
31
31
  case "html":
32
32
  case "markdown":
33
+ case "mermaid":
33
34
  case "table":
34
35
  case "text": {
35
36
  const text = await response.text();
@@ -77,14 +78,16 @@ export const openAttachmentInNewTab = async (id, ext, contentType) => {
77
78
  const linkUrl = URL.createObjectURL(blob);
78
79
  globalThis.open(linkUrl, "_blank");
79
80
  };
81
+ export const MERMAID_CONTENT_TYPE = "application/vnd.allure.diagrams.mermaid";
80
82
  export const PREVIEWABLE_CONTENT_TYPES = [
83
+ MERMAID_CONTENT_TYPE,
81
84
  "text/html",
82
85
  "text/csv",
83
86
  "text/markdown",
84
87
  "text/tab-separated-values",
85
88
  "text/uri-list",
86
89
  ];
87
- export const isPreviewableContentType = (type) => !!type && PREVIEWABLE_CONTENT_TYPES.includes(type);
90
+ export const isPreviewableContentType = (type) => !!type && PREVIEWABLE_CONTENT_TYPES.includes(type.split(";")[0].trim().toLowerCase());
88
91
  const HIGHLIGHT_EXTS = new Set([
89
92
  "js",
90
93
  "mjs",
@@ -263,6 +266,8 @@ export const attachmentType = (type) => {
263
266
  return "image-diff";
264
267
  case "application/vnd.allure.http+json":
265
268
  return "http";
269
+ case MERMAID_CONTENT_TYPE:
270
+ return "mermaid";
266
271
  default:
267
272
  return null;
268
273
  }
@@ -43,7 +43,8 @@ const getStats = (testResults) => {
43
43
  export const generateDurationDynamicsChart = (props) => {
44
44
  const { options, storeData } = props;
45
45
  const { title, limit = DEFAULT_CHART_HISTORY_LIMIT } = options;
46
- const { historyDataPoints, testResults } = storeData;
46
+ const { historyDataPoints } = storeData;
47
+ const testResults = storeData.allTestResults ?? storeData.testResults;
47
48
  const limitedHistoryPoints = limitHistoryDataPoints(historyDataPoints, limit - 1).sort((a, b) => a.timestamp - b.timestamp);
48
49
  const currentReportTimestamp = testResults.reduce((acc, testResult) => Math.max(acc, testResult.stop ?? 0), 0);
49
50
  if (limitedHistoryPoints.length === 0) {
@@ -63,7 +64,7 @@ export const generateDurationDynamicsChart = (props) => {
63
64
  ...limitedHistoryPoints,
64
65
  {
65
66
  testResults: testResults.reduce((acc, testResult) => {
66
- acc[testResult.retryHash ?? testResult.id] = testResult;
67
+ acc[testResult.id] = testResult;
67
68
  return acc;
68
69
  }, {}),
69
70
  uuid: "current",
@@ -51,7 +51,7 @@ const getBucketsFromDurations = (durations) => {
51
51
  export const generateDurationsChart = (props) => {
52
52
  const { options, storeData } = props;
53
53
  const { groupBy = BY_NONE, title } = options;
54
- const { testResults } = storeData;
54
+ const testResults = storeData.allTestResults ?? storeData.testResults;
55
55
  const enrichedTrs = enrichAndFilterTrs(testResults, groupBy);
56
56
  const durations = getDurations(enrichedTrs);
57
57
  const buckets = durations.size > 0 ? getBucketsFromDurations(Array.from(durations)) : [];
@@ -28,6 +28,19 @@ const generateChartData = async (props) => {
28
28
  }
29
29
  return trs;
30
30
  };
31
+ const getAllTrs = async () => {
32
+ let trs = [];
33
+ if (envId) {
34
+ trs = await store.testResultsByEnvironmentId(envId, { includeRetries: true });
35
+ }
36
+ else {
37
+ trs = await store.allTestResults({ includeRetries: true });
38
+ }
39
+ if (filter) {
40
+ trs = trs.filter(filter);
41
+ }
42
+ return trs;
43
+ };
31
44
  const getHistoryDataPoints = async () => {
32
45
  let historyDataPoints = [];
33
46
  if (envId) {
@@ -43,7 +56,7 @@ const generateChartData = async (props) => {
43
56
  try {
44
57
  return filter(tr);
45
58
  }
46
- catch (error) {
59
+ catch {
47
60
  return false;
48
61
  }
49
62
  });
@@ -66,7 +79,7 @@ const generateChartData = async (props) => {
66
79
  getHistoryDataPoints(),
67
80
  getTrs(),
68
81
  getStatistic(),
69
- store.allTestResults({ includeRetries: true }),
82
+ getAllTrs(),
70
83
  ]).then(([historyDataPoints, testResults, statistic, allTestResults]) => ({
71
84
  historyDataPoints,
72
85
  testResults,
@@ -7,19 +7,18 @@ export type SubtreeNodeState = {
7
7
  };
8
8
  export declare const isSubtreeFirstLevelOnlyOpened: (rootId: string, rootOpenedByDefault: boolean, subtreeNodes: SubtreeNodeState[], isNodeOpened: (id: string, openedByDefault: boolean) => boolean) => boolean;
9
9
  export declare const isSubtreeExpandedAll: (subtreeNodes: SubtreeNodeState[], isNodeOpened: (id: string, openedByDefault: boolean) => boolean) => boolean;
10
- export declare const getNextSubtreeToggleState: (payload: {
10
+ export type SubtreeTogglePayload = {
11
11
  hasOnlyLeafResults: boolean;
12
12
  isSubtreeCollapsedAll: boolean;
13
13
  isSubtreeFirstLevelOnly: boolean;
14
14
  isSubtreeExpandedAll: boolean;
15
15
  lastSubtreeToggle: SubtreeToggleState | null;
16
- }) => SubtreeToggleState;
16
+ };
17
+ export declare const getNextSubtreeToggleState: (payload: SubtreeTogglePayload) => SubtreeToggleState;
18
+ export type SubtreeToggleAction = "expand-first-level" | "collapse-to-first-level" | "expand-all" | "collapse-all";
19
+ export declare const getSubtreeToggleAction: (payload: SubtreeTogglePayload) => SubtreeToggleAction;
17
20
  export declare const resolveNextSubtreeToggleState: (subtreeNodes: SubtreeNodeState[], isNodeOpened: (id: string, openedByDefault: boolean) => boolean, lastSubtreeToggle: SubtreeToggleState | null) => {
18
21
  nextState: SubtreeToggleState;
19
22
  nextLastToggle: SubtreeToggleState | null;
20
23
  };
21
- export declare const getSubtreeToggleIcon: (payload: {
22
- hasOnlyLeafResults: boolean;
23
- isSubtreeCollapsedAll: boolean;
24
- isSubtreeFirstLevelOnly: boolean;
25
- }) => SubtreeToggleIconState;
24
+ export declare const getSubtreeToggleIcon: (payload: SubtreeTogglePayload) => SubtreeToggleIconState;
@@ -21,6 +21,16 @@ export const getNextSubtreeToggleState = (payload) => {
21
21
  }
22
22
  return "all";
23
23
  };
24
+ export const getSubtreeToggleAction = (payload) => {
25
+ const nextState = getNextSubtreeToggleState(payload);
26
+ if (nextState === "all") {
27
+ return "expand-all";
28
+ }
29
+ if (nextState === "none") {
30
+ return "collapse-all";
31
+ }
32
+ return payload.isSubtreeCollapsedAll ? "expand-first-level" : "collapse-to-first-level";
33
+ };
24
34
  export const resolveNextSubtreeToggleState = (subtreeNodes, isNodeOpened, lastSubtreeToggle) => {
25
35
  const root = subtreeNodes.find((node) => node.isRoot);
26
36
  if (!root || subtreeNodes.length === 0) {
@@ -43,15 +53,14 @@ export const resolveNextSubtreeToggleState = (subtreeNodes, isNodeOpened, lastSu
43
53
  };
44
54
  };
45
55
  export const getSubtreeToggleIcon = (payload) => {
46
- const { hasOnlyLeafResults, isSubtreeCollapsedAll, isSubtreeFirstLevelOnly } = payload;
47
- if (hasOnlyLeafResults) {
48
- return isSubtreeCollapsedAll ? "single-down" : "single-up";
49
- }
50
- if (isSubtreeCollapsedAll) {
51
- return "single-down";
52
- }
53
- if (isSubtreeFirstLevelOnly) {
54
- return "double-down";
56
+ switch (getSubtreeToggleAction(payload)) {
57
+ case "expand-first-level":
58
+ return "single-down";
59
+ case "expand-all":
60
+ return payload.hasOnlyLeafResults ? "single-down" : "double-down";
61
+ case "collapse-to-first-level":
62
+ return "double-up";
63
+ case "collapse-all":
64
+ return "single-up";
55
65
  }
56
- return "double-up";
57
66
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allurereport/web-commons",
3
- "version": "3.20.1",
3
+ "version": "3.21.0",
4
4
  "description": "Collection of utilities used across the web Allure reports",
5
5
  "keywords": [
6
6
  "allure",
@@ -22,27 +22,30 @@
22
22
  "build": "run clean && tsc --project ./tsconfig.json",
23
23
  "clean": "rimraf ./dist",
24
24
  "test": "vitest run",
25
+ "test:unit": "yarn test",
25
26
  "lint": "oxlint --import-plugin src test features stories",
26
27
  "lint:fix": "oxlint --import-plugin --fix src test features stories"
27
28
  },
28
29
  "dependencies": {
29
- "@allurereport/aql": "3.20.1",
30
- "@allurereport/charts-api": "3.20.1",
31
- "@allurereport/core-api": "3.20.1",
32
- "@allurereport/plugin-api": "3.20.1",
30
+ "@allurereport/aql": "3.21.0",
31
+ "@allurereport/charts-api": "3.21.0",
32
+ "@allurereport/core-api": "3.21.0",
33
+ "@allurereport/plugin-api": "3.21.0",
33
34
  "@preact/signals": "^2.6.1",
34
35
  "@preact/signals-core": "^1.12.2",
35
36
  "ansi-to-html": "^0.7.2",
36
37
  "d3-interpolate": "^3.0.1",
37
38
  "d3-scale": "^4.0.2",
38
39
  "d3-shape": "^3.2.0",
39
- "dompurify": "^3.4.0",
40
+ "dompurify": "3.4.16",
40
41
  "nanoid": "^5.1.16"
41
42
  },
42
43
  "devDependencies": {
44
+ "@allurereport/test-config": "3.21.0",
43
45
  "@types/d3-interpolate": "^3.0.4",
44
46
  "@types/d3-scale": "^4.0.9",
45
47
  "@types/d3-shape": "^3.1.8",
48
+ "@vitest/coverage-istanbul": "^4.1.0",
46
49
  "@vitest/runner": "^2",
47
50
  "allure-js-commons": "^3",
48
51
  "allure-vitest": "^3",