monocart-coverage-reports 2.5.4 → 2.5.5

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/README.md CHANGED
@@ -65,8 +65,8 @@ console.log(coverageResults.summary);
65
65
  ## Available Reports
66
66
  > V8 build-in reports (V8 data only):
67
67
  - `v8`
68
- - Browser: Build with webpack [V8](https://cenfun.github.io/monocart-coverage-reports/v8) and [V8 Minify](https://cenfun.github.io/monocart-coverage-reports/v8-minify); Build with [Rollup](https://cenfun.github.io/monocart-coverage-reports/v8-rollup) and [Esbuild](https://cenfun.github.io/monocart-coverage-reports/v8-esbuild); Collect with [puppeteer](https://cenfun.github.io/monocart-coverage-reports/puppeteer/); [anonymous](https://cenfun.github.io/monocart-coverage-reports/anonymous/) and [css](https://cenfun.github.io/monocart-coverage-reports/css/)
69
- - Node.js: Collect with [env](https://cenfun.github.io/monocart-coverage-reports/v8-node-env), and also V8 [API](https://cenfun.github.io/monocart-coverage-reports/v8-node-api), [Inspector](https://cenfun.github.io/monocart-coverage-reports/v8-node-ins) and [CDP](https://cenfun.github.io/monocart-coverage-reports/v8-node-cdp); Web server example: [koa](https://cenfun.github.io/monocart-coverage-reports/v8-node-koa/)
68
+ - Browser: Build with webpack [V8](https://cenfun.github.io/monocart-coverage-reports/v8) and [Minify](https://cenfun.github.io/monocart-coverage-reports/minify); Build with [Rollup](https://cenfun.github.io/monocart-coverage-reports/rollup) and [Esbuild](https://cenfun.github.io/monocart-coverage-reports/esbuild); Collect with [puppeteer](https://cenfun.github.io/monocart-coverage-reports/puppeteer/); [anonymous](https://cenfun.github.io/monocart-coverage-reports/anonymous/) and [css](https://cenfun.github.io/monocart-coverage-reports/css/)
69
+ - Node.js: Collect with [env](https://cenfun.github.io/monocart-coverage-reports/node-env), and also V8 [API](https://cenfun.github.io/monocart-coverage-reports/node-api), [Inspector](https://cenfun.github.io/monocart-coverage-reports/node-ins) and [CDP](https://cenfun.github.io/monocart-coverage-reports/node-cdp); Web server example: [koa](https://cenfun.github.io/monocart-coverage-reports/node-koa/)
70
70
 
71
71
  ![](./assets/v8.gif)
72
72
 
@@ -306,7 +306,7 @@ const addCssRules = (list, coverageList, coveredRanges, empty) => {
306
306
  const getCssAstInfo = (item, coverageList) => {
307
307
 
308
308
  const {
309
- source, sourcePath, ranges, empty
309
+ source, ranges, empty
310
310
  } = item;
311
311
 
312
312
  // sort covered ranges
@@ -320,9 +320,7 @@ const getCssAstInfo = (item, coverageList) => {
320
320
  };
321
321
  });
322
322
 
323
- const time_start_parse = new Date();
324
323
  const ast = parseCss(source);
325
- Util.logTime(`parse css: ${sourcePath}`, time_start_parse);
326
324
 
327
325
  addCssRules(ast.nodes, coverageList, coveredRanges, empty);
328
326
 
@@ -1,4 +1,5 @@
1
1
  const fs = require('fs');
2
+ const path = require('path');
2
3
  const EC = require('eight-colors');
3
4
  const { fileURLToPath, pathToFileURL } = require('url');
4
5
  const Concurrency = require('../platform/concurrency.js');
@@ -66,16 +67,49 @@ const getSourceMapUrl = (content, url) => {
66
67
  }
67
68
  };
68
69
 
69
- const resolveSourceMap = (data) => {
70
- if (data) {
71
- const {
72
- sources, sourcesContent, mappings
73
- } = data;
74
- if (!sources || !sourcesContent || !mappings) {
75
- return;
70
+ const resolveSourcesContent = async (sources, url) => {
71
+ const list = [];
72
+ for (const file of sources) {
73
+ const sourceUrl = Util.resolveUrl(file, url);
74
+ if (sourceUrl) {
75
+ const sourcePath = sourceUrl.toString();
76
+ if (sourcePath.startsWith('file:')) {
77
+ const content = await Util.readFile(path.resolve(fileURLToPath(sourcePath)));
78
+ list.push(content);
79
+ continue;
80
+ }
76
81
  }
82
+ Util.logDebug(EC.red(`failed to load source content ${file}`));
83
+ }
84
+ if (list.length === sources.length) {
85
+ return list;
86
+ }
87
+ };
88
+
89
+ const resolveSourceMap = async (data, url) => {
90
+ if (!data) {
91
+ return;
92
+ }
93
+ const {
94
+ sources, sourcesContent, mappings
95
+ } = data;
96
+
97
+ if (!sources || !mappings) {
98
+ return;
99
+ }
100
+
101
+ // exists sources content
102
+ if (sourcesContent && sourcesContent.length === sources.length) {
77
103
  return data;
78
104
  }
105
+
106
+ // load sources content by sources
107
+ const contents = await resolveSourcesContent(sources, url);
108
+ if (contents) {
109
+ data.sourcesContent = contents;
110
+ return data;
111
+ }
112
+
79
113
  };
80
114
 
81
115
  const saveSourceFile = async (filePath, data) => {
@@ -92,7 +126,7 @@ const saveSourceFile = async (filePath, data) => {
92
126
 
93
127
  const collectSourceMaps = async (v8list, options) => {
94
128
 
95
- let count = 0;
129
+ const smList = [];
96
130
  const concurrency = new Concurrency();
97
131
  for (const item of v8list) {
98
132
 
@@ -130,8 +164,11 @@ const collectSourceMaps = async (v8list, options) => {
130
164
  // from inline sync
131
165
  const smc = convertSourceMap.fromSource(source);
132
166
  if (smc) {
133
- sourceData.sourceMap = resolveSourceMap(smc.sourcemap);
134
- count += 1;
167
+ sourceData.sourceMap = await resolveSourceMap(smc.sourcemap, url);
168
+ smList.push({
169
+ url,
170
+ inline: true
171
+ });
135
172
  await saveSourceFile(sourcePath, sourceData);
136
173
  continue;
137
174
  }
@@ -154,16 +191,20 @@ const collectSourceMaps = async (v8list, options) => {
154
191
 
155
192
  // from url concurrency
156
193
  await concurrency.start(async (item) => {
157
- const sourceData = item.sourceData;
158
- const data = await loadSourceMap(item.sourceMapUrl);
194
+ const { sourceMapUrl, sourceData } = item;
195
+ const { url } = sourceData;
196
+ const data = await loadSourceMap(sourceMapUrl);
159
197
  if (data) {
160
- sourceData.sourceMap = resolveSourceMap(data);
161
- count += 1;
198
+ sourceData.sourceMap = await resolveSourceMap(data, url);
199
+ smList.push({
200
+ url,
201
+ sourceMapUrl
202
+ });
162
203
  }
163
204
  await saveSourceFile(item.sourcePath, sourceData);
164
205
  });
165
206
 
166
- return count;
207
+ return smList;
167
208
 
168
209
  };
169
210
 
@@ -1300,6 +1300,7 @@ const convertV8List = (v8list, options) => {
1300
1300
  }
1301
1301
 
1302
1302
  // ============================
1303
+ const time_start_ast = Date.now();
1303
1304
  // move functions and ranges to coverageList
1304
1305
  let coverageList = [];
1305
1306
  let astInfo;
@@ -1318,6 +1319,7 @@ const convertV8List = (v8list, options) => {
1318
1319
  delete item.ranges;
1319
1320
  }
1320
1321
  }
1322
+ Util.logTime(`- parsed ast: ${sourcePath}`, time_start_ast);
1321
1323
 
1322
1324
  // console.log(sourcePath, astInfo.statements.length);
1323
1325
  // ============================
@@ -1345,14 +1347,19 @@ const convertV8List = (v8list, options) => {
1345
1347
  v8Data: item
1346
1348
  };
1347
1349
 
1350
+ const time_start_unpack = Date.now();
1348
1351
  unpackDistFile(item, state, options);
1352
+ Util.logTime(`- unpacked dist: ${sourcePath}`, time_start_unpack);
1349
1353
 
1350
1354
  stateList.push(state);
1351
1355
 
1352
1356
  }
1353
1357
 
1354
- return generateV8DataList(stateList, options);
1358
+ const time_start_convert = Date.now();
1359
+ const dataList = generateV8DataList(stateList, options);
1360
+ Util.logTime('- generated v8 data list', time_start_convert);
1355
1361
 
1362
+ return dataList;
1356
1363
  };
1357
1364
 
1358
1365
  module.exports = {
package/lib/generate.js CHANGED
@@ -247,7 +247,7 @@ const getCoverageResults = async (dataList, sourceCache, options) => {
247
247
  const {
248
248
  v8DataList, coverageData, fileSources
249
249
  } = results;
250
- Util.logTime(`converted v8 data: ${v8DataList.length}`, time_start);
250
+ Util.logTime(`converted v8 list: ${v8DataList.length}`, time_start);
251
251
 
252
252
  return generateV8ListReports(v8DataList, coverageData, fileSources, options);
253
253
  }