monocart-coverage-reports 2.12.1 → 2.12.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.
package/lib/cli.js CHANGED
@@ -93,10 +93,10 @@ const initNodeOptions = async (cliOptions) => {
93
93
  // export source after
94
94
  if (preloadType === '--import') {
95
95
  const importPath = getRegisterPath('register.mjs');
96
- nodeOptions.push(`--import ${importPath}`);
96
+ nodeOptions.unshift(`--import ${importPath}`);
97
97
  } else {
98
98
  const requirePath = getRegisterPath('register.js');
99
- nodeOptions.push(`--require ${requirePath}`);
99
+ nodeOptions.unshift(`--require ${requirePath}`);
100
100
  }
101
101
 
102
102
  // console.log(nodeOptions);
@@ -869,6 +869,12 @@ const decodeSourceMappings = (state, originalDecodedMap) => {
869
869
 
870
870
  const allDecodedMappings = [];
871
871
  decodedList.forEach((segments, generatedLine) => {
872
+
873
+ if (!segments.length) {
874
+ return;
875
+ }
876
+
877
+ // line segments
872
878
  const lastIndex = segments.length - 1;
873
879
  segments.forEach((segment, i) => {
874
880
 
@@ -881,12 +887,17 @@ const decodeSourceMappings = (state, originalDecodedMap) => {
881
887
  // the segment length could be 1, 4 or 5
882
888
 
883
889
  if (typeof sourceIndex === 'undefined') {
890
+ // console.log('============================ sourceIndex undefined');
891
+ // console.log(segment);
884
892
  return;
885
893
  }
886
894
 
895
+ // 1-base
896
+ const generatedSN = generatedLine + 1;
897
+
887
898
  const generatedOffset = generatedLocator.locationToOffset({
888
899
  // 1-base
889
- line: generatedLine + 1,
900
+ line: generatedSN,
890
901
  column: generatedColumn
891
902
  });
892
903
 
@@ -910,15 +921,49 @@ const decodeSourceMappings = (state, originalDecodedMap) => {
910
921
  }
911
922
 
912
923
  allDecodedMappings.push(info);
913
-
914
924
  originalDecodedMap.get(sourceIndex).push(info);
915
925
 
926
+ // calculate line end column
927
+ if (!info.last) {
928
+ return;
929
+ }
930
+
931
+ const lineItem = generatedLocator.getLine(generatedSN);
932
+ if (!lineItem) {
933
+ // console.log('============================== not found line item');
934
+ return;
935
+ }
936
+
937
+ // console.log(generatedSN, generatedColumn, lineItem.length, lineItem.text);
938
+
939
+ if (generatedColumn >= lineItem.length) {
940
+ return;
941
+ }
942
+
943
+ const endColumn = {
944
+ generatedOffset: generatedOffset + (lineItem.length - generatedColumn),
945
+ generatedLine,
946
+ generatedColumn: lineItem.length,
947
+
948
+ end: true,
949
+
950
+ sourceIndex,
951
+ originalLine,
952
+ originalColumn,
953
+ nameIndex
954
+ };
955
+
956
+ // console.log(generatedSN, generatedColumn, info, endColumn);
957
+
958
+ allDecodedMappings.push(endColumn);
959
+ originalDecodedMap.get(sourceIndex).push(endColumn);
960
+
916
961
  });
917
962
 
918
963
 
919
964
  });
920
965
 
921
- // defaults to sort by generated offset, not need sort
966
+ // defaults to sort by generated offset, no need sort
922
967
  // allDecodedMappings.sort((a, b) => {
923
968
  // return a.generatedOffset - b.generatedOffset;
924
969
  // });
@@ -934,6 +979,19 @@ const getOriginalDecodedMappings = (originalDecodedMap, sourceIndex, locator) =>
934
979
  return [];
935
980
  }
936
981
 
982
+ // calculate line end column
983
+ decodedMappings.forEach((item) => {
984
+ if (!item.end) {
985
+ return;
986
+ }
987
+ const originalSN = item.originalLine + 1;
988
+ const lineItem = locator.getLine(originalSN);
989
+ // console.log(originalSN, item.originalColumn, lineItem.length, lineItem.text);
990
+ if (lineItem) {
991
+ item.originalColumn = lineItem.length;
992
+ }
993
+ });
994
+
937
995
  // sort by original line/column
938
996
  decodedMappings.sort((a, b) => {
939
997
  if (a.originalLine === b.originalLine) {
@@ -1078,6 +1136,56 @@ const generateCoverageForDist = (state) => {
1078
1136
 
1079
1137
  };
1080
1138
 
1139
+ const handleUncoveredInCovered = (state, originalStateMap) => {
1140
+ if (!state.fake) {
1141
+ return;
1142
+ }
1143
+
1144
+ // fake statements/branches/functions
1145
+ originalStateMap.forEach((originalState) => {
1146
+ const { bytes } = originalState;
1147
+ const list = [];
1148
+ originalState.bytes = bytes.filter((item) => {
1149
+ if (item.count === 0) {
1150
+ const range = bytes.find((it) => {
1151
+ if (it.count === 0) {
1152
+ return false;
1153
+ }
1154
+ if (it.start > item.end) {
1155
+ return false;
1156
+ }
1157
+ if (it.end < item.start) {
1158
+ return false;
1159
+ }
1160
+ return true;
1161
+ });
1162
+ if (range) {
1163
+ list.push(item);
1164
+ return false;
1165
+ }
1166
+ }
1167
+ return true;
1168
+ });
1169
+
1170
+ if (!list.length) {
1171
+ return;
1172
+ }
1173
+
1174
+ list.forEach((item) => {
1175
+ ['statements', 'branches', 'functions'].forEach((key) => {
1176
+ originalState[key] = originalState[key].filter((it) => {
1177
+ if (it.start === item.start && it.end === item.end) {
1178
+ return false;
1179
+ }
1180
+ return true;
1181
+ });
1182
+ });
1183
+ });
1184
+
1185
+ });
1186
+
1187
+ };
1188
+
1081
1189
  const unpackSourceMap = (state, options) => {
1082
1190
 
1083
1191
  const { sourceMap, sourcePath } = state;
@@ -1128,6 +1236,9 @@ const unpackSourceMap = (state, options) => {
1128
1236
  handleOriginalBytesCoverage(originalState);
1129
1237
  });
1130
1238
 
1239
+ // remove uncovered in covered for fake
1240
+ handleUncoveredInCovered(state, originalStateMap);
1241
+
1131
1242
  // collect coverage for original list
1132
1243
  collectOriginalList(state, originalStateMap);
1133
1244
 
@@ -1173,16 +1284,10 @@ const filterCoverageList = (item) => {
1173
1284
  // the inline sourcemap could be removed
1174
1285
  const maxOffset = source.length;
1175
1286
 
1176
- const rootFunctionInfo = {
1177
- root: true,
1178
- ranges: [{
1179
- startOffset: minOffset,
1180
- endOffset: maxOffset,
1181
- count: 1
1182
- }]
1183
- };
1287
+ const wrapperList = [];
1184
1288
 
1185
1289
  const coverageList = functions.filter((block) => {
1290
+
1186
1291
  const { ranges } = block;
1187
1292
 
1188
1293
  // first one is function coverage info
@@ -1192,31 +1297,31 @@ const filterCoverageList = (item) => {
1192
1297
  return true;
1193
1298
  }
1194
1299
 
1195
- // blocks
1196
- const len = ranges.length;
1197
- if (len > 1) {
1198
- for (let i = 1; i < len; i++) {
1199
- const range = ranges[i];
1200
- if (range.startOffset >= minOffset && range.endOffset <= maxOffset) {
1201
- rootFunctionInfo.ranges.push(range);
1202
- }
1203
- }
1204
- }
1300
+ wrapperList.push(block);
1205
1301
 
1206
1302
  return false;
1207
1303
  });
1208
1304
 
1209
- // first one for root function
1210
- if (rootFunctionInfo.ranges.length > 1) {
1211
- coverageList.unshift(rootFunctionInfo);
1305
+ if (wrapperList.length) {
1306
+ const rootBlock = wrapperList.pop();
1307
+ rootBlock.root = true;
1308
+ coverageList.unshift(rootBlock);
1212
1309
  }
1213
1310
 
1311
+ // if (item.sourcePath.includes('PlaceB.tsx')) {
1312
+ // console.log(coverageList);
1313
+ // }
1314
+
1214
1315
  return coverageList;
1215
1316
  };
1216
1317
 
1217
1318
  const initJsCoverageList = (item) => {
1218
1319
  const coverageList = filterCoverageList(item);
1219
1320
 
1321
+ // if (item.sourcePath.includes('PlaceB.tsx')) {
1322
+ // console.log(coverageList[0]);
1323
+ // }
1324
+
1220
1325
  // function could be covered even it is defined after an uncovered return, see case closures.js
1221
1326
  // fix uncovered range if there are covered ranges in uncovered range
1222
1327
 
@@ -565,9 +565,9 @@ const getFixedOriginalStart = (start, mappings, state, cache, options) => {
565
565
  };
566
566
  }
567
567
 
568
- // skip last mapping
568
+ // skip last and end column mapping
569
569
  let startNextLine = false;
570
- if (m1.last) {
570
+ if (m1.end || m1.last) {
571
571
  const locStart = state.locator.offsetToLocation(start);
572
572
  // 1-base
573
573
  const lineIndex = locStart.line - 1;