@allurereport/reader 3.8.2 → 3.9.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.
@@ -34,27 +34,26 @@ const xmlParser = new XMLParser({
34
34
  isArray: arrayTags.has.bind(arrayTags),
35
35
  });
36
36
  const readerId = "allure1";
37
+ const matchesAllure1File = (fileName) => fileName.endsWith("-testsuite.xml");
37
38
  export const allure1 = {
39
+ matches: (data) => matchesAllure1File(data.getOriginalFileName()),
38
40
  read: async (visitor, data) => {
39
- if (data.getOriginalFileName().endsWith("-testsuite.xml")) {
40
- try {
41
- const asBuffer = await data.asBuffer();
42
- if (!asBuffer) {
43
- return false;
44
- }
45
- const content = cleanBadXmlCharacters(asBuffer).toString("utf-8");
46
- const parsed = xmlParser.parse(content);
47
- if (!isStringAnyRecord(parsed)) {
48
- return false;
49
- }
50
- return await parseRootElement(visitor, parsed);
41
+ try {
42
+ const asBuffer = await data.asBuffer();
43
+ if (!asBuffer) {
44
+ return false;
51
45
  }
52
- catch (e) {
53
- console.error("error parsing", data.getOriginalFileName(), e);
46
+ const content = cleanBadXmlCharacters(asBuffer).toString("utf-8");
47
+ const parsed = xmlParser.parse(content);
48
+ if (!isStringAnyRecord(parsed)) {
54
49
  return false;
55
50
  }
51
+ return await parseRootElement(visitor, parsed);
52
+ }
53
+ catch (e) {
54
+ console.error("error parsing", data.getOriginalFileName(), e);
55
+ return false;
56
56
  }
57
- return false;
58
57
  },
59
58
  readerId: () => readerId,
60
59
  };
@@ -17,13 +17,39 @@ const xmlParser = new XMLParser({
17
17
  isArray: (tagName, jPath) => arrayTags.has(jPath.toString()),
18
18
  });
19
19
  const readerId = "allure2";
20
+ const isAllure2AttachmentFileName = (fileName) => {
21
+ const attachmentIdx = fileName.lastIndexOf("-attachment");
22
+ if (attachmentIdx === -1) {
23
+ return false;
24
+ }
25
+ const suffix = fileName.slice(attachmentIdx + "-attachment".length);
26
+ return suffix === "" || suffix.startsWith(".");
27
+ };
28
+ const matchesAllure2File = (fileName) => {
29
+ if (fileName.endsWith("-result.json"))
30
+ return true;
31
+ if (fileName.endsWith("-check.json"))
32
+ return true;
33
+ if (fileName.endsWith("-container.json"))
34
+ return true;
35
+ if (fileName.endsWith("-globals.json"))
36
+ return true;
37
+ if (isAllure2AttachmentFileName(fileName))
38
+ return true;
39
+ if (fileName === "executor.json")
40
+ return true;
41
+ if (fileName === "categories.json")
42
+ return true;
43
+ if (fileName === "environment.properties")
44
+ return true;
45
+ if (fileName === "environment.xml")
46
+ return true;
47
+ return false;
48
+ };
20
49
  export const allure2 = {
50
+ matches: (data) => matchesAllure2File(data.getOriginalFileName()),
21
51
  read: async (visitor, data) => {
22
52
  const originalFileName = data.getOriginalFileName();
23
- if (originalFileName.match(/-attachment(?:\..+)?/)) {
24
- await visitor.visitAttachmentFile(data, { readerId });
25
- return true;
26
- }
27
53
  if (originalFileName.endsWith("-check.json")) {
28
54
  try {
29
55
  const parsed = await data.asJson();
@@ -1,5 +1,6 @@
1
1
  const readerId = "attachments";
2
2
  export const attachments = {
3
+ matches: () => true,
3
4
  read: async (visitor, data) => {
4
5
  await visitor.visitAttachmentFile(data, { readerId });
5
6
  return true;
@@ -5,6 +5,7 @@ import { ensureArray, ensureInt, ensureString, isArray, isNonNullObject, isStrin
5
5
  import { STEP_NAME_PLACEHOLDER, TEST_NAME_PLACEHOLDER } from "./model.js";
6
6
  const NS_IN_MS = 1000000;
7
7
  const readerId = "cucumberjson";
8
+ const matchesCucumberJsonFile = (fileName) => fileName.endsWith(".json");
8
9
  const allureStepStatusPriorityOrder = {
9
10
  failed: 0,
10
11
  broken: 1,
@@ -31,23 +32,25 @@ const allureStepMessages = {
31
32
  failed: "The step failed",
32
33
  };
33
34
  export const cucumberjson = {
35
+ matches: (data) => matchesCucumberJsonFile(data.getOriginalFileName()),
34
36
  read: async (visitor, data) => {
35
37
  const originalFileName = data.getOriginalFileName();
36
- if (originalFileName.endsWith(".json")) {
37
- try {
38
- const parsed = await data.asJson();
39
- if (isArray(parsed)) {
40
- let oneOrMoreFeaturesParsed = false;
41
- for (const feature of parsed) {
42
- oneOrMoreFeaturesParsed || (oneOrMoreFeaturesParsed = await processFeature(visitor, originalFileName, feature));
38
+ try {
39
+ const parsed = await data.asJson();
40
+ if (isArray(parsed)) {
41
+ let oneOrMoreFeaturesParsed = false;
42
+ for (const feature of parsed) {
43
+ oneOrMoreFeaturesParsed || (oneOrMoreFeaturesParsed = await processFeature(visitor, originalFileName, feature));
44
+ if (oneOrMoreFeaturesParsed) {
45
+ break;
43
46
  }
44
- return oneOrMoreFeaturesParsed;
45
47
  }
48
+ return oneOrMoreFeaturesParsed;
46
49
  }
47
- catch (e) {
48
- console.error("error parsing", originalFileName, e);
49
- return false;
50
- }
50
+ }
51
+ catch (e) {
52
+ console.error("error parsing", originalFileName, e);
53
+ return false;
51
54
  }
52
55
  return false;
53
56
  },
@@ -23,26 +23,26 @@ const xmlParser = new XMLParser({
23
23
  isArray: (tagName, jPath) => arrayTags.has(jPath.toString()),
24
24
  });
25
25
  const readerId = "junit";
26
+ const matchesJunitXmlFile = (fileName) => fileName.endsWith(".xml");
26
27
  export const junitXml = {
28
+ matches: (data) => matchesJunitXmlFile(data.getOriginalFileName()),
27
29
  read: async (visitor, data) => {
28
- if (data.getOriginalFileName().endsWith(".xml")) {
29
- try {
30
- const content = await data.asUtf8String();
31
- if (!content) {
32
- return false;
33
- }
34
- const parsed = xmlParser.parse(content);
35
- if (!isStringAnyRecord(parsed)) {
36
- return false;
37
- }
38
- return await parseRootElement(visitor, parsed);
30
+ const originalFileName = data.getOriginalFileName();
31
+ try {
32
+ const content = await data.asUtf8String();
33
+ if (!content) {
34
+ return false;
39
35
  }
40
- catch (e) {
41
- console.error("error parsing", data.getOriginalFileName(), e);
36
+ const parsed = xmlParser.parse(content);
37
+ if (!isStringAnyRecord(parsed)) {
42
38
  return false;
43
39
  }
40
+ return await parseRootElement(visitor, parsed);
41
+ }
42
+ catch (e) {
43
+ console.error("error parsing", originalFileName, e);
44
+ return false;
44
45
  }
45
- return false;
46
46
  },
47
47
  readerId: () => readerId,
48
48
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allurereport/reader",
3
- "version": "3.8.2",
3
+ "version": "3.9.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,9 +26,9 @@
26
26
  "lint:fix": "oxlint --import-plugin --fix src test features stories"
27
27
  },
28
28
  "dependencies": {
29
- "@allurereport/core-api": "3.8.2",
30
- "@allurereport/plugin-api": "3.8.2",
31
- "@allurereport/reader-api": "3.8.2",
29
+ "@allurereport/core-api": "3.9.0",
30
+ "@allurereport/plugin-api": "3.9.0",
31
+ "@allurereport/reader-api": "3.9.0",
32
32
  "fast-xml-parser": "^5.5.7"
33
33
  },
34
34
  "devDependencies": {