@allurereport/plugin-allure2 3.20.0 → 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.
@@ -1,4 +1,4 @@
1
- import { isStep, redactParameters } from "@allurereport/core-api";
1
+ import { hasRetriesStatusChange, isStep, redactParameters } from "@allurereport/core-api";
2
2
  import { matchCategories } from "./categories.js";
3
3
  import { severityValues } from "./model.js";
4
4
  import { createStatistic, updateStatistic } from "./utils.js";
@@ -170,8 +170,7 @@ export const convertTestResult = (context, test) => {
170
170
  duration: retry.duration,
171
171
  },
172
172
  }));
173
- const retriesStatusChange = isImportantStatus(status) &&
174
- retries.find((retry) => isImportantStatus(retry.status) && retry.status !== status) !== undefined;
173
+ const retriesStatusChange = hasRetriesStatusChange(test, context.retries);
175
174
  const historyItems = context.legacyHistory
176
175
  ? context.legacyHistory.items.map((item) => ({
177
176
  uid: item.uid,
@@ -1,5 +1,5 @@
1
1
  import type { AttachmentLink, GlobalAttachmentLink, HistoryDataPoint, TestError } from "@allurereport/core-api";
2
- import type { ReportFiles, ResultFile } from "@allurereport/plugin-api";
2
+ import type { ExitCode, ReportFiles, ResultFile } from "@allurereport/plugin-api";
3
3
  import type { ReportStaticManifest } from "@allurereport/plugin-api/static-assets";
4
4
  import type { Allure2CategoriesTrendItem, Allure2DurationTrendItem, Allure2ExecutorInfo, Allure2LegacyHistoryTrendItem, Allure2RetryTrendItem, Allure2TestResult } from "./model.js";
5
5
  import type { Allure2DataWriter, ReportFile } from "./writer.js";
@@ -13,6 +13,7 @@ export declare const generateStaticFiles: (payload: {
13
13
  reportFiles: ReportFiles;
14
14
  reportDataFiles: ReportFile[];
15
15
  reportUuid: string;
16
+ overviewHref?: string;
16
17
  }) => Promise<void>;
17
18
  export declare const generateTree: (writer: Allure2DataWriter, name: string, labelNames: string[], tests: Allure2TestResult[]) => Promise<void>;
18
19
  export declare const generatePackagesData: (writer: Allure2DataWriter, tests: Allure2TestResult[]) => Promise<void>;
@@ -31,4 +32,4 @@ export declare const generateDurationTrendData: (writer: Allure2DataWriter, test
31
32
  export declare const generateRetryTrendData: (writer: Allure2DataWriter, tests: Allure2TestResult[], history?: Allure2RetryTrendItem[], executor?: Partial<Allure2ExecutorInfo>) => Promise<void>;
32
33
  export declare const generateCategoriesTrendData: (writer: Allure2DataWriter, tests: Allure2TestResult[], history?: Allure2CategoriesTrendItem[], executor?: Partial<Allure2ExecutorInfo>) => Promise<void>;
33
34
  export declare const generateAttachmentsData: (writer: Allure2DataWriter, attachmentLinks: AttachmentLink[], contentFunction: (id: string) => Promise<ResultFile | undefined>) => Promise<Map<string, string>>;
34
- export declare const generateGlobalsData: (writer: Allure2DataWriter, globalErrors: TestError[], globalAttachments: GlobalAttachmentLink[], attachmentMap: Map<string, string>, attachmentTimestamps?: Record<string, number>, errorTimestamps?: Array<number | undefined>) => Promise<void>;
35
+ export declare const generateGlobalsData: (writer: Allure2DataWriter, globalErrors: TestError[], globalAttachments: GlobalAttachmentLink[], attachmentMap: Map<string, string>, attachmentTimestamps?: Record<string, number>, errorTimestamps?: Array<number | undefined>, exitCode?: ExitCode) => Promise<void>;
@@ -1,4 +1,4 @@
1
- import { createBaseUrlScript, createScriptTag, createStylesLinkTag } from "@allurereport/core-api";
1
+ import { createBaseUrlScript, createScriptTag, createStylesLinkTag, stringifyForInlineScript, } from "@allurereport/core-api";
2
2
  import { copyReportStaticAssets, getReportStaticAsset, readReportStaticAssets, } from "@allurereport/plugin-api/static-assets";
3
3
  import Handlebars from "handlebars";
4
4
  import { byLabels, collapseTree, createTree, createWidget } from "./tree.js";
@@ -38,6 +38,11 @@ const template = `<!DOCTYPE html>
38
38
  }
39
39
  </script>
40
40
  ${createBaseUrlScript()}
41
+ {{#if reportOptions}}
42
+ <script>
43
+ window.allureReportOptions = {{{ reportOptions }}}
44
+ </script>
45
+ {{/if}}
41
46
  {{#if analyticsEnable}}
42
47
  <script async src="https://www.googletagmanager.com/gtag/js?id=G-FVWC4GKEYS"></script>
43
48
  <script>
@@ -56,11 +61,15 @@ const template = `<!DOCTYPE html>
56
61
  </html>
57
62
  `;
58
63
  const compiledTemplate = Handlebars.compile(template);
59
- const createEmbeddedReportDataScript = (reportFiles) => {
60
- const reportFilesDeclaration = reportFiles
61
- .map(({ name, value }) => `d(${JSON.stringify(name)},${JSON.stringify(value)})`)
62
- .join(",");
63
- return `
64
+ const reportDataScriptPlaceholder = "<!-- allure2-report-data -->";
65
+ const injectEmbeddedReportDataScript = (html, reportFiles) => {
66
+ const placeholderIndex = html.indexOf(reportDataScriptPlaceholder);
67
+ if (placeholderIndex === -1) {
68
+ throw new Error("Report data script placeholder is missing from the Allure 2 HTML template");
69
+ }
70
+ const chunks = [
71
+ Buffer.from(html.slice(0, placeholderIndex), "utf8"),
72
+ Buffer.from(`
64
73
  <script>
65
74
  window.reportDataReady = false;
66
75
  window.reportData = window.reportData || {};
@@ -73,18 +82,24 @@ const createEmbeddedReportDataScript = (reportFiles) => {
73
82
  }
74
83
  </script>
75
84
  <script>
76
- Promise.allSettled([${reportFilesDeclaration}]).then(function () {
85
+ Promise.allSettled([`),
86
+ ];
87
+ reportFiles.forEach(({ name, value }, index) => {
88
+ chunks.push(Buffer.from(`${index === 0 ? "" : ","}d(${stringifyForInlineScript(name)},${stringifyForInlineScript(value)})`));
89
+ });
90
+ chunks.push(Buffer.from(`]).then(function () {
77
91
  window.reportDataReady = true;
78
92
  });
79
93
  </script>
80
- `;
94
+ `), Buffer.from(html.slice(placeholderIndex + reportDataScriptPlaceholder.length), "utf8"));
95
+ return Buffer.concat(chunks);
81
96
  };
82
97
  export const readTemplateManifest = async () => {
83
98
  const { manifest } = await readReportStaticAssets(reportStaticArchive);
84
99
  return manifest;
85
100
  };
86
101
  export const generateStaticFiles = async (payload) => {
87
- const { reportName, reportLanguage, singleFile, reportFiles, reportDataFiles, reportUuid, allureVersion } = payload;
102
+ const { reportName, reportLanguage, singleFile, reportFiles, reportDataFiles, reportUuid, allureVersion, overviewHref, } = payload;
88
103
  const staticAssets = await readReportStaticAssets(reportStaticArchive);
89
104
  const { manifest } = staticAssets;
90
105
  const mainJs = manifest["main.js"];
@@ -110,15 +125,16 @@ export const generateStaticFiles = async (payload) => {
110
125
  const html = compiledTemplate({
111
126
  headTags: headTags.join("\n"),
112
127
  bodyTags: bodyTags.join("\n"),
113
- reportFilesScript: singleFile ? createEmbeddedReportDataScript(reportDataFiles) : "",
128
+ reportFilesScript: singleFile ? reportDataScriptPlaceholder : "",
114
129
  analyticsEnable: process.env.ALLURE_NO_ANALYTICS?.toLowerCase() !== "true",
115
130
  allureVersion,
116
131
  reportLanguage,
117
132
  reportUuid,
118
133
  reportName,
119
134
  singleFile,
135
+ reportOptions: overviewHref ? stringifyForInlineScript({ overviewHref }) : undefined,
120
136
  });
121
- await reportFiles.addFile("index.html", Buffer.from(html, "utf8"));
137
+ await reportFiles.addFile("index.html", singleFile ? injectEmbeddedReportDataScript(html, reportDataFiles) : Buffer.from(html, "utf8"));
122
138
  }
123
139
  catch (err) {
124
140
  if (err instanceof RangeError) {
@@ -308,7 +324,7 @@ export const generateAttachmentsData = async (writer, attachmentLinks, contentFu
308
324
  }
309
325
  return result;
310
326
  };
311
- export const generateGlobalsData = async (writer, globalErrors, globalAttachments, attachmentMap, attachmentTimestamps = {}, errorTimestamps = []) => {
327
+ export const generateGlobalsData = async (writer, globalErrors, globalAttachments, attachmentMap, attachmentTimestamps = {}, errorTimestamps = [], exitCode) => {
312
328
  const data = {
313
329
  errors: globalErrors.map(({ message, trace, actual, expected }, index) => ({
314
330
  message,
@@ -334,5 +350,8 @@ export const generateGlobalsData = async (writer, globalErrors, globalAttachment
334
350
  ];
335
351
  }),
336
352
  };
353
+ if (exitCode) {
354
+ data.exitCode = exitCode;
355
+ }
337
356
  await writer.writeWidget("globals.json", data);
338
357
  };
package/dist/model.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { Statistic } from "@allurereport/core-api";
2
+ import type { ExitCode } from "@allurereport/plugin-api";
2
3
  export type Allure2Status = "failed" | "broken" | "passed" | "skipped" | "unknown";
3
4
  export interface Allure2Time {
4
5
  start?: number;
@@ -38,6 +39,7 @@ export interface Allure2GlobalAttachment extends Allure2Attachment {
38
39
  timestamp?: number;
39
40
  }
40
41
  export interface Allure2GlobalsData {
42
+ exitCode?: ExitCode;
41
43
  errors: Allure2GlobalError[];
42
44
  attachments: Allure2GlobalAttachment[];
43
45
  }
package/dist/plugin.js CHANGED
@@ -16,13 +16,14 @@ export class Allure2Plugin {
16
16
  const writer = singleFile ? new InMemoryReportDataWriter() : new ReportFileDataWriter(context.reportFiles);
17
17
  const attachmentLinks = await store.allAttachments();
18
18
  const attachmentMap = await generateAttachmentsData(writer, attachmentLinks, (id) => store.attachmentContentById(id));
19
- const [globalErrors, globalAttachments] = await Promise.all([
19
+ const [globalErrors, globalAttachments, globalExitCode] = await Promise.all([
20
20
  store.allGlobalErrors(),
21
21
  store.allGlobalAttachments(),
22
+ store.globalExitCode(),
22
23
  ]);
23
24
  const globalAttachmentTimestamps = (await store.metadataByKey("allure2_global_attachment_timestamps")) ?? {};
24
25
  const globalErrorTimestamps = (await store.metadataByKey("allure2_global_error_timestamps")) ?? [];
25
- await generateGlobalsData(writer, globalErrors, globalAttachments, attachmentMap, globalAttachmentTimestamps, globalErrorTimestamps);
26
+ await generateGlobalsData(writer, globalErrors, globalAttachments, attachmentMap, globalAttachmentTimestamps, globalErrorTimestamps, globalExitCode);
26
27
  const categories = (await store.metadataByKey("allure2_categories")) ?? [];
27
28
  const legacyHistory = (await store.metadataByKey("allure2_history")) ?? {};
28
29
  const environmentItems = (await store.metadataByKey("allure_environment")) ?? [];
@@ -80,6 +81,7 @@ export class Allure2Plugin {
80
81
  reportFiles: context.reportFiles,
81
82
  reportDataFiles,
82
83
  reportUuid: context.reportUuid,
84
+ overviewHref: context.overviewHref,
83
85
  });
84
86
  });
85
87
  this.update = async (context, store) => {
Binary file
package/dist/tree.js CHANGED
@@ -1,5 +1,5 @@
1
- import { createHash } from "node:crypto";
2
1
  import { byStatistic, compareBy } from "@allurereport/core-api";
2
+ import { md5 } from "@allurereport/plugin-api";
3
3
  import { calculateStatisticByLeafs } from "./utils.js";
4
4
  const rootNodeUid = "__ROOT__";
5
5
  const createLeaf = (endNode, test) => {
@@ -72,7 +72,6 @@ const groupByLabels = (test, labelNames) => {
72
72
  const groupUid = (parentUid, groupName) => {
73
73
  return md5(parentUid ? `${parentUid}.${groupName}` : groupName);
74
74
  };
75
- const md5 = (data) => createHash("md5").update(data).digest("hex");
76
75
  export const collapseTree = (treeGroup, separator = ".") => {
77
76
  const newChildren = treeGroup.children.map((c) => {
78
77
  if (!("children" in c)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allurereport/plugin-allure2",
3
- "version": "3.20.0",
3
+ "version": "3.21.0",
4
4
  "description": "The Allure 2-compatible HTML report",
5
5
  "keywords": [
6
6
  "allure",
@@ -26,17 +26,20 @@
26
26
  "build": "run clean && tsc --project ./tsconfig.json && node ../../scripts/pack-report-static.mjs ../web-allure2/dist/multi ./dist/static/report.tar",
27
27
  "clean": "rimraf ./dist",
28
28
  "test": "rimraf ./out && vitest run",
29
+ "test:unit": "yarn test",
29
30
  "lint": "oxlint --import-plugin src test features stories",
30
31
  "lint:fix": "oxlint --import-plugin --fix src test features stories"
31
32
  },
32
33
  "dependencies": {
33
- "@allurereport/core-api": "3.20.0",
34
- "@allurereport/plugin-api": "3.20.0",
35
- "handlebars": "^4.7.9"
34
+ "@allurereport/core-api": "3.21.0",
35
+ "@allurereport/plugin-api": "3.21.0",
36
+ "handlebars": "4.7.10"
36
37
  },
37
38
  "devDependencies": {
38
- "@allurereport/web-allure2": "3.20.0",
39
+ "@allurereport/test-config": "3.21.0",
40
+ "@allurereport/web-allure2": "3.21.0",
39
41
  "@types/node": "^20",
42
+ "@vitest/coverage-istanbul": "^4.1.0",
40
43
  "@vitest/runner": "^2",
41
44
  "allure-js-commons": "^3",
42
45
  "allure-vitest": "^3",