@allurereport/reader 3.17.0 → 3.19.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.
@@ -3,7 +3,7 @@ import { randomUUID } from "node:crypto";
3
3
  import { notNull } from "@allurereport/core-api";
4
4
  import { XMLParser } from "fast-xml-parser";
5
5
  import { parseProperties } from "../properties.js";
6
- import { ensureBoolean, ensureInt, ensureString } from "../utils.js";
6
+ import { ensureArray, ensureBoolean, ensureInt, ensureString } from "../utils.js";
7
7
  import { cleanBadXmlCharacters, isStringAnyRecord, isStringAnyRecordArray } from "../xml-utils.js";
8
8
  import { ParameterMode } from "./model.js";
9
9
  const arrayTags = new Set(["environment.parameter"]);
@@ -24,6 +24,43 @@ const historyMetadataKeys = {
24
24
  "retry-trend.json": "allure2_retry_trend",
25
25
  "categories-trend.json": "allure2_categories_trend",
26
26
  };
27
+ const stripAnsi = (value) => value.replace(/\x1B\[[0-9;?]*[ -/]*[@-~]/g, "");
28
+ const trimDiffValue = (value) => value?.trim().replace(/^["'`](.*)["'`]$/s, "$1");
29
+ const findLabeledAssertionDiff = (text) => {
30
+ const expected = text.match(/^\s*Expected(?:\s+\w+)?:\s*(?<value>.+)\s*$/im)?.groups?.value;
31
+ const actual = text.match(/^\s*(?:Received|Actual)(?:\s+\w+)?:\s*(?<value>.+)\s*$/im)?.groups?.value;
32
+ const normalizedActual = trimDiffValue(actual);
33
+ const normalizedExpected = trimDiffValue(expected);
34
+ return normalizedActual && normalizedExpected
35
+ ? { actual: normalizedActual, expected: normalizedExpected }
36
+ : undefined;
37
+ };
38
+ const findPytestAssertionDiff = (text) => {
39
+ const lines = text.split(/\r?\n/).map((line) => line
40
+ .replace(/^\s*(?:E\s+|>\s*)/, "")
41
+ .replace(/^AssertionError:\s*/, "")
42
+ .trim());
43
+ for (const line of lines) {
44
+ const match = line.match(/^assert\s+(?<actual>.+?)\s+==\s+(?<expected>.+)$/);
45
+ if (!match?.groups) {
46
+ continue;
47
+ }
48
+ const actual = trimDiffValue(match.groups.actual);
49
+ const expected = trimDiffValue(match.groups.expected);
50
+ if (actual && expected) {
51
+ return { actual, expected };
52
+ }
53
+ }
54
+ return undefined;
55
+ };
56
+ const inferAssertionDiff = (message, trace, actual, expected) => {
57
+ if (actual || expected) {
58
+ return { actual, expected };
59
+ }
60
+ const text = stripAnsi([message, trace].filter(Boolean).join("\n"));
61
+ const inferredDiff = findLabeledAssertionDiff(text) ?? findPytestAssertionDiff(text);
62
+ return inferredDiff ?? { actual, expected };
63
+ };
27
64
  const isAllure2AttachmentFileName = (fileName) => {
28
65
  const attachmentIdx = fileName.lastIndexOf("-attachment");
29
66
  if (attachmentIdx === -1) {
@@ -199,6 +236,22 @@ export const allure2 = {
199
236
  const processTestResult = async (visitor, result, originalFileName) => {
200
237
  const links = result?.links?.filter(notNull) ?? [];
201
238
  const topLevelAttachmentCount = result?.attachments?.filter(notNull).length ?? 0;
239
+ const message = ensureString(result?.statusDetails?.message);
240
+ const trace = ensureString(result?.statusDetails?.trace);
241
+ const diff = inferAssertionDiff(message, trace, ensureString(result?.statusDetails?.actual, ""), ensureString(result?.statusDetails?.expected, ""));
242
+ const errors = ensureArray(result?.statusDetails?.errors)
243
+ ?.filter(notNull)
244
+ .map((error) => {
245
+ const errorMessage = ensureString(error.message);
246
+ const errorTrace = ensureString(error.trace);
247
+ const errorDiff = inferAssertionDiff(errorMessage, errorTrace, ensureString(error.actual, ""), ensureString(error.expected, ""));
248
+ return {
249
+ message: errorMessage,
250
+ trace: errorTrace,
251
+ actual: errorDiff.actual,
252
+ expected: errorDiff.expected,
253
+ };
254
+ });
202
255
  const dest = {
203
256
  uuid: ensureString(result.uuid),
204
257
  titlePath: result?.titlePath?.length ? result.titlePath : [],
@@ -211,10 +264,11 @@ const processTestResult = async (visitor, result, originalFileName) => {
211
264
  description: ensureString(result.description),
212
265
  descriptionHtml: ensureString(result.descriptionHtml),
213
266
  status: convertStatus(result.status),
214
- message: ensureString(result?.statusDetails?.message),
215
- trace: ensureString(result?.statusDetails?.trace),
216
- actual: ensureString(result?.statusDetails?.actual, ""),
217
- expected: ensureString(result?.statusDetails?.expected, ""),
267
+ message,
268
+ trace,
269
+ actual: diff.actual,
270
+ expected: diff.expected,
271
+ errors,
218
272
  flaky: ensureBoolean(result?.statusDetails?.flaky),
219
273
  known: ensureBoolean(result?.statusDetails?.known),
220
274
  muted: ensureBoolean(result?.statusDetails?.muted),
@@ -43,6 +43,7 @@ export interface Parameter {
43
43
  export interface StatusDetails {
44
44
  message?: string;
45
45
  trace?: string;
46
+ errors?: StatusDetails[];
46
47
  known?: boolean;
47
48
  muted?: boolean;
48
49
  flaky?: boolean;
@@ -56,6 +56,8 @@ export const utiToMediaType = {
56
56
  "public.tiff": "image/tiff",
57
57
  "com.apple.pict": "image/x-pict",
58
58
  "public.png": "image/png",
59
+ "public.webp": "image/webp",
60
+ "org.webmproject.webp": "image/webp",
59
61
  "public.xbitmap-image": "image/x-quicktime",
60
62
  "com.apple.quicktime-image": "image/x-quicktime",
61
63
  "com.apple.quicktime-movie": "video/quicktime",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allurereport/reader",
3
- "version": "3.17.0",
3
+ "version": "3.19.0",
4
4
  "description": "Collection of utilities which helps to process different kind of test results as Allure Results",
5
5
  "keywords": [
6
6
  "allure",
@@ -26,10 +26,10 @@
26
26
  "lint:fix": "oxlint --import-plugin --fix src test features stories"
27
27
  },
28
28
  "dependencies": {
29
- "@allurereport/core-api": "3.17.0",
30
- "@allurereport/plugin-api": "3.17.0",
31
- "@allurereport/reader-api": "3.17.0",
32
- "fast-xml-parser": "^5.7.0"
29
+ "@allurereport/core-api": "3.19.0",
30
+ "@allurereport/plugin-api": "3.19.0",
31
+ "@allurereport/reader-api": "3.19.0",
32
+ "fast-xml-parser": "^5.11.1"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/archiver": "^6.0.3",