Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

monocart-coverage-reports

Package Overview
Dependencies
Maintainers
0
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

monocart-coverage-reports - npm Package Compare versions

Comparing version 2.10.0 to 2.10.1

lib/reports/custom.js

23

lib/converter/converter.js

@@ -69,4 +69,4 @@ /**

// no need handle ignored and uncovered byte
if (count === 0 && ignored) {
// no need handle ignored byte
if (ignored) {
return;

@@ -145,5 +145,4 @@ }

lineItem.coveredCount = 1;
lineItem.uncoveredEntire = null;
lineItem.uncoveredPieces = [];
Util.initLineCoverage(lineItem);
lineMap.set(line, lineItem);

@@ -512,2 +511,7 @@ });

block.ranges.forEach((range) => {
const { fixedStart, fixedEnd } = Util.fixSourceRange(state.locator, range.startOffset, range.endOffset);
range.startOffset = fixedStart;
range.endOffset = fixedEnd;
addJsBytesCoverage(state, range);

@@ -561,3 +565,5 @@ });

const result = findOriginalRange(start, end, state, originalStateMap, true);
const result = findOriginalRange(start, end, state, originalStateMap, {
checkName: true
});
if (result.error) {

@@ -803,2 +809,3 @@ logMappingErrors('function', result);

const handleAllOriginalBytesCoverage = (state, originalStateMap) => {

@@ -826,3 +833,5 @@

const result = findOriginalRange(startOffset, endOffset, state, originalStateMap);
const result = findOriginalRange(startOffset, endOffset, state, originalStateMap, {
fixOriginalRange: true
});
if (result.error) {

@@ -829,0 +838,0 @@ logMappingErrors('byte', result);

@@ -537,4 +537,4 @@ const { diffSequence } = require('../packages/monocart-coverage-vendor.js');

// ========================================================================================================
const getFunctionName = (mp, state, checkName) => {
if (checkName && typeof mp.nameIndex !== 'undefined') {
const getFunctionName = (mp, state, options) => {
if (options.checkName && typeof mp.nameIndex !== 'undefined') {
return state.sourceMapNames[mp.nameIndex];

@@ -544,3 +544,3 @@ }

const getFixedOriginalStart = (start, mappings, state, cache, checkName) => {
const getFixedOriginalStart = (start, mappings, state, cache, options) => {

@@ -554,3 +554,3 @@ const [m1, m2] = mappings;

originalStart: m2.originalOffset,
originalName: getFunctionName(m2, state, checkName)
originalName: getFunctionName(m2, state, options)
};

@@ -587,3 +587,3 @@ }

originalStart: originalOffset + originalPos,
originalName: getFunctionName(m1, state, checkName)
originalName: getFunctionName(m1, state, options)
};

@@ -649,3 +649,3 @@ };

const getOriginalStartPosition = (cache, state, checkName) => {
const getOriginalStartPosition = (cache, state, options) => {

@@ -655,3 +655,3 @@ const { start, startMappings } = cache;

if (Array.isArray(startMappings)) {
return getFixedOriginalStart(start, startMappings, state, cache, checkName);
return getFixedOriginalStart(start, startMappings, state, cache, options);
}

@@ -662,3 +662,3 @@

originalStart: startMappings.originalOffset,
originalName: getFunctionName(startMappings, state, checkName)
originalName: getFunctionName(startMappings, state, options)
};

@@ -890,7 +890,8 @@ };

const findOriginalRange = (start, end, state, originalMap, checkName) => {
const findOriginalRange = (start, end, state, originalMap, options = {}) => {
const { sourcePath, rangeCache } = state;
const key = `${start}_${end}`;
const key = `${start}_${end}_${Boolean(options.fixOriginalRange)}`;
if (rangeCache.has(key)) {

@@ -920,3 +921,3 @@ return rangeCache.get(key);

const originalStartResult = getOriginalStartPosition(cache, state, checkName);
const originalStartResult = getOriginalStartPosition(cache, state, options);
const { originalStart, originalName } = originalStartResult;

@@ -938,4 +939,5 @@ // could be used for end

const { originalState } = cache;
const locator = originalState.locator;
const inComment = originalState.locator.lineParser.commentParser.isComment(originalStart, originalEnd);
const inComment = locator.lineParser.commentParser.isComment(originalStart, originalEnd);
if (inComment) {

@@ -945,3 +947,2 @@ return createMappingError(['the range in a original comment']);

const res = {

@@ -954,2 +955,8 @@ start: originalStart,

if (options.fixOriginalRange) {
const { fixedStart, fixedEnd } = Util.fixSourceRange(locator, originalStart, originalEnd);
res.start = fixedStart;
res.end = fixedEnd;
}
// cache response

@@ -956,0 +963,0 @@ rangeCache.set(key, res);

@@ -35,2 +35,4 @@ const fs = require('fs');

const { customReport } = require('./reports/custom.js');
const allBuiltInReports = {

@@ -212,3 +214,3 @@ // v8

} else {
await Util.runCustomReporter(reportName, coverageResults, reportOptions, options);
await customReport(reportName, coverageResults, reportOptions, options);
}

@@ -215,0 +217,0 @@ Util.logTime(`┌ [generate] saved report: ${reportName}`, t1);

@@ -341,2 +341,8 @@ const Util = {

initLineCoverage: (lineItem) => {
lineItem.coveredCount = 1;
lineItem.uncoveredEntire = null;
lineItem.uncoveredPieces = [];
},
updateLinesCoverage: (lines, count, lineMap) => {

@@ -343,0 +349,0 @@ lines.forEach((it) => {

const path = require('path');
const generateMarkdownGrid = require('../utils/markdown.js');
const Util = require('../utils/util.js');

@@ -106,3 +105,3 @@

const markdownGrid = generateMarkdownGrid({
const markdownGrid = Util.markdownGrid({
options: {

@@ -109,0 +108,0 @@ name: reportData.name

const path = require('path');
const generateMarkdownGrid = require('../utils/markdown.js');
const Util = require('../utils/util.js');

@@ -31,3 +30,3 @@

const markdownGrid = generateMarkdownGrid({
const markdownGrid = Util.markdownGrid({
options: {

@@ -34,0 +33,0 @@ name: reportData.name

@@ -55,3 +55,3 @@ const os = require('os');

const generateMarkdownGrid = (data) => {
const markdownGrid = (data) => {

@@ -133,2 +133,2 @@ const options = {

module.exports = generateMarkdownGrid;
module.exports = markdownGrid;
const fs = require('fs');
const { writeFile, readFile } = require('fs/promises');
const path = require('path');
const { pathToFileURL } = require('url');
const os = require('os');

@@ -9,6 +8,9 @@ const crypto = require('crypto');

const CG = require('console-grid');
const acornWalk = require('acorn-walk');
const Share = require('../platform/share.js');
const request = require('./request.js');
const version = require('../../package.json').version;
const acornWalk = require('acorn-walk');
const markdownGrid = require('./markdown.js');
const { findUpSync, supportsColor } = require('../packages/monocart-coverage-vendor.js');

@@ -33,2 +35,3 @@

request,
markdownGrid,

@@ -188,30 +191,2 @@ relativePath: function(p, root) {

runCustomReporter: async (reportName, reportData, reportOptions, globalOptions) => {
let CustomReporter;
let err;
try {
CustomReporter = await import(reportName);
} catch (e) {
err = e;
try {
CustomReporter = await import(pathToFileURL(reportName));
} catch (ee) {
err = ee;
}
}
if (!CustomReporter) {
Util.logError(err.message);
return;
}
CustomReporter = CustomReporter.default || CustomReporter;
const reporter = new CustomReporter(reportOptions, globalOptions);
const results = await reporter.generate(reportData);
return results;
},
getEOL: function(content) {

@@ -563,2 +538,83 @@ if (!content) {

// skip \s and comments
fixSourceRange: (locator, start, end) => {
let fixedStart = start;
let fixedEnd = end;
const rangeText = locator.getSlice(start, end);
let text = rangeText;
// =======================================
// handle end first
const oldLen = text.length;
text = text.trimEnd();
const newLen = text.length;
if (newLen < oldLen) {
fixedEnd -= oldLen - newLen;
}
// =======================================
// handle start
const comments = locator.lineParser.commentParser.comments;
let startOffset = 0;
// never start in a comment, skip to comment end
const inComment = comments.find((it) => start > it.start && start < it.end);
if (inComment) {
startOffset = inComment.end - start;
// next text
text = text.slice(startOffset);
}
while (startOffset < newLen) {
const beforeLen = text.length;
text = text.trimStart();
const afterLen = text.length;
if (afterLen === beforeLen) {
// no indent
break;
}
const indentLen = beforeLen - afterLen;
startOffset += indentLen;
// no comments
if (!comments.length) {
break;
}
const nextPos = start + startOffset;
const comment = comments.find((it) => it.start === nextPos);
if (!comment) {
break;
}
const commentLen = comment.end - comment.start;
startOffset += commentLen;
// next text
text = text.slice(commentLen);
}
// It should never be possible to start with }
if (rangeText[startOffset] === '}') {
startOffset += 1;
}
fixedStart = start + startOffset;
return {
fixedStart,
fixedEnd
};
},
cmpVersion: (v1, v2) => {

@@ -565,0 +621,0 @@ const [strMajor1, strMinor1, strPatch1] = `${v1}`.split('.');

@@ -14,2 +14,3 @@ const EC = require('eight-colors');

const { v8JsonReport } = require('../reports/v8-json.js');
const { customReport } = require('../reports/custom.js');

@@ -357,3 +358,3 @@ const getWrapperSource = (offset, source) => {

} else {
outputs[reportName] = await Util.runCustomReporter(reportName, reportData, reportOptions, options);
outputs[reportName] = await customReport(reportName, reportData, reportOptions, options);
}

@@ -360,0 +361,0 @@ Util.logTime(`┌ [generate] saved report: ${reportName}`, t1);

{
"name": "monocart-coverage-reports",
"version": "2.10.0",
"version": "2.10.1",
"description": "A code coverage tool to generate native V8 reports or Istanbul reports.",

@@ -56,5 +56,5 @@ "main": "./lib/index.js",

"test-client": "node ./test/test-client.js",
"test-all": "node ./test/test.js && node ./scripts/docs.js",
"test-all": "node ./test/test.js",
"test-pr": "node --inspect=9230 ./test/test-pr.js",
"test": "npm run test-unit && npx mcr npm run test-all -c test/mcr.config.mcr.js",
"test": "npm run test-unit && npx mcr npm run test-all -c test/mcr.config.mcr.js && node ./scripts/docs.js",
"test:snap": "cross-env TEST_SNAPSHOT=true npm run test",

@@ -109,6 +109,6 @@ "dev": "npx sf d app",

"starfall-cli": "^2.0.20",
"stylelint": "^16.7.0",
"stylelint": "^16.8.1",
"stylelint-config-plus": "^1.1.2",
"supports-color": "^9.4.0",
"tsx": "^4.16.2",
"tsx": "^4.16.5",
"turbogrid": "^3.2.0",

@@ -115,0 +115,0 @@ "vine-ui": "^3.1.16",

@@ -119,5 +119,7 @@ # Monocart Coverage Reports

- `v8-json`
- Save `CoverageResults` to a json file
- Preview [coverage-report.json](https://cenfun.github.io/monocart-coverage-reports/v8-and-istanbul/coverage-report.json)
- Save `CoverageResults` to a json file (defaults to [`coverage-report.json`](https://cenfun.github.io/monocart-coverage-reports/v8-and-istanbul/coverage-report.json)).
- Shows native V8 code coverage with VSCode extension [monocart-coverage-vscode](https://github.com/cenfun/monocart-coverage-vscode)
![](./assets/mcv.gif)
> Istanbul build-in reports (both V8 and Istanbul data):

@@ -124,0 +126,0 @@

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc