monocart-coverage-reports 2.6.5 → 2.7.1

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.
@@ -54,22 +54,37 @@ const getSourceMapUrl = (content, url) => {
54
54
  }
55
55
  };
56
56
 
57
- const resolveSourcesContent = (sources, url) => {
58
- const list = [];
59
- for (const file of sources) {
57
+ const resolveSourcesContent = (data, url) => {
58
+
59
+ const { sources, sourcesContent } = data;
60
+
61
+ let failed = false;
62
+ sources.forEach((file, i) => {
63
+ if (typeof sourcesContent[i] === 'string') {
64
+ return;
65
+ }
66
+
60
67
  const sourceUrl = Util.resolveUrl(file, url);
61
68
  if (sourceUrl) {
62
- const sourcePath = sourceUrl.toString();
69
+ let sourcePath = sourceUrl.toString();
70
+ // could be no `file:`
63
71
  if (sourcePath.startsWith('file:')) {
64
- const content = Util.readFileSync(path.resolve(fileURLToPath(sourcePath)));
65
- list.push(content);
66
- continue;
72
+ sourcePath = fileURLToPath(sourcePath);
73
+ }
74
+ const content = Util.readFileSync(path.resolve(sourcePath));
75
+ if (typeof content === 'string') {
76
+ sourcesContent[i] = content;
77
+ return;
67
78
  }
68
79
  }
80
+
69
81
  Util.logDebug(EC.red(`failed to load source content ${file}`));
70
- }
71
- if (list.length === sources.length) {
72
- return list;
82
+ failed = true;
83
+ });
84
+
85
+
86
+ if (!failed) {
87
+ return data;
73
88
  }
74
89
  };
75
90
 
@@ -85,17 +100,19 @@ const resolveSourceMap = (data, url) => {
85
100
  return;
86
101
  }
87
102
 
88
- // exists sources content
89
- if (sourcesContent && sourcesContent.length === sources.length) {
90
- return data;
103
+ // check sources content
104
+ if (sourcesContent) {
105
+ // all should be string, could be [null]
106
+ const contents = sourcesContent.filter((content) => typeof content === 'string');
107
+ if (contents.length === sources.length) {
108
+ return data;
109
+ }
110
+ } else {
111
+ data.sourcesContent = [];
91
112
  }
92
113
 
93
114
  // load sources content by sources
94
- const contents = resolveSourcesContent(sources, url);
95
- if (contents) {
96
- data.sourcesContent = contents;
97
- return data;
98
- }
115
+ return resolveSourcesContent(data, url);
99
116
 
100
117
  };
101
118
 
@@ -1069,12 +1069,12 @@ const generateCoverageForDist = (state) => {
1069
1069
 
1070
1070
  const unpackSourceMap = (state, options) => {
1071
1071
 
1072
- const { sourceMap } = state;
1072
+ const { sourceMap, sourcePath } = state;
1073
1073
 
1074
1074
  // keep original urls
1075
1075
  const fileUrls = {};
1076
1076
  const sourcePathHandler = getSourcePathHandler(options);
1077
- initSourceMapSourcePath(sourceMap, fileUrls, sourcePathHandler);
1077
+ initSourceMapSourcePath(sourceMap, fileUrls, sourcePath, sourcePathHandler);
1078
1078
  state.fileUrls = fileUrls;
1079
1079
 
1080
1080
  // ===============================================
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
@@ -255,7 +255,7 @@ declare namespace MCR {
255
255
  *
256
256
  * {object} Replace key with value.
257
257
  * */
258
- sourcePath?: ((filePath: string) => string) | {
258
+ sourcePath?: ((filePath: string, info: any) => string) | {
259
259
  [key: string]: string;
260
260
  };
261
261
 
@@ -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
@@ -3,3 +3,4 @@ export default MCR;
3
3
  export const CoverageReport = MCR.CoverageReport;
4
4
  export const getSnapshot = MCR.getSnapshot;
5
5
  export const diffSnapshot = MCR.diffSnapshot;
6
+ export const CDPClient = MCR.CDPClient;