monocart-coverage-reports 2.10.2 → 2.10.3
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.
|
@@ -146,7 +146,9 @@ const createBranchGroup = (type, node, parents, branchMap) => {
|
|
|
146
146
|
};
|
|
147
147
|
|
|
148
148
|
const addBranch = (group, node, locationMap) => {
|
|
149
|
-
const {
|
|
149
|
+
const {
|
|
150
|
+
start, end, type
|
|
151
|
+
} = node;
|
|
150
152
|
|
|
151
153
|
const branchKey = `${group.start}_${group.end}`;
|
|
152
154
|
|
|
@@ -159,6 +161,24 @@ const addBranch = (group, node, locationMap) => {
|
|
|
159
161
|
count: 0
|
|
160
162
|
};
|
|
161
163
|
|
|
164
|
+
if (type === 'SwitchCase') {
|
|
165
|
+
|
|
166
|
+
// console.log(node);
|
|
167
|
+
|
|
168
|
+
// check break
|
|
169
|
+
if (node.consequent) {
|
|
170
|
+
const breakItem = node.consequent.find((it) => it.type === 'BreakStatement');
|
|
171
|
+
if (breakItem) {
|
|
172
|
+
branchInfo.hasBreak = true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// check default
|
|
177
|
+
if (!node.test) {
|
|
178
|
+
branchInfo.isDefault = true;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
162
182
|
group.locations.push(branchInfo);
|
|
163
183
|
|
|
164
184
|
// update group end
|
|
@@ -183,12 +203,14 @@ const addNoneBranch = (group) => {
|
|
|
183
203
|
const updateBlockLocations = (locations) => {
|
|
184
204
|
const noBlockList = [];
|
|
185
205
|
let blockCount = 0;
|
|
186
|
-
locations.forEach((item) => {
|
|
206
|
+
locations.forEach((item, i) => {
|
|
187
207
|
if (item.block) {
|
|
188
208
|
item.count = item.block.count;
|
|
189
209
|
blockCount += item.count;
|
|
190
210
|
return;
|
|
191
211
|
}
|
|
212
|
+
// for calculate mo break branches
|
|
213
|
+
item.index = i;
|
|
192
214
|
noBlockList.push(item);
|
|
193
215
|
});
|
|
194
216
|
|
|
@@ -240,13 +262,34 @@ const LogicalExpression = (group, parentCount) => {
|
|
|
240
262
|
};
|
|
241
263
|
|
|
242
264
|
const SwitchStatement = (group, parentCount) => {
|
|
243
|
-
|
|
265
|
+
|
|
266
|
+
const locations = group.locations;
|
|
267
|
+
|
|
268
|
+
const { noBlockList, blockCount } = updateBlockLocations(locations);
|
|
244
269
|
if (!noBlockList.length) {
|
|
245
270
|
return;
|
|
246
271
|
}
|
|
247
|
-
|
|
272
|
+
|
|
273
|
+
// calculate switch/case count
|
|
274
|
+
const countLeft = parentCount - blockCount;
|
|
248
275
|
noBlockList.forEach((item) => {
|
|
249
|
-
|
|
276
|
+
|
|
277
|
+
let hasCount = false;
|
|
278
|
+
|
|
279
|
+
// check no break branches
|
|
280
|
+
for (let i = item.index - 1; i >= 0; i--) {
|
|
281
|
+
const b = locations[i];
|
|
282
|
+
if (b && !b.hasBreak && b.count > 0) {
|
|
283
|
+
item.count += b.count;
|
|
284
|
+
hasCount = true;
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (!hasCount) {
|
|
291
|
+
item.count = countLeft;
|
|
292
|
+
}
|
|
250
293
|
});
|
|
251
294
|
};
|
|
252
295
|
|