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

monocart-coverage-reports

Package Overview
Dependencies
Maintainers
1
Versions
89
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.7.4 to 2.7.5

75

lib/converter/ast-visitor.js

@@ -11,2 +11,8 @@ const Util = require('../utils/util.js');

const setGeneratedOnly = (block, generatedOnly) => {
if (block && generatedOnly) {
block.generatedOnly = true;
}
};
const getParentFunctionState = (reverseParents) => {

@@ -270,2 +276,3 @@ const parentFunction = reverseParents.find((it) => it._state && it._state.isFunction);

parentCount = groupBlock.count;
setGeneratedOnly(groupBlock, group.generatedOnly);
}

@@ -282,2 +289,3 @@

item.block = getFunctionBlock(start, end, functionState);
setGeneratedOnly(item.block, group.generatedOnly);
});

@@ -320,3 +328,3 @@

branches.push({
const branch = {
type: group.type,

@@ -326,3 +334,7 @@ start: group.start,

locations: group.locations
});
};
setGeneratedOnly(branch, group.generatedOnly);
branches.push(branch);
});

@@ -404,3 +416,31 @@

// =======================================================================================
// handle special generated codes for original coverage
const webpackWrapHandler = (node) => {
// ignore webpack wrap for original function
// id: { type: 'Identifier', name: '__webpack_modules__' },
const name = node.id && node.id.name;
if (name === '__webpack_modules__' && node.init && node.init.properties) {
// mark all as wrap function
node.init.properties.forEach((it) => {
it.value._webpackWrapKey = it.key && it.key.value;
});
// console.log('==========================', node.type);
// console.log(name, parents.length);
}
};
const viteImportDefaultHandler = (node, group) => {
// ignore vite conditional expression for __esModule default
const testObj = node.test.object;
const testName = testObj && testObj.name;
if (testName && testName.startsWith('__vite__cjsImport')) {
setGeneratedOnly(group, true);
}
};
// =======================================================================================
const collectNodes = (ast) => {

@@ -418,14 +458,3 @@ const functionNodes = [];

// =============================================================
// id: { type: 'Identifier', name: '__webpack_modules__' },
const name = node.id && node.id.name;
if (name === '__webpack_modules__' && node.init && node.init.properties) {
// mark all as wrap function
node.init.properties.forEach((it) => {
it.value._wrapKey = it.key && it.key.value;
});
// console.log('==========================', node.type);
// console.log(name, parents.length);
}
// =============================================================
webpackWrapHandler(node);

@@ -483,2 +512,3 @@ },

ConditionalExpression: (node, parents) => {
const { consequent, alternate } = node;

@@ -488,2 +518,5 @@ const group = createBranchGroup(BranchTypes.ConditionalExpression, node, parents, branchMap);

addBranch(group, alternate, locationMap);
viteImportDefaultHandler(node, group);
},

@@ -631,3 +664,3 @@

const functionName = id && id.name;
const isWrap = Boolean(node._wrapKey);
const _webpackWrapKey = node._webpackWrapKey;

@@ -642,5 +675,5 @@ const functionItem = {

};
if (isWrap) {
functionItem.wrap = true;
}
setGeneratedOnly(functionItem, _webpackWrapKey);
functions.push(functionItem);

@@ -655,5 +688,5 @@

if (functionRange) {
if (isWrap) {
functionRange.wrap = true;
}
setGeneratedOnly(functionRange, _webpackWrapKey);
functionState.range = functionRange;

@@ -660,0 +693,0 @@ functionState.count = functionRange.count;

@@ -31,3 +31,10 @@ const fs = require('fs');

return res.data;
const content = res.data;
// could be string not json, if Content-Type is application/octet-stream
if (typeof content === 'string') {
return JSON.parse(content);
}
return content;
};

@@ -34,0 +41,0 @@

@@ -513,2 +513,7 @@ /**

// it could be a dist file, do not handle twice
if (state.addedGeneratedBytes) {
return;
}
const { js, coverageList } = state;

@@ -528,2 +533,4 @@

state.addedGeneratedBytes = true;
};

@@ -556,11 +563,12 @@

state.astInfo.functions.forEach((it) => {
const {
start, end, bodyStart, bodyEnd, wrap
} = it;
// remove webpack wrap functions for functions count, not for ranges here
if (wrap) {
if (it.generatedOnly) {
return;
}
const {
start, end, bodyStart, bodyEnd
} = it;
const result = findOriginalRange(start, end, state, originalStateMap);

@@ -604,2 +612,6 @@ if (result.error) {

if (group.generatedOnly) {
return;
}
const { type, locations } = group;

@@ -675,2 +687,7 @@

state.astInfo.statements.forEach((it) => {
if (it.generatedOnly) {
return;
}
const { start, end } = it;

@@ -807,7 +824,6 @@

coverageList.forEach((block) => {
block.ranges.forEach((range, index) => {
block.ranges.forEach((range) => {
// remove wrap functions for original files
if (range.wrap) {
// console.log(range);
if (range.generatedOnly) {
return;

@@ -814,0 +830,0 @@ }

@@ -122,4 +122,28 @@ const { diff } = require('../packages/monocart-coverage-vendor');

const getWordEndPosition = (list, gp, direction) => {
// for end only
if (direction !== 'end') {
return;
}
const prev = list[gp - 1];
if (prev && prev.original && prev.wordEnd) {
const op = prev.original.index + 1;
// console.log(gp, JSON.stringify(gt));
// console.log(op, JSON.stringify(ot));
return {
pos: op
};
}
};
const getAlignPosition = (gt, gp, ot, direction) => {
// there is no need to align for long text
const maxLength = 500;
if (gt.length > maxLength || ot.length > maxLength) {
// console.log(gt.length, ot.length, gp);
return;
}
// generatedText: '"false";\n',

@@ -151,17 +175,4 @@ // originalText: "'false';\r\n ",

// inclusive, for end only
if (gp && direction === 'end') {
const prev = list[gp - 1];
if (prev && prev.original && prev.wordEnd) {
// console.log(direction, '=====================================================================');
const op = prev.original.index + 1;
// console.log(gp, JSON.stringify(gt));
// console.log(op, JSON.stringify(ot));
return getWordEndPosition(list, gp, direction);
return {
pos: op
};
}
}
};

@@ -257,3 +268,9 @@

const ot = info.originalText;
const olt = info.originalLineText;
// seems direction is start only
if (gp === 0) {
return;
}
// whole generated text

@@ -264,3 +281,3 @@ if (gp >= gt.length) {

return {
pos: info.originalLineText.length
pos: olt.length
};

@@ -267,0 +284,0 @@ }

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

@@ -50,2 +50,3 @@ "main": "./lib/index.js",

"test-tsx": "npx mcr tsx ./test/specs/tsx.test.ts -c test/mcr.config.tsx.js",
"test-demo": "node ./test/test-demo.js",
"test-merge": "node ./test/test-merge.js",

@@ -52,0 +53,0 @@ "test-merge-istanbul": "node ./test/test-merge-istanbul.js",

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