monocart-coverage-reports 2.6.4 → 2.7.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.
- package/README.md +70 -3
- package/lib/client/cdp-client.js +146 -0
- package/lib/client/cdp-session.js +63 -0
- package/lib/client/coverage-client.js +280 -0
- package/lib/converter/find-original-range.js +49 -27
- package/lib/generate.js +6 -0
- package/lib/index.d.ts +53 -0
- package/lib/index.js +2 -0
- package/lib/index.mjs +1 -0
- package/lib/packages/monocart-coverage-v8.js +1 -1
- package/lib/packages/monocart-coverage-vendor.js +44 -38
- package/lib/utils/request.js +6 -5
- package/lib/utils/snapshot.js +4 -0
- package/lib/v8/v8.js +2 -1
- package/package.json +83 -81
|
@@ -97,6 +97,7 @@ const getBlockEndPosition = (originalLineText) => {
|
|
|
97
97
|
// generatedPos: 17,
|
|
98
98
|
// originalText: ' }}</slot>'
|
|
99
99
|
|
|
100
|
+
// end marks
|
|
100
101
|
const list = ['>', '}', ')'];
|
|
101
102
|
for (const s of list) {
|
|
102
103
|
const endBlockIndex = originalLineText.lastIndexOf(s);
|
|
@@ -116,7 +117,11 @@ const getBlockEndPosition = (originalLineText) => {
|
|
|
116
117
|
|
|
117
118
|
};
|
|
118
119
|
|
|
119
|
-
const getComparedPosition = (
|
|
120
|
+
const getComparedPosition = (info, direction) => {
|
|
121
|
+
|
|
122
|
+
let gt = info.generatedText;
|
|
123
|
+
const gp = info.generatedPos;
|
|
124
|
+
let ot = info.originalText;
|
|
120
125
|
|
|
121
126
|
// before trim
|
|
122
127
|
const oLen = ot.length;
|
|
@@ -175,45 +180,54 @@ const getComparedPosition = (gt, gp, ot, direction) => {
|
|
|
175
180
|
|
|
176
181
|
// ============================
|
|
177
182
|
// right matched
|
|
183
|
+
// only for original first line text
|
|
178
184
|
|
|
185
|
+
const olt = info.originalLineText;
|
|
179
186
|
const right = gt.slice(gp);
|
|
180
|
-
if (
|
|
187
|
+
if (olt.endsWith(right)) {
|
|
181
188
|
return {
|
|
182
|
-
pos:
|
|
189
|
+
pos: olt.length - right.length
|
|
183
190
|
};
|
|
184
191
|
}
|
|
185
192
|
|
|
186
193
|
};
|
|
187
194
|
|
|
195
|
+
const initOriginalLineText = (info) => {
|
|
196
|
+
const originalText = info.originalText;
|
|
197
|
+
// never cross line, using first line of original text
|
|
198
|
+
// trim end remove \r\n and \n
|
|
199
|
+
const originalLines = originalText.split(/\n/);
|
|
200
|
+
if (originalLines.length === 1) {
|
|
201
|
+
// already single line
|
|
202
|
+
info.originalLineText = originalText.trimEnd();
|
|
203
|
+
info.originalSingle = true;
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
// multiple liens
|
|
207
|
+
info.originalLineText = originalLines[0].trimEnd();
|
|
208
|
+
};
|
|
209
|
+
|
|
188
210
|
const getSimilarPosition = (info, direction) => {
|
|
189
211
|
|
|
190
|
-
|
|
191
|
-
generatedText, generatedPos, originalText
|
|
192
|
-
} = info;
|
|
212
|
+
initOriginalLineText(info);
|
|
193
213
|
|
|
194
|
-
const textPos = getComparedPosition(
|
|
214
|
+
const textPos = getComparedPosition(info, direction);
|
|
195
215
|
if (textPos) {
|
|
196
216
|
return textPos;
|
|
197
217
|
}
|
|
198
218
|
|
|
199
|
-
|
|
200
|
-
// trim end remove \r\n and \n
|
|
201
|
-
const originalLines = originalText.split(/\n/);
|
|
202
|
-
if (originalLines.length === 1) {
|
|
203
|
-
// already single line
|
|
204
|
-
info.originalLineText = originalText;
|
|
219
|
+
if (info.originalSingle) {
|
|
205
220
|
return;
|
|
206
221
|
}
|
|
207
222
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
223
|
+
// multiple lines
|
|
224
|
+
const { generatedPos, originalLineText } = info;
|
|
211
225
|
// generatedPos not in first line
|
|
212
226
|
if (generatedPos > originalLineText.length) {
|
|
213
227
|
return;
|
|
214
228
|
}
|
|
215
229
|
|
|
216
|
-
const linePos = getComparedPosition(
|
|
230
|
+
const linePos = getComparedPosition(info, direction);
|
|
217
231
|
if (linePos) {
|
|
218
232
|
return linePos;
|
|
219
233
|
}
|
|
@@ -236,6 +250,7 @@ const getFixedPosition = (info, direction) => {
|
|
|
236
250
|
return similarPos.pos;
|
|
237
251
|
}
|
|
238
252
|
|
|
253
|
+
|
|
239
254
|
// generatedText: never cross lines
|
|
240
255
|
// originalText: could be multiple lines
|
|
241
256
|
// originalLineText: single line originalText
|
|
@@ -266,7 +281,7 @@ const getOriginalEndOffset = (m, rangeInfo) => {
|
|
|
266
281
|
return m.originalEndOffset;
|
|
267
282
|
};
|
|
268
283
|
|
|
269
|
-
const getOriginalText = (m1, m2, rangeInfo
|
|
284
|
+
const getOriginalText = (m1, m2, rangeInfo) => {
|
|
270
285
|
const originalLocator = rangeInfo.originalState.locator;
|
|
271
286
|
|
|
272
287
|
const o1 = m1.originalOffset;
|
|
@@ -383,15 +398,17 @@ const getFixedOriginalStart = (start, mappings, state, rangeInfo) => {
|
|
|
383
398
|
}
|
|
384
399
|
|
|
385
400
|
const direction = 'start';
|
|
386
|
-
const { originalText, originalOffset } = getOriginalText(m1, m2, rangeInfo
|
|
401
|
+
const { originalText, originalOffset } = getOriginalText(m1, m2, rangeInfo);
|
|
387
402
|
const { generatedText, generatedPos } = getGeneratedText(m1, m2, state, start);
|
|
388
403
|
|
|
389
|
-
const
|
|
404
|
+
const info = {
|
|
390
405
|
generatedText,
|
|
391
406
|
generatedPos,
|
|
392
407
|
originalText,
|
|
393
408
|
originalState
|
|
394
|
-
}
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
const originalPos = getFixedPosition(info, direction);
|
|
395
412
|
|
|
396
413
|
// if (start === 2660) {
|
|
397
414
|
// console.log('=====================================================');
|
|
@@ -437,7 +454,8 @@ const getFixedOriginalEnd = (end, mappings, state, rangeInfo) => {
|
|
|
437
454
|
const gt = state.locator.source[end];
|
|
438
455
|
const oi = m2.originalOffset - 1;
|
|
439
456
|
const ot = originalState.locator.source[oi];
|
|
440
|
-
|
|
457
|
+
// it could be ; but it quite far away
|
|
458
|
+
if (gt === ot && [';', ','].includes(gt)) {
|
|
441
459
|
return {
|
|
442
460
|
originalEnd: oi
|
|
443
461
|
};
|
|
@@ -456,24 +474,28 @@ const getFixedOriginalEnd = (end, mappings, state, rangeInfo) => {
|
|
|
456
474
|
}
|
|
457
475
|
|
|
458
476
|
const direction = 'end';
|
|
459
|
-
const { originalText, originalOffset } = getOriginalText(m1, m2, rangeInfo
|
|
477
|
+
const { originalText, originalOffset } = getOriginalText(m1, m2, rangeInfo);
|
|
460
478
|
const { generatedText, generatedPos } = getGeneratedText(m1, m2, state, end);
|
|
461
479
|
|
|
462
|
-
const
|
|
480
|
+
const info = {
|
|
481
|
+
offset: end,
|
|
463
482
|
generatedText,
|
|
464
483
|
generatedPos,
|
|
465
484
|
originalText,
|
|
466
485
|
originalState
|
|
467
|
-
}
|
|
486
|
+
};
|
|
468
487
|
|
|
469
|
-
|
|
488
|
+
const originalPos = getFixedPosition(info, direction);
|
|
489
|
+
|
|
490
|
+
// if (end === 1304578) {
|
|
470
491
|
// console.log('=====================================================');
|
|
471
492
|
// console.log('fixed end', originalState.sourcePath);
|
|
472
493
|
// console.log({
|
|
473
494
|
// generatedText,
|
|
474
495
|
// generatedPos,
|
|
475
496
|
// originalText,
|
|
476
|
-
// originalPos
|
|
497
|
+
// originalPos,
|
|
498
|
+
// originalLineText: info.originalLineText
|
|
477
499
|
// });
|
|
478
500
|
// }
|
|
479
501
|
|
package/lib/generate.js
CHANGED
|
@@ -244,6 +244,12 @@ const getDetailsRows = (files, metrics, cdOptions) => {
|
|
|
244
244
|
|
|
245
245
|
const flatRows = [];
|
|
246
246
|
files.forEach((file) => {
|
|
247
|
+
|
|
248
|
+
// do NOT add debug file
|
|
249
|
+
if (file.debug) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
247
253
|
const { sourcePath, summary } = file;
|
|
248
254
|
const fileRow = getRowData(sourcePath, summary, metrics);
|
|
249
255
|
fileRow.uncoveredLines = getUncoveredLines(file);
|
package/lib/index.d.ts
CHANGED
|
@@ -378,6 +378,8 @@ declare namespace MCR {
|
|
|
378
378
|
loadConfig: (configFile?: string) => Promise<void>;
|
|
379
379
|
}
|
|
380
380
|
|
|
381
|
+
//=====================================================================================================
|
|
382
|
+
|
|
381
383
|
export interface CoverageSnapshot {
|
|
382
384
|
type: "v8" | "istanbul";
|
|
383
385
|
summary: {
|
|
@@ -414,6 +416,57 @@ declare namespace MCR {
|
|
|
414
416
|
message: string;
|
|
415
417
|
};
|
|
416
418
|
|
|
419
|
+
//=====================================================================================================
|
|
420
|
+
|
|
421
|
+
export class CoverageClient {
|
|
422
|
+
/** start js coverage */
|
|
423
|
+
startJSCoverage: () => Promise<void>;
|
|
424
|
+
/** stop and return js coverage */
|
|
425
|
+
stopJSCoverage: () => Promise<V8CoverageEntry[]>;
|
|
426
|
+
|
|
427
|
+
/** start css coverage */
|
|
428
|
+
startCSSCoverage: () => Promise<void>;
|
|
429
|
+
/** stop and return css coverage */
|
|
430
|
+
stopCSSCoverage: () => Promise<V8CoverageEntry[]>;
|
|
431
|
+
|
|
432
|
+
/** start both js and css coverage */
|
|
433
|
+
startCoverage: () => Promise<void>;
|
|
434
|
+
/** stop and return both js and css coverage */
|
|
435
|
+
stopCoverage: () => Promise<V8CoverageEntry[]>;
|
|
436
|
+
|
|
437
|
+
/** write the coverage started by NODE_V8_COVERAGE to disk on demand, returns v8 coverage dir */
|
|
438
|
+
writeCoverage: () => Promise<string>
|
|
439
|
+
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/** Adapt to the CDPSession of Playwright or Puppeteer */
|
|
443
|
+
export interface CDPSession {
|
|
444
|
+
send: (method: string, params?: any) => Promise<any>;
|
|
445
|
+
on: (type: string, handler: (e: any) => void) => void;
|
|
446
|
+
detach: () => Promise<void>
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
export interface CDPOptions {
|
|
450
|
+
/** Adapt to the CDPSession of Playwright or Puppeteer */
|
|
451
|
+
session?: CDPSession;
|
|
452
|
+
/** websocket debugger url */
|
|
453
|
+
url?: string;
|
|
454
|
+
/** debugger port, defaults to 9222 */
|
|
455
|
+
port?: number;
|
|
456
|
+
/** debugger host, defaults to localhost */
|
|
457
|
+
host?: string;
|
|
458
|
+
/** enable https, defaults to false (http) */
|
|
459
|
+
secure?: boolean;
|
|
460
|
+
/** target filter, defaults to first page */
|
|
461
|
+
target?: (targets) => any;
|
|
462
|
+
/** websocket options */
|
|
463
|
+
ws?: any;
|
|
464
|
+
/** timeout, defaults to 10 * 1000 */
|
|
465
|
+
timeout?: number;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
export function CDPClient(cdpOptions: CDPOptions): Promise<CoverageClient | undefined>;
|
|
469
|
+
|
|
417
470
|
}
|
|
418
471
|
|
|
419
472
|
/** create coverage report */
|
package/lib/index.js
CHANGED
|
@@ -9,6 +9,7 @@ const Util = require('./utils/util.js');
|
|
|
9
9
|
const { initV8ListAndSourcemap, getEntryFilter } = require('./v8/v8.js');
|
|
10
10
|
const { getInputData, generateCoverageReports } = require('./generate.js');
|
|
11
11
|
const { getSnapshot, diffSnapshot } = require('./utils/snapshot.js');
|
|
12
|
+
const CDPClient = require('./client/cdp-client.js');
|
|
12
13
|
|
|
13
14
|
const resolveConfigOptions = async (configPath) => {
|
|
14
15
|
// json format
|
|
@@ -271,5 +272,6 @@ const MCR = function(options) {
|
|
|
271
272
|
MCR.CoverageReport = CoverageReport;
|
|
272
273
|
MCR.getSnapshot = getSnapshot;
|
|
273
274
|
MCR.diffSnapshot = diffSnapshot;
|
|
275
|
+
MCR.CDPClient = CDPClient;
|
|
274
276
|
|
|
275
277
|
module.exports = MCR;
|
package/lib/index.mjs
CHANGED