monocart-coverage-reports
Advanced tools
Comparing version 2.3.1 to 2.3.2
@@ -19,8 +19,3 @@ #!/usr/bin/env node | ||
const cleanDir = (dir) => { | ||
if (fs.existsSync(dir)) { | ||
fs.rmSync(dir, { | ||
recursive: true, | ||
force: true | ||
}); | ||
} | ||
Util.rmSync(dir); | ||
}; | ||
@@ -131,2 +126,3 @@ | ||
.option('-n, --name <name>', 'report name for title') | ||
.option('-i, --inputDir <dir>', 'input dir for merging raw files') | ||
@@ -133,0 +129,0 @@ .option('--outputFile <path>', 'output file for v8 report') |
@@ -46,3 +46,3 @@ const { | ||
}; | ||
createBranches(ast, rootFunctionInfo, branchMap); | ||
createBranches(rootFunctionInfo, branchMap, ast); | ||
} | ||
@@ -67,3 +67,3 @@ | ||
// Function include FunctionDeclaration, ArrowFunctionExpression, FunctionExpression | ||
Function(node) { | ||
Function(node, parents) { | ||
@@ -99,3 +99,3 @@ const { | ||
createBranches(node.body, functionInfo, branchMap); | ||
createBranches(functionInfo, branchMap, node.body, node.params, parents); | ||
@@ -102,0 +102,0 @@ } |
@@ -149,9 +149,27 @@ const Util = require('../utils/util.js'); | ||
const createBranches = (ast, functionInfo, branchMap) => { | ||
const addAssignmentPattern = (params, parents, functionInfo, branchMap, locationMap) => { | ||
if (!Util.isList(params)) { | ||
return; | ||
} | ||
params.forEach((param) => { | ||
if (param.type !== 'AssignmentPattern') { | ||
return; | ||
} | ||
const start = param.start; | ||
const group = createBranchGroup('AssignmentPattern', start, parents, branchMap, functionInfo); | ||
addBranch(group, param, locationMap, functionInfo); | ||
}); | ||
}; | ||
const createBranches = (functionInfo, branchMap, body, params, functionParents = []) => { | ||
// locationMap for chain LogicalExpression locations | ||
const locationMap = new Map(); | ||
Util.visitAst(ast, { | ||
// function's arguments | ||
addAssignmentPattern(params, functionParents, functionInfo, branchMap, locationMap); | ||
Util.visitAst(body, { | ||
Function() { | ||
@@ -199,3 +217,3 @@ return 'break'; | ||
// var b = a || b || c; | ||
// do not using BinaryExpression | ||
// do not use BinaryExpression | ||
LogicalExpression: (node, parents) => { | ||
@@ -250,6 +268,2 @@ addNodeCount(node, parents, functionInfo); | ||
// default-arg - seems that V8 coverage do NOT supported | ||
// (a = 0) => {} | ||
// AssignmentPattern: (node) => {} | ||
}); | ||
@@ -373,3 +387,6 @@ | ||
handlers[type](group, parentCount, noBlockList, blockCount); | ||
const handler = handlers[type]; | ||
if (handler) { | ||
handler(group, parentCount, noBlockList, blockCount); | ||
} | ||
@@ -376,0 +393,0 @@ }; |
const fs = require('fs'); | ||
const EC = require('eight-colors'); | ||
const { fileURLToPath } = require('url'); | ||
const { fileURLToPath, pathToFileURL } = require('url'); | ||
const Concurrency = require('../platform/concurrency.js'); | ||
@@ -24,3 +24,3 @@ const { convertSourceMap, axios } = require('../packages/monocart-coverage-vendor.js'); | ||
if (url.startsWith('file://')) { | ||
if (url.startsWith('file:')) { | ||
const p = fileURLToPath(url); | ||
@@ -59,2 +59,6 @@ const content = Util.readFileSync(p); | ||
if (!URL.canParse(filename, url)) { | ||
url = pathToFileURL(url).toString(); | ||
} | ||
let mapUrl; | ||
@@ -61,0 +65,0 @@ |
@@ -55,3 +55,3 @@ const fs = require('fs'); | ||
// values can be nested/flat/pkg. Defaults to 'pkg' | ||
defaultSummarizer: options.defaultSummarizer || 'pkg', | ||
defaultSummarizer: options.defaultSummarizer || 'nested', | ||
@@ -58,0 +58,0 @@ dir: options.outputDir, |
@@ -42,4 +42,4 @@ const path = require('path'); | ||
// url could be a absolute path | ||
if (path.isAbsolute(url)) { | ||
// url could be a path | ||
if (!URL.canParse(url)) { | ||
url = pathToFileURL(url).toString(); | ||
@@ -46,0 +46,0 @@ } |
@@ -380,7 +380,13 @@ const fs = require('fs'); | ||
rmSync: (p) => { | ||
if (fs.existsSync(p)) { | ||
if (!fs.existsSync(p)) { | ||
return; | ||
} | ||
try { | ||
fs.rmSync(p, { | ||
recursive: true, | ||
force: true | ||
force: true, | ||
maxRetries: 10 | ||
}); | ||
} catch (err) { | ||
console.log(err.message); | ||
} | ||
@@ -387,0 +393,0 @@ }, |
{ | ||
"name": "monocart-coverage-reports", | ||
"version": "2.3.1", | ||
"version": "2.3.2", | ||
"description": "Monocart coverage reports", | ||
@@ -24,3 +24,3 @@ "main": "./lib/index.js", | ||
"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 && npm run test-vm", | ||
"test-node-env": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-env node ./test/test-node-env.js && node ./test/generate-node-report.js", | ||
"test-node-env": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-env node ./test/test-node-env.js && node ./test/generate-report.js", | ||
"test-node-api": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-api node ./test/test-node-api.js", | ||
@@ -32,6 +32,11 @@ "test-node-fgc": "node ./test/test-node-fgc.js", | ||
"test-vm": "node ./test/test-vm.js", | ||
"test-browser": "node ./test/test.js", | ||
"test-istanbul": "node ./test/test-istanbul.js", | ||
"test-v8": "node ./test/test-v8.js", | ||
"test-browser": "node ./test/test.js && npm run test-istanbul && npm run test-v8 && npm run test-anonymous && npm run test-css", | ||
"test-anonymous": "node ./test/test-anonymous.js", | ||
"test-css": "node ./test/test-css.js", | ||
"test-cli": "npx mcr \"node ./test/test-node-env.js\" -o docs/cli -c test/cli-options.js", | ||
"test-merge": "node ./test/test-merge.js", | ||
"test": "npm run test-browser && npm run test-node && npm run test-cli && npm run test-merge && npm run build-docs", | ||
"test-all": "npm run test-browser && npm run test-node && npm run test-cli && npm run test-merge && npm run build-docs", | ||
"test": "npx mcr \"npm run test-all\" -c test/mcr-options.js", | ||
"dev": "sf d v8", | ||
@@ -38,0 +43,0 @@ "open": "node ./scripts/open.js", |
@@ -26,3 +26,2 @@ # Monocart Coverage Reports | ||
* [Merge Coverage Reports](#merge-coverage-reports) | ||
* [Integration](#integration) | ||
* [Ignoring Uncovered Codes](#ignoring-uncovered-codes) | ||
@@ -34,2 +33,3 @@ * [Chromium Coverage API](#chromium-coverage-api) | ||
- [How Monocart Works](#how-monocart-works) | ||
* [Integration](#integration) - Playwright, Jest, Vitest, Codecov, Coveralls, Sonar Cloud | ||
* [Istanbul Introduction](#istanbul-introduction) | ||
@@ -347,3 +347,3 @@ * [Thanks](#thanks) | ||
- Example: | ||
> cross-env NODE_V8_COVERAGE=`.temp/v8-coverage-env` node [./test/test-node-env.js](./test/test-node-env.js) && node [./test/generate-node-report.js](./test/generate-node-report.js) | ||
> cross-env NODE_V8_COVERAGE=`.temp/v8-coverage-env` node [./test/test-node-env.js](./test/test-node-env.js) && node [./test/generate-report.js](./test/generate-report.js) | ||
@@ -466,7 +466,2 @@ - [V8](https://nodejs.org/docs/latest/api/v8.html#v8takecoverage) API + NODE_V8_COVERAGE | ||
## Integration | ||
- [monocart-reporter](https://cenfun.github.io/monocart-reporter/) - Test reporter for [Playwright](https://github.com/microsoft/playwright) | ||
- [jest-monocart-coverage](https://github.com/cenfun/jest-monocart-coverage) - Integration with [Jest](https://github.com/jestjs/jest/) for coverage reports | ||
- [vitest-monocart-coverage](https://github.com/cenfun/vitest-monocart-coverage) - Integration with [Vitest](https://github.com/vitest-dev/vitest) for coverage reports | ||
## Ignoring Uncovered Codes | ||
@@ -589,2 +584,54 @@ To ignore codes, use the special comment which starts with `v8 ignore `: | ||
## Integration | ||
- [monocart-reporter](https://github.com/cenfun/monocart-reporter) - A [Playwright](https://github.com/microsoft/playwright) custom reporter, supports generating [Code Coverage Report](https://github.com/cenfun/monocart-reporter?#code-coverage-report) | ||
- [jest-monocart-coverage](https://github.com/cenfun/jest-monocart-coverage) - A [Jest](https://github.com/jestjs/jest/) custom reporter for coverage reports | ||
- [vitest-monocart-coverage](https://github.com/cenfun/vitest-monocart-coverage) - A [Vitest](https://github.com/vitest-dev/vitest) custom provider module for coverage reports | ||
- [Codecov](https://codecov.com/) | ||
- [![codecov](https://codecov.io/gh/cenfun/monocart-coverage-reports/graph/badge.svg?token=H0LW7UKYU3)](https://codecov.io/gh/cenfun/monocart-coverage-reports) | ||
- Supports native `codecov` built-in report ([specification](https://docs.codecov.com/docs/codecov-custom-coverage-format)) | ||
```js | ||
const coverageOptions = { | ||
outputDir: "./coverage-reports", | ||
reports: [ | ||
['codecov'] | ||
] | ||
}; | ||
``` | ||
- Github Actions example: | ||
```yml | ||
- name: Codecov | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
files: ./coverage-reports/codecov.json | ||
``` | ||
- [Coveralls](https://coveralls.io/) | ||
- [![Coverage Status](https://coveralls.io/repos/github/cenfun/monocart-coverage-reports/badge.svg?branch=main)](https://coveralls.io/github/cenfun/monocart-coverage-reports?branch=main) | ||
- Github Actions example: | ||
```yml | ||
- name: Coveralls | ||
uses: coverallsapp/github-action@v2 | ||
with: | ||
files: ./coverage-reports/lcov.info | ||
``` | ||
- [Sonar Cloud](https://sonarcloud.io/) | ||
- [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=monocart-coverage-reports&metric=coverage)](https://sonarcloud.io/summary/new_code?id=monocart-coverage-reports) | ||
- Github Actions example: | ||
```yml | ||
- name: Analyze with SonarCloud | ||
uses: sonarsource/sonarcloud-github-action@master | ||
env: | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
with: | ||
projectBaseDir: ./ | ||
args: > | ||
-Dsonar.organization=cenfun | ||
-Dsonar.projectKey=monocart-coverage-reports | ||
-Dsonar.projectName=monocart-coverage-reports | ||
-Dsonar.javascript.lcov.reportPaths=docs/mcr/lcov.info | ||
-Dsonar.sources=lib | ||
-Dsonar.tests=test | ||
-Dsonar.exclusions=dist/*,packages/* | ||
``` | ||
## Istanbul Introduction | ||
@@ -591,0 +638,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
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
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
894599
6945
639
238394