monocart-coverage-reports
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -173,3 +173,3 @@ const { | ||
} catch (e) { | ||
Util.logError(`failed to parse source file and fall back to loose: ${item.sourcePath} ${e.message}`); | ||
Util.logInfo(`failed to parse source file: ${item.sourcePath} ${e.message}`); | ||
// https://github.com/acornjs/acorn/tree/master/acorn-loose | ||
@@ -176,0 +176,0 @@ // It is recommended to always try a parse with the regular acorn parser first, |
@@ -777,4 +777,5 @@ // https://github.com/demurgos/v8-coverage | ||
const url = fileUrls[sourcePath] || sourcePath; | ||
// add dist for id | ||
const id = Util.calculateSha1(distFile + url + source); | ||
const id = Util.calculateSha1(distFile + sourcePath + source); | ||
@@ -979,3 +980,4 @@ const sourceItem = { | ||
Object.assign(coverageData, state.coverageData); | ||
if (state.sourceList) { | ||
if (Util.isList(state.sourceList)) { | ||
sourceList = sourceList.concat(state.sourceList); | ||
@@ -986,8 +988,12 @@ } | ||
// dedupe | ||
dedupeV8List(v8list); | ||
// add all sources | ||
if (sourceList.length) { | ||
sourceList.forEach((item) => { | ||
// exists same id, mark previous item as dedupe | ||
const prevItem = v8list.find((it) => it.id === item.id); | ||
if (prevItem) { | ||
prevItem.dedupe = true; | ||
} | ||
v8list.push(item); | ||
@@ -997,2 +1003,5 @@ }); | ||
// dedupe | ||
dedupeV8List(v8list); | ||
return { | ||
@@ -999,0 +1008,0 @@ fileSources, |
@@ -107,8 +107,5 @@ declare namespace MCR { | ||
status: "low" | "medium" | "high" | "unknown"; | ||
} | ||
export interface LinesSummary extends MetricsSummary { | ||
/** V8 only */ | ||
/** V8 lines only */ | ||
blank?: number; | ||
/** V8 only */ | ||
/** V8 lines only */ | ||
comment?: number; | ||
@@ -120,3 +117,3 @@ } | ||
branches: MetricsSummary; | ||
lines: LinesSummary; | ||
lines: MetricsSummary; | ||
/** V8 only */ | ||
@@ -237,2 +234,7 @@ bytes?: MetricsSummary; | ||
export interface McrCliOptions extends CoverageReportOptions { | ||
/** {function} onStart hook */ | ||
onStart?: (coverageReport: CoverageReport) => Promise<void>; | ||
} | ||
} | ||
@@ -239,0 +241,0 @@ |
const path = require('path'); | ||
const { fileURLToPath } = require('url'); | ||
const Util = require('./util.js'); | ||
@@ -41,12 +42,17 @@ | ||
const u = resolveUrl(url); | ||
if (u) { | ||
const host = [u.hostname, u.port].filter((it) => it).join('-'); | ||
if (url.startsWith('file:')) { | ||
const relPath = Util.relativePath(fileURLToPath(url)); | ||
return filterPath(relPath); | ||
} | ||
const urlObj = resolveUrl(url); | ||
if (urlObj) { | ||
const host = [urlObj.hostname, urlObj.port].filter((it) => it).join('-'); | ||
// always start with '/' | ||
const pathname = u.pathname; | ||
const pathname = urlObj.pathname; | ||
let p = host + pathname; | ||
// webpack://monocart-v8/packages/v8/src/app.vue?5cc4 | ||
if (u.search) { | ||
p += `/${u.search}`; | ||
if (urlObj.search) { | ||
p += `/${urlObj.search}`; | ||
} | ||
@@ -57,4 +63,3 @@ | ||
const relPath = Util.relativePath(url); | ||
return filterPath(relPath); | ||
return filterPath(url); | ||
}; | ||
@@ -61,0 +66,0 @@ |
@@ -58,3 +58,9 @@ const path = require('path'); | ||
data.id = Util.calculateSha1(data.url + data.source); | ||
const idList = []; | ||
// could be existed | ||
const distFile = item.distFile; | ||
if (distFile) { | ||
data.distFile = distFile; | ||
idList.push(distFile); | ||
} | ||
@@ -71,2 +77,7 @@ let sourcePath = getSourcePath(data.url, i + 1, data.type); | ||
idList.push(sourcePath); | ||
idList.push(data.source); | ||
data.id = Util.calculateSha1(idList.join('')); | ||
return data; | ||
@@ -73,0 +84,0 @@ }); |
{ | ||
"name": "monocart-coverage-reports", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Monocart coverage reports", | ||
"main": "lib/index.js", | ||
"main": "./lib/index.js", | ||
"bin": { | ||
"mcr": "./lib/cli.js" | ||
}, | ||
"exports": { | ||
@@ -20,3 +23,3 @@ ".": { | ||
"build": "sf lint && sf b -p && npm run build-test", | ||
"test-node": "npm run test-node-env && npm run test-node-api && npm run test-node-ins && npm run test-node-cdp", | ||
"test-node": "npm run test-node-env && npm run test-node-api && npm run test-node-ins && npm run test-node-cdp && npm run test-node-koa", | ||
"test-node-env": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-env node ./test/test-node-env.js && node ./test/generate-node-report.js", | ||
@@ -27,4 +30,6 @@ "test-node-api": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-api node ./test/test-node-api.js", | ||
"test-node-cdp": "node --inspect=9229 ./test/test-node-cdp.js", | ||
"test-node-koa": "node ./test/test-node-koa.js", | ||
"test-browser": "node ./test/test.js", | ||
"test": "npm run test-browser && npm run test-node && npm run build-docs", | ||
"test-cli": "npx mcr \"node ./test/test-node-env.js\" -o docs/cli -r v8,console-summary --lcov -c test/cli-options.js", | ||
"test": "npm run test-browser && npm run test-node && npm run test-cli && npm run build-docs", | ||
"dev": "sf d v8", | ||
@@ -55,9 +60,10 @@ "open": "node ./scripts/open.js", | ||
"monocart-formatter": "~2.3.0", | ||
"turbogrid": "~3.0.12" | ||
"turbogrid": "^3.0.13" | ||
}, | ||
"devDependencies": { | ||
"commander": "^11.1.0", | ||
"eslint": "^8.56.0", | ||
"eslint-config-plus": "^1.0.6", | ||
"eslint-plugin-html": "^7.1.0", | ||
"eslint-plugin-vue": "^9.20.0", | ||
"eslint-plugin-vue": "^9.20.1", | ||
"stylelint": "^15.11.0", | ||
@@ -64,0 +70,0 @@ "stylelint-config-plus": "^1.0.4" |
@@ -16,2 +16,3 @@ # Monocart Coverage Reports | ||
* [onEnd Hook](#onend-hook) | ||
* [`mcr` CLI](#mcr-cli) | ||
* [Compare Reports](#compare-reports) | ||
@@ -53,5 +54,9 @@ * [Compare Workflows](#compare-workflows) | ||
- `v8` (V8 data only) | ||
- [V8 html](https://cenfun.github.io/monocart-coverage-reports/v8) - Example for browser, build with webpack, and also [Rollup](https://cenfun.github.io/monocart-coverage-reports/v8-rollup) and [Esbuild](https://cenfun.github.io/monocart-coverage-reports/v8-esbuild) | ||
- [V8 Node](https://cenfun.github.io/monocart-coverage-reports/v8-node-env) - Example for Node.js using env, and also [V8 API](https://cenfun.github.io/monocart-coverage-reports/v8-node-api), [Inspector](https://cenfun.github.io/monocart-coverage-reports/v8-node-ins) and [CDP](https://cenfun.github.io/monocart-coverage-reports/v8-node-cdp) | ||
- [V8 Minify](https://cenfun.github.io/monocart-coverage-reports/v8-minify) | ||
- Test in browser | ||
- Build with webpack: [V8](https://cenfun.github.io/monocart-coverage-reports/v8) and [V8 Minify](https://cenfun.github.io/monocart-coverage-reports/v8-minify) | ||
- Build with [Rollup](https://cenfun.github.io/monocart-coverage-reports/v8-rollup) and [Esbuild](https://cenfun.github.io/monocart-coverage-reports/v8-esbuild) | ||
- Collect with [puppeteer](https://cenfun.github.io/monocart-coverage-reports/puppeteer/) | ||
- Test in Node.js | ||
- Collect with [env](https://cenfun.github.io/monocart-coverage-reports/v8-node-env), and also V8 [API](https://cenfun.github.io/monocart-coverage-reports/v8-node-api), [Inspector](https://cenfun.github.io/monocart-coverage-reports/v8-node-ins) and [CDP](https://cenfun.github.io/monocart-coverage-reports/v8-node-cdp) | ||
- Web server example: [koa](https://cenfun.github.io/monocart-coverage-reports/v8-node-koa/) | ||
@@ -169,2 +174,39 @@ ![](test/v8.gif) | ||
## `mcr` CLI | ||
- Global mode | ||
```sh | ||
npm i monocart-coverage-reports -g | ||
mcr "node ./test/test-node-env.js" -r v8,console-summary --lcov | ||
``` | ||
- Current working directory mode | ||
```sh | ||
npm i monocart-coverage-reports | ||
npx mcr "node ./test/test-node-env.js" -r v8,console-summary --lcov | ||
``` | ||
- CLI Options | ||
```sh | ||
Usage: mcr [options] <command> | ||
CLI to generate coverage reports | ||
Arguments: | ||
command command to execute | ||
Options: | ||
-V, --version output the version number | ||
-c, --config <path> config path for options | ||
-o, --outputDir <dir> output dir for reports | ||
-r, --reports <name[,name]> coverage reports to use | ||
-n, --name <name> report name for title | ||
--outputFile <path> output file for v8 report | ||
--inline inline html for v8 report | ||
--assetsPath <path> assets path if not inline | ||
--lcov generate lcov.info file | ||
-h, --help display help for command | ||
``` | ||
- Using configuration file for more options | ||
```sh | ||
mcr "node ./test/test-node-env.js" -c test/cli-options.js | ||
``` | ||
## Compare Reports | ||
@@ -212,3 +254,3 @@ | | Istanbul | V8 | V8 to Istanbul | | ||
- Browser (Chromium Only) | ||
> Collecting coverage data with [Chromium Coverage API](#chromium-coverage-api), see [example](https://github.com/cenfun/monocart-coverage-reports/blob/main/test/test-v8.js) | ||
> Collecting coverage data with [Chromium Coverage API](#chromium-coverage-api), see [playwright example](https://github.com/cenfun/monocart-coverage-reports/blob/main/test/test-v8.js) or [puppeteer example](https://github.com/cenfun/monocart-coverage-reports/blob/main/test/test-puppeteer.js) | ||
- Node.js | ||
@@ -219,3 +261,4 @@ > see [Node.js V8 Coverage Report for Server Side](#nodejs-v8-coverage-report-for-server-side) | ||
## Node.js V8 Coverage Report for Server Side | ||
- Using Node.js env [NODE_V8_COVERAGE](https://nodejs.org/docs/latest/api/cli.html#node_v8_coveragedir)=`dir` | ||
Possible solutions: | ||
- Node.js env [NODE_V8_COVERAGE](https://nodejs.org/docs/latest/api/cli.html#node_v8_coveragedir)=`dir` | ||
- Before running your Node.js application, set env `NODE_V8_COVERAGE`=`dir`. After the application runs and exits, the coverage data will be saved to the `dir` directory in JSON file format | ||
@@ -226,3 +269,3 @@ - Read the json file(s) from the `dir` and generate coverage report | ||
- Using [V8](https://nodejs.org/docs/latest/api/v8.html#v8takecoverage) API + NODE_V8_COVERAGE | ||
- [V8](https://nodejs.org/docs/latest/api/v8.html#v8takecoverage) API + NODE_V8_COVERAGE | ||
- Writing the coverage started by NODE_V8_COVERAGE to disk on demand with `v8.takeCoverage()` and stopping with `v8.stopCoverage()`. | ||
@@ -232,3 +275,3 @@ - example: | ||
- Using [Inspector](https://nodejs.org/docs/latest/api/inspector.html) API (or module [collect-v8-coverage](https://github.com/SimenB/collect-v8-coverage)) | ||
- [Inspector](https://nodejs.org/docs/latest/api/inspector.html) API (or module [collect-v8-coverage](https://github.com/SimenB/collect-v8-coverage)) | ||
- Connecting to the V8 inspector and enable V8 coverage. | ||
@@ -238,3 +281,3 @@ - Taking coverage data and adding to the report after your application runs. | ||
- Using [CDP](https://chromedevtools.github.io/devtools-protocol/) API | ||
- [CDP](https://chromedevtools.github.io/devtools-protocol/) API | ||
- Enabling [Node Debugging](https://nodejs.org/en/guides/debugging-getting-started/) | ||
@@ -244,2 +287,7 @@ - Collecting coverage data with CDP API. | ||
- [Debugger](https://nodejs.org/en/guides/debugging-getting-started) + NODE_V8_COVERAGE + CDP + V8 API | ||
> cross-env NODE_V8_COVERAGE=.temp/v8-coverage-koa node --inspect=9229 [./test/koa.js](./test/koa.js) | ||
- example: | ||
> node [./test/test-node-koa.js](./test/test-node-koa.js) | ||
## Using `entryFilter` and `sourceFilter` to filter the results for V8 report | ||
@@ -345,4 +393,4 @@ When V8 coverage data collected, it actually contains the data of all entry files, for example: | ||
- [V8 coverage report](https://v8.dev/blog/javascript-code-coverage) - Native support for JavaScript code coverage to V8. (Chromium only) | ||
- [Puppeteer Coverage Class](https://pptr.dev/api/puppeteer.coverage) | ||
- [Playwright Coverage Class](https://playwright.dev/docs/api/class-coverage) | ||
- [Puppeteer Coverage class](https://pptr.dev/api/puppeteer.coverage) | ||
- [DevTools Protocol for Coverage](https://chromedevtools.github.io/devtools-protocol/tot/Profiler/#method-startPreciseCoverage) | ||
@@ -393,3 +441,22 @@ | ||
### Collect raw v8 coverage data with Puppeteer | ||
```js | ||
await page.coverage.startJSCoverage({ | ||
// provide raw v8 coverage data | ||
includeRawScriptCoverage: true | ||
}); | ||
await page.goto(url); | ||
const jsCoverage = await page.coverage.stopJSCoverage(); | ||
const rawV8CoverageData = jsCoverage.map((it) => { | ||
// Convert to raw v8 coverage format | ||
return { | ||
source: it.text, | ||
... it.rawScriptCoverage | ||
}; | ||
} | ||
``` | ||
see example: [./test/test-puppeteer.js](./test/test-puppeteer.js) | ||
## Istanbul Introduction | ||
@@ -396,0 +463,0 @@ - [Istanbul coverage report](https://istanbul.js.org/) - Instrumenting source codes and generating coverage reports |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 7 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
867938
33
6499
458
7
45
12
+ Addedturbogrid@3.2.0(transitive)
- Removedturbogrid@3.0.13(transitive)
Updatedturbogrid@^3.0.13