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.7 to 2.7.8

5

lib/client/cdp-client.js

@@ -15,6 +15,3 @@

const url = `${protocol}://${options.host}:${options.port}/json/list`;
const [err, res] = await Util.request({
url,
timeout: options.timeout
});
const [err, res] = await Util.request(url);
if (err) {

@@ -21,0 +18,0 @@ return [err];

4

lib/converter/collect-source-maps.js

@@ -22,5 +22,3 @@ const fs = require('fs');

const [err, res] = await Util.request({
url
});
const [err, res] = await Util.request(url);

@@ -27,0 +25,0 @@ if (err) {

@@ -8,4 +8,4 @@ /**

const EC = require('eight-colors');
const { Locator } = require('monocart-formatter');
const { Locator } = require('monocart-locator');
const Util = require('../utils/util.js');

@@ -988,5 +988,9 @@

const lengthBefore = sources.length;
let lengthAfter = 0;
sources.forEach((sourcePath, sourceIndex) => {
// filter
// do not change for sourceIndex
if (!sourceFilter(sourcePath)) {

@@ -1039,4 +1043,7 @@ // console.log('-', sourcePath);

originalStateMap.set(sourceIndex, originalState);
lengthAfter += 1;
});
Util.logFilter(`source filter (${state.sourcePath}):`, lengthBefore, lengthAfter);
return originalStateMap;

@@ -1050,2 +1057,4 @@ };

let added = 0;
// collect original files

@@ -1077,4 +1086,7 @@ originalStateMap.forEach((originalState) => {

state.originalList.push(originalState);
added += 1;
});
Util.logDebug(`added source files: ${EC.yellow(added)}`);
};

@@ -1081,0 +1093,0 @@

@@ -689,2 +689,3 @@ const fs = require('fs');

if (emptyData) {
Util.logDebug(`added empty files for all: ${EC.yellow(emptyData.length)}`);
const coverageResults = await addHandler(emptyData);

@@ -786,3 +787,7 @@ // after `add`

coverageData = coverageData.filter((entry) => entry.url && entry.url.startsWith('file:'));
const lengthBefore = coverageData.length;
coverageData = coverageData.filter(entryFilter);
const lengthAfter = coverageData.length;
Util.logFilter('entry filter (addFromDir):', lengthBefore, lengthAfter);

@@ -789,0 +794,0 @@ if (!Util.isList(coverageData)) {

@@ -64,2 +64,5 @@ const fs = require('fs');

// before clean cache, do no call initOptions again in hasCache
this.fixedOptions = true;
// init logging for clean after generated

@@ -83,3 +86,2 @@ this.logging = Util.initLoggingLevel(this.options.logging);

this.fixedOptions = true;
}

@@ -86,0 +88,0 @@

const http = require('http');
const https = require('https');
const dns = require('dns');
// fixed ECONNREFUSED on NodeJS 18
dns.setDefaultResultOrder('ipv4first');
// minimal http request for get sourcemap json
// https://nodejs.org/docs/latest/api/http.html#httprequesturl-options-callback
const request = (options) => {
const request = (url, options) => {
const url = `${options.url}`;
const HTTP = url.startsWith('https') ? https : http;

@@ -67,2 +62,26 @@ // console.log('request', url);

module.exports = request;
module.exports = async (url, options = {}) => {
let urlErr;
let urlObj;
try {
urlObj = new URL(url);
} catch (err) {
// console.error('error url', input);
urlErr = err;
}
if (urlErr) {
return [urlErr];
}
const [err, res] = await request(urlObj.toString(), options);
if (err) {
// replace localhost to 127.0.0.1
// ECONNREFUSED on NodeJS 18 https://github.com/node-fetch/node-fetch/issues/1624
if (urlObj.hostname === 'localhost') {
urlObj.hostname = '127.0.0.1';
return request(urlObj.toString(), options);
}
}
return [err, res];
};

@@ -146,2 +146,10 @@ const path = require('path');

// prepend sourceRoot
if (sourceRoot && !sourceName.startsWith(sourceRoot)) {
if (!sourceRoot.endsWith('/')) {
sourceRoot += '/';
}
sourceName = sourceRoot + sourceName;
}
// could be absolute path

@@ -166,10 +174,9 @@ // c:\\workspace\test\\selenium.spec.js

// as relative path, join sourceRoot
if (sourceRoot && !sourceName.startsWith(sourceRoot)) {
sourceName = path.join(sourceRoot, sourceName);
}
// console.log('sourceName', sourceName);
sourceName = path.normalize(sourceName);
// as relative path
const sourceUrl = pathToFileURL(sourceName).toString();
// console.log('sourceUrl', sourceUrl);
return sourceUrl;

@@ -203,2 +210,5 @@ };

module.exports = {
// for unit test
resolveSourceUrl,
getSourcePath,

@@ -205,0 +215,0 @@ getSourceType,

@@ -446,11 +446,14 @@ const fs = require('fs');

cmpVersion: (v1, v2) => {
const [major1, minor1, patch1] = `${v1}`.split('.').map((s) => parseInt(s));
const [major2, minor2, patch2] = `${v2}`.split('.').map((s) => parseInt(s));
const [strMajor1, strMinor1, strPatch1] = `${v1}`.split('.');
const [strMajor2, strMinor2, strPatch2] = `${v2}`.split('.');
const strList = [strMajor1, strMinor1, strPatch1, strMajor2, strMinor2, strPatch2];
const list = strList.map((str) => Util.toNum(parseInt(str)));
const [major1, minor1, patch1, major2, minor2, patch2] = list;
if (major1 === major2) {
if (minor1 === minor2) {
return Util.toNum(patch1) - Util.toNum(patch2);
return patch1 - patch2;
}
return Util.toNum(minor1) - Util.toNum(minor2);
return minor1 - minor2;
}
return Util.toNum(major1) - Util.toNum(major2);
return major1 - major2;
},

@@ -518,2 +521,13 @@

logFilter: (message, lengthBefore, lengthAfter) => {
if (Util.loggingLevel < Util.loggingLevels.debug) {
return;
}
if (lengthAfter < lengthBefore) {
lengthBefore = EC.yellow(lengthBefore);
lengthAfter = EC.yellow(lengthAfter);
}
console.log(`[MCR] ${message} before ${lengthBefore} => after ${lengthAfter}`);
},
// time is debug level, fix the log info, for checking snapshot

@@ -520,0 +534,0 @@ logTime: (message, time_start) => {

@@ -63,2 +63,7 @@ const path = require('path');

const lengthBefore = v8list.length;
v8list = v8list.filter(entryFilter);
const lengthAfter = v8list.length;
Util.logFilter('entry filter (add):', lengthBefore, lengthAfter);
// filter no source or text

@@ -69,7 +74,2 @@ // init type and css source from text

// filter entry
if (!entryFilter(entry)) {
// console.log('-', entry.url);
return false;
}
// console.log(entry.url);

@@ -97,3 +97,2 @@

// onEntry hook

@@ -100,0 +99,0 @@ // after filter but before init, because id depends source and sourcePath

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

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

"build": "sf lint && sf b -p && npm run build-test",
"test-unit": "mocha --parallel test/unit/*.test.js",
"test-node-env": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-env node ./test/test-node-env.js && node ./test/generate-report.js",

@@ -46,2 +47,3 @@ "test-node-api": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-api node ./test/test-node-api.js",

"test-rollup": "node ./test/test-rollup.js",
"test-swc": "node ./test/test-swc.js",
"test-v8-and-istanbul": "node ./test/test-v8-and-istanbul.js",

@@ -56,3 +58,3 @@ "test-browser": "node ./test/test.js --browser",

"test-all": "node ./test/test.js && node ./scripts/docs.js",
"test": "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",
"test:snap": "cross-env TEST_SNAPSHOT=true npm run test",

@@ -82,4 +84,5 @@ "dev": "sf d v8",

"lz-utils": "^2.0.2",
"monocart-code-viewer": "^1.1.2",
"monocart-formatter": "^2.3.2",
"monocart-code-viewer": "^1.1.3",
"monocart-formatter": "^3.0.0",
"monocart-locator": "^1.0.0",
"turbogrid": "^3.0.13"

@@ -93,5 +96,5 @@ },

"eslint-plugin-html": "^8.0.0",
"eslint-plugin-vue": "^9.23.0",
"minimatch": "^9.0.3",
"stylelint": "^16.3.0",
"eslint-plugin-vue": "^9.24.0",
"minimatch": "^9.0.4",
"stylelint": "^16.3.1",
"stylelint-config-plus": "^1.1.0",

@@ -98,0 +101,0 @@ "supports-color": "^9.4.0",

@@ -53,2 +53,4 @@ # Monocart Coverage Reports

- [Sonar Cloud](#sonar-cloud)
* [Contributing](#contributing)
* [Changelog](CHANGELOG.md)
* [Thanks](#thanks)

@@ -226,15 +228,20 @@

- swc: [swc-plugin-coverage-instrument](https://github.com/kwonoj/swc-plugin-coverage-instrument)
- Browser
- Collecting coverage data from `window.__coverage__`, example: [test-istanbul.js](./test/test-istanbul.js)
- Node.js
- Collecting coverage data from `global.__coverage__`
- CDP
- `getIstanbulCoverage()` see [`CDPClient` API](#collecting-v8-coverage-data-with-cdpclient-api)
## Collecting V8 Coverage Data
- Before coverage collection: Enabling `sourcemap` for source code
- [webpack](https://webpack.js.org/configuration/): `devtool: source-map` and `mode: development`, example [webpack.config-v8.js](./test/build/webpack.config-v8.js)
- [rollup](https://rollupjs.org/configuration-options/): `sourcemap: true`
- [rollup](https://rollupjs.org/configuration-options/): `sourcemap: true` and `treeshake: false`
- [esbuild](https://esbuild.github.io/api/): `sourcemap: true`, `treeShaking: false` and `minify: false`
- [vite](https://vitejs.dev/config/build-options.html): `sourcemap: true` and `minify: false`
- [esbuild](https://esbuild.github.io/api/): `sourcemap: true` and `minify: false`
- Browser (Chromium Only)
- Browser (Chromium-based Only)
- [Collecting V8 Coverage Data with Playwright](#collecting-v8-coverage-data-with-playwright)

@@ -336,4 +343,24 @@ - [Collecting Raw V8 Coverage Data with Puppeteer](#collecting-raw-v8-coverage-data-with-puppeteer)

### Collecting V8 Coverage Data with `CDPClient` API
- Work with node debugger port `--inspect=9229`
- `CDPClient` available APIs
```js
startJSCoverage: () => Promise<void>;
stopJSCoverage: () => Promise<V8CoverageEntry[]>;
startCSSCoverage: () => Promise<void>;
stopCSSCoverage: () => Promise<V8CoverageEntry[]>;
/** start both js and css coverage */
startCoverage: () => Promise<void>;
/** stop and return both js and css coverage */
stopCoverage: () => Promise<V8CoverageEntry[]>;
/** write the coverage started by NODE_V8_COVERAGE to disk on demand, returns v8 coverage dir */
writeCoverage: () => Promise<string>;
/** get istanbul coverage data */
getIstanbulCoverage: (coverageKey?: string) => Promise<any>;
```
- Work with node debugger port `--inspect=9229` or browser debugging port `--remote-debugging-port=9229`
```js
const MCR = require('monocart-coverage-reports');

@@ -347,2 +374,3 @@ const client = await MCR.CDPClient({

```
- Work with [Playwright CDPSession](https://playwright.dev/docs/api/class-cdpsession)

@@ -364,2 +392,3 @@ ```js

```
- Work with [Puppeteer CDPSession](https://pptr.dev/api/puppeteer.cdpsession)

@@ -381,2 +410,3 @@ ```js

```
- Work with [Selenium Webdriver](https://www.selenium.dev/documentation/webdriver/) WebSocket (Chrome/Edge Browser)

@@ -393,26 +423,3 @@ ```js

```
- `CDPClient` available APIs
```js
/** start js coverage */
startJSCoverage: () => Promise<void>;
/** stop and return js coverage */
stopJSCoverage: () => Promise<V8CoverageEntry[]>;
/** start css coverage */
startCSSCoverage: () => Promise<void>;
/** stop and return css coverage */
stopCSSCoverage: () => Promise<V8CoverageEntry[]>;
/** start both js and css coverage */
startCoverage: () => Promise<void>;
/** stop and return both js and css coverage */
stopCoverage: () => Promise<V8CoverageEntry[]>;
/** write the coverage started by NODE_V8_COVERAGE to disk on demand, returns v8 coverage dir */
writeCoverage: () => Promise<string>;
/** get istanbul coverage data */
getIstanbulCoverage: (coverageKey?: string) => Promise<any>;
```
### V8 Coverage Data API

@@ -710,2 +717,8 @@ - [JavaScript code coverage in V8](https://v8.dev/blog/javascript-code-coverage)

- Examples
- [Mocha](#mocha)
- [tsx](#tsx)
- [ts-node](#ts-node)
- [AVA](#ava)
## Config File

@@ -980,2 +993,14 @@ Loading config file by priority:

## Contributing
```sh
# Node.js 20+
npm install starfall-cli -g
npm install
npm run build
npm run test
npm run dev
```
### VSCode Extension

@@ -982,0 +1007,0 @@ - [Coverage Gutters](https://github.com/ryanluker/vscode-coverage-gutters) - Display test coverage generated by lcov or xml in VSCode editor.

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

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