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.10.8 to 2.10.9-beta.0

24

lib/converter/untested.js

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

// save all empty coverage
const dataId = Util.uid();
// save all empty coverage, 20 - 5(empty)
const dataId = Util.uid(15, 'empty');
const results = {

@@ -170,6 +170,5 @@ id: dataId

// for raw report: source file
// id, url, source, sourceMap
await saveUntestedFileSource(entry, options);
const { type, url } = entry;
if (coverageType === 'istanbul') {

@@ -179,3 +178,3 @@

const item = {
path: fileURLToPath(url),
path: fileURLToPath(entry.url),
statementMap: {},

@@ -195,16 +194,3 @@ fnMap: {},

// ===============================================
if (type === 'js') {
// empty js
entry.functions = entry.functions || [{
functionName: '',
ranges: [{
startOffset: 0,
endOffset: entry.source.length,
count: 0
}]
}];
} else {
// empty css
entry.ranges = entry.ranges || [];
}
Util.setEmptyV8Coverage(entry);

@@ -211,0 +197,0 @@ const item = {

@@ -275,2 +275,23 @@ const fs = require('fs');

setEmptyV8Coverage: (entry) => {
if (entry.type === 'css') {
// empty css
if (!entry.ranges) {
entry.ranges = [];
}
} else {
// empty js
if (!entry.functions) {
entry.functions = [{
functionName: '',
ranges: [{
startOffset: 0,
endOffset: entry.source ? entry.source.length : 0,
count: 0
}]
}];
}
}
},
saveSourceCacheFile: async (sourceData, options, fileCache) => {

@@ -277,0 +298,0 @@ const { cacheName, cachePath } = Util.getCacheFileInfo('source', sourceData.id, options.cacheDir);

@@ -112,7 +112,7 @@ const EC = require('eight-colors');

// coverage
if (data.type === 'js') {
// coverage info
if (data.type === 'css') {
data.ranges = entry.ranges;
} else {
data.functions = entry.functions;
} else {
data.ranges = entry.ranges;
}

@@ -217,6 +217,6 @@

const item = itemMap[id];
if (item.type === 'js') {
if (item.type === 'css') {
item.ranges = await mergeCssRanges(itemList);
} else {
item.functions = await mergeJsFunctions(itemList);
} else {
item.ranges = await mergeCssRanges(itemList);
}

@@ -241,12 +241,17 @@ }

// try to load coverage and source by id
for (const item of mergedList) {
const { id } = item;
const json = sourceCache.get(id);
for (const entry of mergedList) {
const json = sourceCache.get(entry.id);
if (json) {
item.source = json.source;
item.sourceMap = json.sourceMap;
entry.source = json.source;
entry.sourceMap = json.sourceMap;
} else {
Util.logError(`Not found source data: ${Util.relativePath(item.sourcePath)}`);
item.source = '';
Util.logError(`Not found source data: ${Util.relativePath(entry.sourcePath)}`);
entry.source = '';
}
// add empty coverage after source init
if (entry.empty) {
Util.setEmptyV8Coverage(entry);
}
}

@@ -253,0 +258,0 @@

{
"name": "monocart-coverage-reports",
"version": "2.10.8",
"version": "2.10.9-beta.0",
"description": "A code coverage tool to generate native V8 reports or Istanbul reports.",

@@ -61,3 +61,4 @@ "main": "./lib/index.js",

"eol": "git rm -rf --cached . && git reset --hard HEAD",
"patch": "npm run build && npm run test && npx sf publish patch -r"
"patch": "npm version patch && npm run build && npm run test && npm publish",
"beta": "npm version prerelease --preid=beta && npm run build && npm run test && npm publish --tag beta"
},

@@ -64,0 +65,0 @@ "workspaces": [

@@ -612,14 +612,12 @@ # Monocart Coverage Reports

## Adding Empty Coverage for Untested Files
By default the untested files will not be included in the coverage report, we can add empty coverage data for all files with option `all`, the untested files will show 0% coverage.
By default the untested files will not be included in the coverage report, we can add empty coverage for untested files with option `all`, the untested files will show 0% coverage.
```js
const coverageOptions = {
all: {
dir: ['./src'],
filter: (filePath) => {
return true;
}
}
all: './src',
// or multiple dirs
all: ['./src', './lib'],
};
```
The filter also supports [`minimatch`](https://github.com/isaacs/minimatch) pattern:
The untested files will apply to the `sourceFilter`. And it also supports additional `filter` (return the file type for js or css coverage):
```js

@@ -629,9 +627,2 @@ const coverageOptions = {

dir: ['./src'],
filter: '**/*.js'
}
};
// or multiple patterns
const coverageOptions = {
all: {
dir: ['./src'],
filter: {

@@ -641,3 +632,2 @@ // exclude files

'**/*.html': false,
'**/*.ts': false,
// empty css coverage

@@ -650,2 +640,28 @@ '**/*.scss': "css",

```
We can also compile these untested files, such as .ts, .jsx, or .vue, etc., so that they can be analyzed by the default AST parser, thus get more coverage metric data.
```js
const path = require("path");
const swc = require("@swc/core");
const coverageOptions = {
all: {
dir: ['./src'],
transformer: async (entry) => {
const { code, map } = await swc.transform(entry.source, {
filename: path.basename(entry.url),
sourceMaps: true,
isModule: true,
jsc: {
parser: {
syntax: "typescript",
jsx: true
},
transform: {}
}
});
entry.source = code;
entry.sourceMap = JSON.parse(map);
}
}
};
```

@@ -652,0 +668,0 @@ ## onEnd Hook

@@ -618,11 +618,9 @@ # Monocart Coverage Reports

const coverageOptions = {
all: {
dir: ['./src'],
filter: (filePath) => {
return true;
}
}
all: './src',
// 支持多个目录
all: ['./src', './lib'],
};
```
`filter`过滤也支持[`minimatch`](https://github.com/isaacs/minimatch)匹配:
未测试的文件也适用于`sourceFilter`过滤器. 而且也可以指定自己的`filter`过滤器 (可以返回文件类型来支持js或css的覆盖率格式):
```js

@@ -632,9 +630,2 @@ const coverageOptions = {

dir: ['./src'],
filter: '**/*.js'
}
};
// 多个匹配
const coverageOptions = {
all: {
dir: ['./src'],
filter: {

@@ -644,3 +635,2 @@ // exclude files

'**/*.html': false,
'**/*.ts': false,
// empty css coverage

@@ -653,2 +643,28 @@ '**/*.scss': "css",

```
我们可能需要编译.ts, .jsx, .vue等等这样的文件, 这样才能被默认的AST解析器解析,以得到更多的覆盖率指标的数据
```js
const path = require("path");
const swc = require("@swc/core");
const coverageOptions = {
all: {
dir: ['./src'],
transformer: async (entry) => {
const { code, map } = await swc.transform(entry.source, {
filename: path.basename(entry.url),
sourceMaps: true,
isModule: true,
jsc: {
parser: {
syntax: "typescript",
jsx: true
},
transform: {}
}
});
entry.source = code;
entry.sourceMap = JSON.parse(map);
}
}
};
```

@@ -655,0 +671,0 @@ ## onEnd Hook

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