monocart-coverage-reports 2.0.4 → 2.0.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
@@ -4,15 +4,31 @@
4
4
  [![](https://badgen.net/npm/dw/monocart-coverage-reports)](https://www.npmjs.com/package/monocart-coverage-reports)
5
5
  ![](https://img.shields.io/github/license/cenfun/monocart-coverage-reports)
6
6
 
7
- > Code coverage tool to generate [V8](https://v8.dev/blog/javascript-code-coverage) or [Istanbul](https://istanbul.js.org/) coverage reports.
7
+ > Code coverage tool to generate native [V8](https://v8.dev/blog/javascript-code-coverage) reports or [Istanbul](https://istanbul.js.org/) reports.
8
+
9
+ * [Preview Reports](#preview-reports)
10
+ * [Usage](#usage)
11
+ * [Default Options](#default-options)
12
+ * [Multiple Reports](#multiple-reports)
13
+ - [V8 reports](#v8-reports)
14
+ - [Istanbul reports](#istanbul-reports)
15
+ * [Multiprocessing Support](#multiprocessing-support)
16
+ * [Compare Reports](#compare-reports)
17
+ * [Compare Workflows](#compare-workflows)
18
+ * [Collecting Istanbul Coverage Data](#collecting-istanbul-coverage-data)
19
+ * [Collecting V8 Coverage Data](#collecting-v8-coverage-data)
20
+ * [Node.js V8 Coverage Report for Server Side](#nodejs-v8-coverage-report-for-server-side)
21
+ * [Using `entryFilter` and `sourceFilter` to filter the results for V8 report](#using-entryfilter-and-sourcefilter-to-filter-the-results-for-v8-report)
22
+ * [How to convert V8 to Istanbul](#how-to-convert-v8-to-istanbul)
23
+ - [Using `v8-to-istanbul`](#using-v8-to-istanbul)
24
+ - [How Monocart Works](#how-monocart-works)
25
+ * [Chromium Coverage API](#chromium-coverage-api)
26
+ * [Istanbul Introduction](#istanbul-introduction)
27
+ * [Thanks](#thanks)
8
28
 
9
29
  ## Preview Reports
10
- - [V8](https://cenfun.github.io/monocart-coverage-reports/v8)
11
- - [V8 Rollup](https://cenfun.github.io/monocart-coverage-reports/v8-rollup)
12
- - [V8 Esbuild](https://cenfun.github.io/monocart-coverage-reports/v8-esbuild)
13
- - [V8 Node v8 API](https://cenfun.github.io/monocart-coverage-reports/v8-node-api)
14
- - [V8 Node env](https://cenfun.github.io/monocart-coverage-reports/v8-node-env)
15
- - [V8 Node Inspector](https://cenfun.github.io/monocart-coverage-reports/v8-node-ins)
30
+ - [V8](https://cenfun.github.io/monocart-coverage-reports/v8) - Example for browser, build with webpack, and also [Rollup](https://cenfun.github.io/monocart-coverage-reports/v8-rollup) and [Esbuild](https://cenfun.github.io/monocart-coverage-reports/v8-esbuild)
31
+ - [V8 Node](https://cenfun.github.io/monocart-coverage-reports/v8-node-env) - Example for Node.js using 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)
16
32
  - [V8 Minify](https://cenfun.github.io/monocart-coverage-reports/v8-minify)
17
33
  - [V8 to Istanbul](https://cenfun.github.io/monocart-coverage-reports/v8-and-istanbul/istanbul)
18
34
  - [Istanbul](https://cenfun.github.io/monocart-coverage-reports/istanbul/)
@@ -105,7 +121,6 @@ console.log(coverageResults.summary);
105
121
  ## Compare Reports
106
122
  | | Istanbul | V8 | V8 to Istanbul |
107
123
  | :--------------| :------ | :------ | :---------------------- |
108
- | Instrumenting code | Required | No | No |
109
124
  | Coverage data | Istanbul (Object) | V8 (Array) | V8 (Array) |
110
125
  | Output | [Istanbul reports](#istanbul-reports) | [V8 reports](#v8-reports) | [Istanbul reports](#istanbul-reports) |
111
126
  | - Bytes | ❌ | ✅ | ❌ |
@@ -121,70 +136,58 @@ console.log(coverageResults.summary);
121
136
 
122
137
  ## Compare Workflows
123
138
  - Istanbul Workflows
124
- - 1, Only for source code: instrumenting code with [babel-plugin-istanbul](https://github.com/istanbuljs/babel-plugin-istanbul),see [webpack.config-istanbul.js](https://github.com/cenfun/monocart-coverage-reports/blob/main/test/webpack.config-istanbul.js), or using [nyc](https://github.com/istanbuljs/nyc).
125
- - 2, Collecting coverage data from browser `window.__coverage__` or from node `global.__coverage__`, see [example](https://github.com/cenfun/monocart-coverage-reports/blob/main/test/test-istanbul.js).
126
- - 3, Generating coverage report.
139
+ - 1, [Collecting Istanbul coverage data](#collecting-istanbul-coverage-data)
140
+ - 2, Adding coverage data and generating coverage report
127
141
 
128
142
  - V8 Workflows
129
- - 1, For any runtime code: nothing to do. For source code: building code with `development` [mode](https://webpack.js.org/configuration/mode/) and [sourcemap](https://webpack.js.org/configuration/devtool/) support, see [webpack.config-v8.js](https://github.com/cenfun/monocart-coverage-reports/blob/main/test/webpack.config-v8.js).
130
- - 2, Collecting coverage data with [Chromium Coverage API](#chromium-coverage-api), see [example](https://github.com/cenfun/monocart-coverage-reports/blob/main/test/test-v8.js).
131
- - 3, Generating coverage report.
143
+ - 1, [Collecting V8 coverage data](#collecting-v8-coverage-data)
144
+ - 3, Adding coverage data and generating coverage report
132
145
 
133
- ## Chromium Coverage API
134
- - [V8 coverage report](https://v8.dev/blog/javascript-code-coverage) - Native support for JavaScript code coverage to V8. (Chromium only)
135
- - [Puppeteer Coverage Class](https://pptr.dev/api/puppeteer.coverage)
136
- - [Playwright Coverage Class](https://playwright.dev/docs/api/class-coverage)
137
- - [DevTools Protocol for Coverage](https://chromedevtools.github.io/devtools-protocol/tot/Profiler/#method-startPreciseCoverage)
146
+ ## Collecting Istanbul Coverage Data
147
+ - Instrumenting source code
148
+ > Before collecting Istanbul coverage data, It requires your source code is instrumented with Istanbul
149
+ - Webpack: [babel-plugin-istanbul](https://github.com/istanbuljs/babel-plugin-istanbul), example: [webpack.config-istanbul.js](https://github.com/cenfun/monocart-coverage-reports/blob/main/test/webpack.config-istanbul.js)
150
+ - Rollup: [rollup-plugin-istanbul](https://github.com/artberri/rollup-plugin-istanbul)
151
+ - Vite: [vite-plugin-istanbul](https://github.com/ifaxity/vite-plugin-istanbul)
152
+ - Browser
153
+ > Collecting coverage data from `window.__coverage__`, example: [test-istanbul.js](https://github.com/cenfun/monocart-coverage-reports/blob/main/test/test-istanbul.js)
154
+ - Node.js
155
+ > Collecting coverage data from `global.__coverage__`
156
+
157
+ ## Collecting V8 Coverage Data
158
+ - For source code: enable `sourcemap` and do not compress/minify:
159
+ - Webpack: with `source-map` [devtool](https://webpack.js.org/configuration/devtool/) and `development` [mode](https://webpack.js.org/configuration/mode/), example [webpack.config-v8.js](https://github.com/cenfun/monocart-coverage-reports/blob/main/test/webpack.config-v8.js)
160
+ - Rollup: [options](https://rollupjs.org/configuration-options/) `sourcemap: true`
161
+ - Browser (Chromium Only)
162
+ > Collecting coverage data with [Chromium Coverage API](#chromium-coverage-api), see [example](https://github.com/cenfun/monocart-coverage-reports/blob/main/test/test-v8.js)
163
+ - Node.js
164
+ > see [Node.js V8 Coverage Report for Server Side](#nodejs-v8-coverage-report-for-server-side)
138
165
 
139
166
 
140
167
  ## Node.js V8 Coverage Report for Server Side
141
- There are two ways to collect native V8 coverage data and generate coverage report:
142
168
  - Using Node.js env [NODE_V8_COVERAGE](https://nodejs.org/docs/latest/api/cli.html#node_v8_coveragedir)=`dir`
143
- - 1, Before running your Node.js application, set env `NODE_V8_COVERAGE`=`dir`. After the application runs and exits, the coverage data will be saved to the `dir` directory in JSON file format.
144
- - 2, Read the json file(s) from the `dir` and generate coverage report. see example:
169
+ - Before running your Node.js application, set env `NODE_V8_COVERAGE`=`dir`. After the application runs and exits, the coverage data will be saved to the `dir` directory in JSON file format
170
+ - Read the json file(s) from the `dir` and generate coverage report
171
+ - example:
145
172
  > cross-env NODE_V8_COVERAGE=`.temp/v8-coverage` node [./test/test-node-env.js](./test/test-node-env.js) && node [./test/generate-node-report.js](./test/generate-node-report.js)
146
-
147
- - Using [Inspector](https://nodejs.org/docs/latest/api/inspector.html) API
148
- - 1, Connecting to the V8 inspector and enable V8 coverage.
149
- ```js
150
- const inspector = require('inspector');
151
- const startV8Coverage = async () => {
152
- const session = new inspector.Session();
153
- session.connect();
154
- await session.post('Profiler.enable');
155
- await session.post('Profiler.startPreciseCoverage', {
156
- callCount: true,
157
- detailed: true
158
- });
159
- return session;
160
- };
161
- ```
162
- - 2, Taking coverage data and adding to the report after your application runs.
163
- ```js
164
- const takeV8Coverage = (session) => {
165
- return new Promise((resolve) => {
166
- session.post('Profiler.takePreciseCoverage', (error, coverage) => {
167
- if (error) {
168
- console.log(error);
169
- resolve();
170
- return;
171
- }
172
- resolve(coverage.result);
173
- });
174
- });
175
- };
176
- const coverageList = await takeV8Coverage(session);
177
- // filter node internal files
178
- coverageList = coverageList.filter((entry) => entry.url && !entry.url.startsWith('node:'));
179
- await new CoverageReport(coverageOptions).add(coverageList);
180
- ```
181
- - 3, Generating coverage report. see example: [./test/test-node-ins.js](./test/test-node-ins.js)
182
- ```js
183
- await new CoverageReport(coverageOptions).generate();
184
- ```
173
+
174
+ - Using [V8](https://nodejs.org/docs/latest/api/v8.html#v8takecoverage) API
175
+ - Writing the coverage started by NODE_V8_COVERAGE to disk on demand with `v8.takeCoverage()` and stopping with `v8.stopCoverage()`.
176
+ - example:
177
+ > cross-env NODE_V8_COVERAGE=`.temp/v8-coverage` node [./test/test-node-api.js](./test/test-node-api.js)
178
+
179
+ - Using [Inspector](https://nodejs.org/docs/latest/api/inspector.html) API (or module [collect-v8-coverage](https://github.com/SimenB/collect-v8-coverage))
180
+ - Connecting to the V8 inspector and enable V8 coverage.
181
+ - Taking coverage data and adding to the report after your application runs.
182
+ - example: [./test/test-node-ins.js](./test/test-node-ins.js)
183
+
184
+ - Using [CDP](https://chromedevtools.github.io/devtools-protocol/) API
185
+ - Enabling [Node Debugging](https://nodejs.org/en/guides/debugging-getting-started/)
186
+ - Collecting coverage data with CDP API.
187
+ - example: [./test/test-node-cdp.js](./test/test-node-cdp.js)
185
188
 
186
189
  ## Using `entryFilter` and `sourceFilter` to filter the results for V8 report
187
- When you add coverage data with [Chromium Coverage API](#chromium-coverage-api), it actually contains the data of all entry files, for example:
190
+ When V8 coverage data collected, it actually contains the data of all entry files, for example:
188
191
  ```
189
192
  1, dist/main.js
190
193
  2, dist/vendor.js
@@ -213,12 +216,63 @@ const coverageOptions = {
213
216
  };
214
217
  ```
215
218
 
216
- ## Istanbul Coverage
219
+ ## How to convert V8 to Istanbul
220
+ ### Using [v8-to-istanbul](https://github.com/istanbuljs/v8-to-istanbul)
221
+ It is a popular library which is used to convert V8 coverage format to istanbul's coverage format. Most test frameworks are using it, such as [Jest](https://github.com/jestjs/jest/), [Vitest](https://github.com/vitest-dev/vitest), but it has two major problems:
222
+ - 1, The source mapping does not work well if the position is between the two consecutive mappings. for example:
223
+ ```js
224
+ const a = tf ? 'true' : 'false';
225
+ ^ ^ ^
226
+ m1 p m2
227
+ ```
228
+ > `m1` and `m2` are two consecutive mappings, `p` is the position we looking for. However, we can only get the position of the `m1` if we don't fix it to `p`. Especially the generated code is different from the original code, such as minified, compressed or converted, then it becomes very difficult to find the middle position between two mappings.
229
+
230
+ - 2, The coverage of functions and branches is incorrect. V8 only provided coverage at functions and it's blocks. But if a function is uncovered (count = 0), there is no information for it's blocks and sub-level functions.
231
+ And also there are some problems about counting the functions and branches:
232
+ ```js
233
+ functions.forEach(block => {
234
+ block.ranges.forEach((range, i) => {
235
+ if (block.isBlockCoverage) {
236
+ // v8-to-istanbul: count range as branch here.
237
+ // Problem: not every block is branch, and the first block is actually function.
238
+ if (block.functionName && i === 0) {
239
+ // v8-to-istanbul: count range as function here.
240
+ // Problem: there is no function name if the function is anonymous or expression.
241
+ }
242
+ } else if (block.functionName) {
243
+ // v8-to-istanbul: count range as function here.
244
+ // Problem: same as above function.
245
+ }
246
+ }
247
+ });
248
+ // Problem: When the function or parent-level function is uncovered, then its sub-level functions will never be counted.
249
+ ```
250
+ see source code [v8-to-istanbul.js](https://github.com/istanbuljs/v8-to-istanbul/blob/master/lib/v8-to-istanbul.js)
251
+
252
+ ### How Monocart Works
253
+ We have removed `v8-to-istanbul` because of the two major problems and implemented new converter:
254
+ - 1, Trying to fix the middle position if not found the exact mapping.
255
+ - 2, Finding all functions and branches by parsing the source code [AST](https://github.com/acornjs/acorn), however the V8 cannot provide effective branch coverage information, so the branches is still not perfect.
256
+
257
+ | AST | V8 |
258
+ | :--------------| :------ |
259
+ | AssignmentPattern | 🛇 Not Support |
260
+ | ConditionalExpression | ✔ Not Perfect |
261
+ | IfStatement | ✔ Not Perfect |
262
+ | LogicalExpression | ✔ Not Perfect |
263
+ | SwitchStatement | ✔ Not Perfect |
264
+
265
+ ## Chromium Coverage API
266
+ - [V8 coverage report](https://v8.dev/blog/javascript-code-coverage) - Native support for JavaScript code coverage to V8. (Chromium only)
267
+ - [Puppeteer Coverage Class](https://pptr.dev/api/puppeteer.coverage)
268
+ - [Playwright Coverage Class](https://playwright.dev/docs/api/class-coverage)
269
+ - [DevTools Protocol for Coverage](https://chromedevtools.github.io/devtools-protocol/tot/Profiler/#method-startPreciseCoverage)
270
+
271
+ ## Istanbul Introduction
217
272
  - [Istanbul coverage report](https://istanbul.js.org/) - Instrumenting source codes and generating coverage reports
218
273
  - [babel-plugin-istanbul](https://github.com/istanbuljs/babel-plugin-istanbul)
219
274
  - [istanbul-reports](https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-reports/lib)
220
275
  - [Code Coverage Introduction](https://docs.cypress.io/guides/tooling/code-coverage)
221
276
 
222
-
223
277
  ## Thanks
224
278
  - Special thanks to [@edumserrano](https://github.com/edumserrano)
@@ -162,6 +162,7 @@ const getJsAstInfo = (item, coverageList) => {
162
162
  allowReturnOutsideFunction: true,
163
163
  allowImportExportEverywhere: true,
164
164
  allowSuperOutsideMethod: true,
165
+ allowAwaitOutsideFunction: true,
165
166
  // first line: #!/usr/bin/env node
166
167
  allowHashBang: true
167
168
  };
@@ -79,56 +79,27 @@ const resolveSourceMap = (data) => {
79
79
  }
80
80
  };
81
81
 
82
- const collectInlineSourceMaps = async (v8list) => {
83
- let count = 0;
84
- const concurrency = new Concurrency();
85
- for (const item of v8list) {
86
-
87
- const { type, source } = item;
88
-
89
- // only for js
90
- if (type === 'js') {
91
- const converter = convertSourceMap.fromSource(source);
92
- if (converter) {
93
- item.sourceMap = resolveSourceMap(converter.sourcemap);
94
- count += 1;
95
- // source map comments is inline source map, remove it because it is big
96
- item.source = convertSourceMap.removeComments(source);
97
-
98
- continue;
99
- }
100
- const sourceMapUrl = getSourceMapUrl(source, item.url);
101
- if (sourceMapUrl) {
102
- // console.log('========================', sourceMapUrl);
103
- item.sourceMapUrl = sourceMapUrl;
104
- concurrency.addItem(item);
105
- }
106
- }
107
- }
108
- await concurrency.start(async (item) => {
109
- const data = await loadSourceMap(item.sourceMapUrl);
110
- if (data) {
111
- item.sourceMap = resolveSourceMap(data);
112
- count += 1;
113
- // source map comments is a link, no need remove
114
- }
115
- });
116
-
117
- return count;
82
+ const saveSourceFile = async (filePath, data) => {
83
+ await Util.writeFile(filePath, JSON.stringify(data));
118
84
  };
119
85
 
120
- const collectFileSourceMaps = async (v8list, options) => {
86
+ const collectSourceMaps = async (v8list, options) => {
87
+
121
88
  let count = 0;
122
89
  const concurrency = new Concurrency();
123
90
  for (const item of v8list) {
124
91
 
125
92
  const {
126
- type, url, source, id
93
+ type, url, id, source, sourceMap
127
94
  } = item;
128
95
 
129
- // remove source just keep functions to reduce artifacts size
96
+ // source and sourceMap will be saved as separated file (could be cached)
97
+ // just keep functions coverage ( could be multiple times, will be merged )
98
+ // so remove source and sourceMap
130
99
  delete item.source;
100
+ delete item.sourceMap;
131
101
 
102
+ // source and sourceMap already saved
132
103
  const sourcePath = Util.resolveCacheSourcePath(options.cacheDir, id);
133
104
  if (fs.existsSync(sourcePath)) {
134
105
  continue;
@@ -137,18 +108,23 @@ const collectFileSourceMaps = async (v8list, options) => {
137
108
  const sourceData = {
138
109
  url,
139
110
  id,
140
- source: convertSourceMap.removeComments(source)
111
+ // source,
112
+ source: convertSourceMap.removeComments(source),
113
+ // could be existed
114
+ sourceMap
141
115
  };
142
116
 
143
- // only for js
144
- if (type === 'js') {
145
- const converter = convertSourceMap.fromSource(source);
146
- if (converter) {
147
- sourceData.sourceMap = resolveSourceMap(converter.sourcemap);
117
+ // check sourceMap only for js
118
+ if (type === 'js' && !sourceData.sourceMap) {
119
+ // from inline sync
120
+ const smc = convertSourceMap.fromSource(source);
121
+ if (smc) {
122
+ sourceData.sourceMap = resolveSourceMap(smc.sourcemap);
148
123
  count += 1;
149
124
  await saveSourceFile(sourcePath, sourceData);
150
125
  continue;
151
126
  }
127
+ // from url async
152
128
  const sourceMapUrl = getSourceMapUrl(source, item.url);
153
129
  if (sourceMapUrl) {
154
130
  concurrency.addItem({
@@ -160,10 +136,12 @@ const collectFileSourceMaps = async (v8list, options) => {
160
136
  }
161
137
  }
162
138
 
139
+ // no need check sourceMap
163
140
  await saveSourceFile(sourcePath, sourceData);
164
141
 
165
142
  }
166
143
 
144
+ // from url concurrency
167
145
  await concurrency.start(async (item) => {
168
146
  const sourceData = item.sourceData;
169
147
  const data = await loadSourceMap(item.sourceMapUrl);
@@ -175,19 +153,6 @@ const collectFileSourceMaps = async (v8list, options) => {
175
153
  });
176
154
 
177
155
  return count;
178
- };
179
-
180
- const saveSourceFile = async (filePath, data) => {
181
- await Util.writeFile(filePath, JSON.stringify(data));
182
- };
183
-
184
- const collectSourceMaps = (v8list, options, inlineSourceMap) => {
185
-
186
- if (inlineSourceMap) {
187
- return collectInlineSourceMaps(v8list);
188
- }
189
-
190
- return collectFileSourceMaps(v8list, options);
191
156
 
192
157
  };
193
158
 
@@ -475,7 +475,7 @@ const generateCoverageForDist = (item, state) => {
475
475
 
476
476
  // ========================================================================================================
477
477
 
478
- const decodeSourceMappings = async (item, state, originalDecodedMap) => {
478
+ const decodeSourceMappings = async (state, originalDecodedMap) => {
479
479
 
480
480
  const generatedLocator = state.locator;
481
481
 
@@ -566,7 +566,7 @@ const getOriginalDecodedMappings = (originalDecodedMap, sourceIndex, locator) =>
566
566
  return decodedMappings;
567
567
  };
568
568
 
569
- const initOriginalList = (item, state, originalDecodedMap, options) => {
569
+ const initOriginalList = (state, originalDecodedMap, options) => {
570
570
 
571
571
  // source filter
572
572
  let sourceFilter = options.sourceFilter;
@@ -580,6 +580,7 @@ const initOriginalList = (item, state, originalDecodedMap, options) => {
580
580
  const originalMap = new Map();
581
581
 
582
582
  const { sources, sourcesContent } = state.sourceMap;
583
+
583
584
  sources.forEach((sourcePath, sourceIndex) => {
584
585
 
585
586
  // filter
@@ -860,12 +861,12 @@ const unpackSourceMap = async (item, state, options) => {
860
861
  const time_start_decode = Date.now();
861
862
  const originalDecodedMap = new Map();
862
863
  // for find-original-range
863
- state.decodedMappings = await decodeSourceMappings(item, state, originalDecodedMap);
864
+ state.decodedMappings = await decodeSourceMappings(state, originalDecodedMap);
864
865
  // only debug level
865
866
  Util.logTime(`decode source mappings: ${sourcePath}`, time_start_decode);
866
867
 
867
868
  // filter original list and init list
868
- const originalMap = initOriginalList(item, state, originalDecodedMap, options);
869
+ const originalMap = initOriginalList(state, originalDecodedMap, options);
869
870
 
870
871
  originalDecodedMap.clear();
871
872
 
package/lib/index.js CHANGED
@@ -63,9 +63,7 @@ class CoverageReport {
63
63
 
64
64
  if (Array.isArray(data)) {
65
65
  results.type = 'v8';
66
- // init v8list and unpack sourcemap
67
- const inlineSourceMap = false;
68
- results.data = await initV8ListAndSourcemap(data, this.options, inlineSourceMap);
66
+ results.data = await initV8ListAndSourcemap(data, this.options);
69
67
  } else {
70
68
  results.type = 'istanbul';
71
69
  results.data = data;
@@ -0,0 +1,9 @@
1
+ const { parentPort } = require('worker_threads');
2
+ const { decode } = require('../packages/monocart-coverage-vendor.js');
3
+
4
+ parentPort.on('message', (message) => {
5
+ const result = decode(message);
6
+ parentPort.postMessage(result);
7
+ });
8
+
9
+ parentPort.postMessage('workerReady');
@@ -1,49 +1,35 @@
1
- const {
2
- Worker, isMainThread, parentPort
3
- } = require('worker_threads');
1
+ const path = require('path');
2
+ const { Worker } = require('worker_threads');
4
3
  const Util = require('./util.js');
5
4
 
6
- if (isMainThread) {
5
+ // do NOT use isMainThread because it could be executed in worker too. (worker in worker)
7
6
 
8
- const decodeMappings = (mappings = '') => {
9
- if (typeof text !== 'string') {
10
- mappings = String(mappings);
11
- }
7
+ const decodeMappings = (mappings = '') => {
8
+ if (typeof text !== 'string') {
9
+ mappings = String(mappings);
10
+ }
12
11
 
13
- return new Promise((resolve) => {
12
+ return new Promise((resolve) => {
14
13
 
15
- const worker = new Worker(__filename);
16
-
17
- worker.on('message', (message) => {
18
- if (message === 'workerReady') {
19
- worker.postMessage(mappings);
20
- return;
21
- }
22
- resolve(message);
23
- worker.terminate();
24
- });
25
-
26
- worker.on('error', (e) => {
27
- Util.logError(e.message);
28
- resolve([]);
29
- worker.terminate();
30
- });
14
+ const workerPath = path.resolve(__dirname, 'decode-mappings-worker.js');
15
+ const worker = new Worker(workerPath);
31
16
 
17
+ worker.on('message', (message) => {
18
+ if (message === 'workerReady') {
19
+ worker.postMessage(mappings);
20
+ return;
21
+ }
22
+ resolve(message);
23
+ worker.terminate();
32
24
  });
33
- };
34
-
35
- module.exports = decodeMappings;
36
-
37
- } else {
38
25
 
39
- const { decode } = require('../packages/monocart-coverage-vendor.js');
26
+ worker.on('error', (e) => {
27
+ Util.logError(e.message);
28
+ resolve([]);
29
+ worker.terminate();
30
+ });
40
31
 
41
- parentPort.on('message', (message) => {
42
- const result = decode(message);
43
- parentPort.postMessage(result);
44
32
  });
33
+ };
45
34
 
46
- parentPort.postMessage('workerReady');
47
-
48
- }
49
-
35
+ module.exports = decodeMappings;
package/lib/v8/v8.js CHANGED
@@ -7,7 +7,7 @@ const { mergeScriptCovs } = require('../packages/monocart-coverage-vendor.js');
7
7
  const collectSourceMaps = require('../converter/collect-source-maps.js');
8
8
  const version = require('../../package.json').version;
9
9
 
10
- const initV8ListAndSourcemap = async (v8list, options, inlineSourceMap) => {
10
+ const initV8ListAndSourcemap = async (v8list, options) => {
11
11
 
12
12
  // filter list first
13
13
  const entryFilter = options.entryFilter;
@@ -47,8 +47,8 @@ const initV8ListAndSourcemap = async (v8list, options, inlineSourceMap) => {
47
47
  data.type = 'js';
48
48
  data.functions = item.functions;
49
49
  data.source = item.source;
50
- // useless here
51
- // data.scriptId = item.scriptId;
50
+ // could be existed
51
+ data.sourceMap = item.sourceMap;
52
52
  } else if (item.ranges) {
53
53
  data.type = 'css';
54
54
  data.ranges = item.ranges;
@@ -72,7 +72,7 @@ const initV8ListAndSourcemap = async (v8list, options, inlineSourceMap) => {
72
72
 
73
73
  // collect sourcemap first
74
74
  const time_start = Date.now();
75
- const count = await collectSourceMaps(v8list, options, inlineSourceMap);
75
+ const count = await collectSourceMaps(v8list, options);
76
76
  if (count) {
77
77
  // debug level time
78
78
  Util.logTime(`loaded ${count} sourcemaps`, time_start);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-coverage-reports",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "Monocart coverage reports",
5
5
  "main": "lib/index.js",
6
6
  "exports": {
@@ -17,13 +17,15 @@
17
17
  "build-docs": "node ./scripts/build-docs.js",
18
18
  "build-test": "node ./scripts/build-test.js",
19
19
  "build": "sf lint && sf b -p && npm run build-test",
20
- "test-node": "npm run test-node-env && npm run test-node-ins && npm run test-node-api",
20
+ "test-node": "npm run test-node-env && npm run test-node-ins && npm run test-node-api && npm run test-node-cdp",
21
21
  "test-node-env": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage node ./test/test-node-env.js && node ./test/generate-node-report.js",
22
22
  "test-node-ins": "node ./test/test-node-ins.js",
23
23
  "test-node-api": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage node ./test/test-node-api.js",
24
+ "test-node-cdp": "node --inspect=9229 ./test/test-node-cdp.js",
24
25
  "test-browser": "node ./test/test.js",
25
26
  "test": "npm run test-browser && npm run test-node && npm run build-docs",
26
27
  "dev": "sf d v8",
28
+ "open": "node ./scripts/open.js",
27
29
  "patch": "npm run build && sf publish patch -r"
28
30
  },
29
31
  "workspaces": [
@@ -46,11 +48,10 @@
46
48
  "istanbul-reports": "~3.1.6",
47
49
  "lz-utils": "~2.0.1",
48
50
  "monocart-code-viewer": "^1.0.13",
49
- "monocart-formatter": "~2.2.0",
51
+ "monocart-formatter": "~2.2.1",
50
52
  "turbogrid": "~3.0.12"
51
53
  },
52
54
  "devDependencies": {
53
- "cross-env": "^7.0.3",
54
55
  "eslint": "^8.56.0",
55
56
  "eslint-config-plus": "^1.0.6",
56
57
  "eslint-plugin-html": "^7.1.0",