monocart-reporter 2.1.1 → 2.2.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.
@@ -2,7 +2,6 @@ const Util = {
2
2
 
3
3
  // definition
4
4
  tagPattern: /(\s*)@([^@\s]+)(\s*)/g,
5
- lineBreakPattern: /\r\n|[\r\n\u2028\u2029]/gu,
6
5
 
7
6
  attachments: {
8
7
  audit: {
@@ -1,21 +1,10 @@
1
1
  const fs = require('fs');
2
2
  const Util = require('../utils/util.js');
3
- const parseSource = require('../utils/parse-source.js');
3
+ const { Locator } = require('monocart-formatter/node');
4
4
 
5
5
  const cacheMap = new Map();
6
6
 
7
- function getEmptyLines(lines) {
8
- const emptyLines = [];
9
- const reg = /\S/;
10
- lines.forEach((text, i) => {
11
- if (!reg.test(text)) {
12
- emptyLines.push(i + 1);
13
- }
14
- });
15
- return emptyLines;
16
- }
17
-
18
- const getFileComments = (sourcePath, options = {}) => {
7
+ const getFileComments = (sourcePath) => {
19
8
 
20
9
  const map = new Map();
21
10
 
@@ -27,33 +16,43 @@ const getFileComments = (sourcePath, options = {}) => {
27
16
 
28
17
  const source = fs.readFileSync(sourcePath).toString('utf-8');
29
18
 
30
- const ast = parseSource({
31
- source,
32
- sourcePath,
33
- options
19
+ const locator = new Locator(source);
20
+
21
+ const { comments, lines } = locator.lineParser;
22
+
23
+ // get empty lines, no value
24
+ lines.forEach((item) => {
25
+ if (item.blank) {
26
+ // 0-base
27
+ map.set(item.line + 1, {});
28
+ }
34
29
  });
35
30
 
36
- if (!ast) {
37
- return map;
38
- }
31
+ comments.forEach((item) => {
32
+ const {
33
+ start, end, text
34
+ } = item;
35
+
36
+ // using last line
37
+ // 1-base
38
+ const eLoc = locator.offsetToLocation(end);
39
+ map.set(eLoc.line, {
40
+ value: text
41
+ });
42
+
43
+ // exists first line
44
+ if (map.has(1)) {
45
+ return;
46
+ }
39
47
 
40
- ast.comments.forEach((item) => {
41
48
  // first line comments for file line 0
42
- const startLine = item.loc.start.line;
43
- if (startLine === 1) {
49
+ const sLoc = locator.offsetToLocation(start);
50
+ if (sLoc.line === 1) {
44
51
  map.set(1, {
45
- value: item.value
52
+ value: text
46
53
  });
47
54
  }
48
- map.set(item.loc.end.line, {
49
- value: item.value
50
- });
51
- });
52
55
 
53
- // get empty lines
54
- const lines = source.split(Util.lineBreakPattern);
55
- getEmptyLines(lines).forEach((line) => {
56
- map.set(line, {});
57
56
  });
58
57
 
59
58
  return map;
@@ -91,7 +90,7 @@ const findComment = (line, map) => {
91
90
  return findCommentAbove(line, map);
92
91
  };
93
92
 
94
- module.exports = (metadata, parserOptions) => {
93
+ module.exports = (metadata) => {
95
94
  const location = metadata.location;
96
95
  if (!location) {
97
96
  return;
@@ -104,7 +103,7 @@ module.exports = (metadata, parserOptions) => {
104
103
 
105
104
  let map = cacheMap.get(location.file);
106
105
  if (!map) {
107
- map = getFileComments(location.file, parserOptions);
106
+ map = getFileComments(location.file);
108
107
  // cache file info
109
108
  cacheMap.set(location.file, map);
110
109
  }
package/lib/visitor.js CHANGED
@@ -104,21 +104,20 @@ class Visitor {
104
104
  // data.type is step, metadata is TestStep, https://playwright.dev/docs/api/class-teststep
105
105
  async customVisitorsHandler(data, metadata) {
106
106
 
107
- const collect = {
108
- comments: (parserOptions) => {
109
- return commentsPlugin(metadata, parserOptions);
110
- }
111
- };
107
+ if (this.options.customFieldsInComments) {
108
+ const customData = commentsPlugin(metadata);
109
+ Object.assign(data, customData);
110
+ }
112
111
 
113
112
  // for all data
114
113
  if (this.customCommonVisitor) {
115
- await this.customCommonVisitor.call(this, data, metadata, collect);
114
+ await this.customCommonVisitor.call(this, data, metadata);
116
115
  }
117
116
 
118
117
  // for single column data (high priority)
119
118
  if (this.customVisitors) {
120
119
  for (const item of this.customVisitors) {
121
- const res = await item.visitor.call(this, data, metadata, collect);
120
+ const res = await item.visitor.call(this, data, metadata);
122
121
  if (typeof res !== 'undefined') {
123
122
  data[item.id] = res;
124
123
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-reporter",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "description": "A playwright test reporter. Shows suites/cases/steps with tree style, markdown annotations, custom columns/formatters/data collection visitors, console logs, style tags, send email.",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -47,14 +47,15 @@
47
47
  "koa": "~2.15.0",
48
48
  "koa-static-resolver": "~1.0.4",
49
49
  "lz-utils": "~2.0.1",
50
- "monocart-coverage-reports": "~2.0.4",
51
- "nodemailer": "~6.9.7",
50
+ "monocart-coverage-reports": "~2.0.9",
51
+ "monocart-formatter": "^2.2.1",
52
+ "nodemailer": "~6.9.8",
52
53
  "open": "~10.0.2",
53
54
  "turbogrid": "^3.0.12"
54
55
  },
55
56
  "devDependencies": {
56
57
  "@playwright/test": "^1.40.1",
57
- "axios": "^1.6.3",
58
+ "axios": "^1.6.5",
58
59
  "dotenv": "^16.3.1",
59
60
  "eslint": "^8.56.0",
60
61
  "eslint-config-plus": "^1.0.6",