monocart-coverage-reports 2.9.3 → 2.10.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.
@@ -69,16 +69,77 @@ const addNextIgnore = (list, content, item, locator) => {
69
69
  };
70
70
 
71
71
  // both v8 or c8
72
- const hasIgnoreKey = (content) => {
73
- const v8Key = 'v8 ignore';
74
- if (content.startsWith(v8Key)) {
75
- return v8Key.length;
72
+ const getStartEndNextInfo = (content) => {
73
+ content = content.trim();
74
+
75
+ const start = 'start';
76
+ const stop = 'stop';
77
+ const next = 'next';
78
+ if (content.startsWith(start)) {
79
+ return {
80
+ type: 'range',
81
+ value: stop
82
+ };
76
83
  }
77
- const c8Key = 'c8 ignore';
78
- if (content.startsWith(c8Key)) {
79
- return c8Key.length;
84
+ if (content.startsWith(stop)) {
85
+ return {
86
+ type: 'range',
87
+ value: stop
88
+ };
89
+ }
90
+ if (content.startsWith(next)) {
91
+ return {
92
+ type: 'next',
93
+ value: content.slice(next.length)
94
+ };
95
+ }
96
+ };
97
+
98
+ const getDisableEnableNextInfo = (content) => {
99
+ content = content.trim();
100
+
101
+ const start = 'disable';
102
+ const stop = 'enable';
103
+ const next = 'ignore next';
104
+ if (content.startsWith(start)) {
105
+ return {
106
+ type: 'range',
107
+ value: stop
108
+ };
109
+ }
110
+ if (content.startsWith(stop)) {
111
+ return {
112
+ type: 'range',
113
+ value: stop
114
+ };
115
+ }
116
+ if (content.startsWith(next)) {
117
+ return {
118
+ type: 'next',
119
+ value: content.slice(next.length)
120
+ };
80
121
  }
81
- // istanbul ignore has different rules, can not support it
122
+ };
123
+
124
+
125
+ const getIgnoreInfo = (content) => {
126
+ content = content.trim();
127
+
128
+ const v8_ignore = 'v8 ignore';
129
+ if (content.startsWith(v8_ignore)) {
130
+ return getStartEndNextInfo(content.slice(v8_ignore.length));
131
+ }
132
+
133
+ const c8_ignore = 'c8 ignore';
134
+ if (content.startsWith(c8_ignore)) {
135
+ return getStartEndNextInfo(content.slice(c8_ignore.length));
136
+ }
137
+
138
+ const node_coverage = 'node:coverage';
139
+ if (content.startsWith(node_coverage)) {
140
+ return getDisableEnableNextInfo(content.slice(node_coverage.length));
141
+ }
142
+
82
143
  };
83
144
 
84
145
  const getIgnoredRanges = (locator, options) => {
@@ -101,42 +162,43 @@ const getIgnoredRanges = (locator, options) => {
101
162
  const {
102
163
  block, start, end, text
103
164
  } = item;
104
- let content = block ? text.slice(2, -2) : text.slice(2);
105
- content = content.trim();
106
165
 
107
- const ignoreKey = hasIgnoreKey(content);
108
- if (!ignoreKey) {
166
+ const content = block ? text.slice(2, -2) : text.slice(2);
167
+ const ignoreInfo = getIgnoreInfo(content);
168
+ if (!ignoreInfo) {
109
169
  return;
110
170
  }
111
171
 
112
- content = content.slice(ignoreKey).trim();
172
+ const { type, value } = ignoreInfo;
113
173
 
114
174
  if (ignoreStart) {
115
175
  // v-8 ignore stop
116
- if (content === 'stop') {
117
- ignoreStart.end = extendEnd(end, source, maxLength);
176
+ if (type === 'range' && value === ignoreStart.value) {
177
+ ignoreStart.ignoreData.end = extendEnd(end, source, maxLength);
118
178
  ignoreStart = null;
119
179
  }
120
180
  return;
121
181
  }
122
182
 
123
183
  // v-8 ignore start
124
- if (content === 'start') {
184
+ if (type === 'range') {
125
185
  // add first for sort by start
126
- ignoreStart = {
127
- type: 'start-stop',
186
+ const ignoreData = {
187
+ type,
128
188
  start: extendStart(start, source),
129
189
  end: start
130
190
  };
131
- list.push(ignoreStart);
191
+ list.push(ignoreData);
192
+ ignoreStart = {
193
+ ignoreData,
194
+ value
195
+ };
132
196
  return;
133
197
  }
134
198
 
135
- // v-8 ignore next N
136
- const nextKey = 'next';
137
- if (content.startsWith(nextKey)) {
138
- content = content.slice(nextKey.length).trim();
139
- addNextIgnore(list, content, item, locator);
199
+ // next N
200
+ if (type === 'next') {
201
+ addNextIgnore(list, value.trim(), item, locator);
140
202
  }
141
203
 
142
204
  });
@@ -16,8 +16,13 @@ module.exports = class InfoFunction {
16
16
  this.original = original;
17
17
  }
18
18
 
19
- getRange() {
19
+ getName(index) {
20
+ return this.functionName || `(anonymous_${index})`;
21
+ }
22
+
23
+ getRange(index) {
20
24
  const range = {
25
+ name: this.getName(index),
21
26
  start: this.start,
22
27
  end: this.end,
23
28
  count: this.count
@@ -51,10 +56,8 @@ module.exports = class InfoFunction {
51
56
 
52
57
  const line = loc.start.line;
53
58
 
54
- const functionName = this.functionName || `(anonymous_${index})`;
55
-
56
59
  return {
57
- name: functionName,
60
+ name: this.getName(index),
58
61
  decl: decl,
59
62
  loc: loc,
60
63
  line: line