Comparing version
@@ -7,5 +7,4 @@ #!/usr/bin/env node | ||
const report = require('../lib/report') | ||
const {resolve} = require('path') | ||
const { resolve } = require('path') | ||
const rimraf = require('rimraf') | ||
const sw = require('spawn-wrap') | ||
const { | ||
@@ -16,7 +15,4 @@ hideInstrumenteeArgs, | ||
} = require('../lib/parse-args') | ||
const instrumenterArgs = hideInstrumenteeArgs() | ||
const argv = yargs.parse(instrumenterArgs) | ||
const tmpDirctory = resolve(argv.coverageDirectory, './tmp') | ||
@@ -26,12 +22,13 @@ rimraf.sync(tmpDirctory) | ||
sw([require.resolve('../lib/wrap')], { | ||
C8_ARGV: JSON.stringify(argv) | ||
}) | ||
process.env.NODE_V8_COVERAGE = tmpDirctory | ||
foreground(hideInstrumenterArgs(argv), (out) => { | ||
report({ | ||
include: argv.include, | ||
exclude: argv.exclude, | ||
reporter: Array.isArray(argv.reporter) ? argv.reporter : [argv.reporter], | ||
coverageDirectory: argv.coverageDirectory, | ||
watermarks: argv.watermarks | ||
watermarks: argv.watermarks, | ||
resolve: argv.resolve | ||
}) | ||
}) |
const Exclude = require('test-exclude') | ||
const findUp = require('find-up') | ||
const {readFileSync} = require('fs') | ||
const { readFileSync } = require('fs') | ||
const yargs = require('yargs') | ||
@@ -31,2 +31,6 @@ const parser = require('yargs-parser') | ||
}) | ||
.option('resolve', { | ||
default: '', | ||
describe: 'resolve paths to alternate base directory' | ||
}) | ||
.pkgConf('c8') | ||
@@ -33,0 +37,0 @@ .config(config) |
@@ -0,12 +1,27 @@ | ||
const Exclude = require('test-exclude') | ||
const libCoverage = require('istanbul-lib-coverage') | ||
const libReport = require('istanbul-lib-report') | ||
const reports = require('istanbul-reports') | ||
const {readdirSync, readFileSync} = require('fs') | ||
const {resolve} = require('path') | ||
const { readdirSync, readFileSync } = require('fs') | ||
const { resolve } = require('path') | ||
const v8CoverageMerge = require('v8-coverage-merge') | ||
const v8toIstanbul = require('v8-to-istanbul') | ||
class Report { | ||
constructor ({reporter, coverageDirectory, watermarks}) { | ||
constructor ({ | ||
exclude, | ||
include, | ||
reporter, | ||
coverageDirectory, | ||
watermarks, | ||
resolve | ||
}) { | ||
this.reporter = reporter | ||
this.coverageDirectory = coverageDirectory | ||
this.watermarks = watermarks | ||
this.resolve = resolve | ||
this.exclude = Exclude({ | ||
exclude: exclude, | ||
include: include | ||
}) | ||
} | ||
@@ -28,5 +43,30 @@ run () { | ||
const map = libCoverage.createCoverageMap({}) | ||
const mergedResults = {} | ||
this._loadReports().forEach((report) => { | ||
report.result.forEach((result) => { | ||
if (this.exclude.shouldInstrument(result.url)) { | ||
if (mergedResults[result.url]) { | ||
mergedResults[result.url] = v8CoverageMerge( | ||
mergedResults[result.url], | ||
result | ||
) | ||
} else { | ||
mergedResults[result.url] = result | ||
} | ||
} | ||
}) | ||
}) | ||
this._loadReports().forEach(function (report) { | ||
map.merge(report) | ||
Object.keys(mergedResults).forEach((url) => { | ||
const result = mergedResults[url] | ||
// console.info(JSON.stringify(result, null, 2)) | ||
try { | ||
const path = resolve(this.resolve, result.url) | ||
const script = v8toIstanbul(path) | ||
script.applyCoverage(result.functions) | ||
map.merge(script.toIstanbul()) | ||
} catch (err) { | ||
// most likely this was an internal Node.js library. | ||
if (err.code !== 'ENOENT') throw err | ||
} | ||
}) | ||
@@ -33,0 +73,0 @@ |
{ | ||
"name": "c8", | ||
"version": "3.0.0-alpha.4", | ||
"version": "3.0.0-candidate.0", | ||
"description": "collect test coverage using v8's inspector", | ||
@@ -8,12 +8,6 @@ "main": "index.js", | ||
"scripts": { | ||
"bundle": "bundle-dependencies update", | ||
"test": "nyc mocha ./test/*.js", | ||
"test": "./bin/c8.js --reporter=html --reporter=text mocha ./test/*.js", | ||
"posttest": "standard", | ||
"release": "standard-version" | ||
}, | ||
"c8": { | ||
"exclude": [ | ||
"test/*.js" | ||
] | ||
}, | ||
"standard": { | ||
@@ -32,47 +26,33 @@ "ignore": [ | ||
], | ||
"engines": { | ||
"node": ">=8.8.1" | ||
}, | ||
"author": "Ben Coe <ben@npmjs.com>", | ||
"license": "ISC", | ||
"dependencies": { | ||
"find-up": "^2.1.0", | ||
"find-up": "^3.0.0", | ||
"foreground-child": "^1.5.6", | ||
"istanbul-lib-coverage": "^1.1.1", | ||
"istanbul-lib-report": "^1.1.2", | ||
"istanbul-reports": "^1.1.3", | ||
"istanbul-lib-coverage": "^2.0.1", | ||
"istanbul-lib-report": "^2.0.1", | ||
"istanbul-reports": "^2.0.0", | ||
"mkdirp": "^0.5.1", | ||
"rimraf": "^2.6.2", | ||
"signal-exit": "^3.0.2", | ||
"spawn-wrap": "^1.4.2", | ||
"test-exclude": "^4.1.1", | ||
"uuid": "^3.1.0", | ||
"test-exclude": "^5.0.0", | ||
"uuid": "^3.3.2", | ||
"v8-coverage-merge": "^1.1.2", | ||
"v8-to-istanbul": "^1.2.0", | ||
"yargs": "^10.0.3", | ||
"yargs-parser": "^8.0.0" | ||
"yargs": "^12.0.2", | ||
"yargs-parser": "^10.1.0" | ||
}, | ||
"devDependencies": { | ||
"bundle-dependencies": "^1.0.2", | ||
"chai": "^4.1.2", | ||
"mocha": "^4.0.1", | ||
"nyc": "^11.4.1", | ||
"standard": "^10.0.3", | ||
"standard-version": "^4.2.0" | ||
"mocha": "^5.2.0", | ||
"standard": "^12.0.1", | ||
"standard-version": "^4.4.0" | ||
}, | ||
"bundledDependencies": [ | ||
"find-up", | ||
"foreground-child", | ||
"istanbul-lib-coverage", | ||
"istanbul-lib-report", | ||
"istanbul-reports", | ||
"mkdirp", | ||
"rimraf", | ||
"signal-exit", | ||
"spawn-wrap", | ||
"test-exclude", | ||
"uuid", | ||
"v8-to-istanbul", | ||
"yargs", | ||
"yargs-parser" | ||
"engines": { | ||
"node": ">=10.10.0" | ||
}, | ||
"files": [ | ||
"lib", | ||
"bin", | ||
"LICENSE" | ||
] | ||
} |
@@ -1,4 +0,4 @@ | ||
# c8 - native v8 code-coverage | ||
# c8 - native V8 code-coverage | ||
Code-coverage using [v8's Inspector](https://nodejs.org/dist/latest-v8.x/docs/api/inspector.html) | ||
Code-coverage using [V8's Inspector](https://nodejs.org/dist/latest-v8.x/docs/api/inspector.html) | ||
that's compatible with [Istanbul's reporters](https://istanbul.js.org/docs/advanced/alternative-reporters/). | ||
@@ -13,11 +13,8 @@ | ||
The above example will collect coverage for `foo.js` using v8's inspector. | ||
The above example will collect coverage for `foo.js` using V8's inspector. | ||
## How it Works | ||
## Disclaimer | ||
Before running your application c8 creates [an inspector session](https://nodejs.org/api/inspector.html) in v8, and enables v8's | ||
[built in coverage reporting](https://v8project.blogspot.com/2017/12/javascript-code-coverage.html). | ||
Just before your application exits c8 fetches the coverage information from | ||
v8 and writes it to disk in a format compatible with | ||
[Istanbul's reporters](https://istanbul.js.org/). | ||
c8 uses | ||
[bleeding edge Node.js features](https://github.com/nodejs/node/pull/22527), | ||
make sure you're running Node.js `>= 10.10.0`. |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
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 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
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
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 2 instances 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 21 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
13
-7.14%4
-33.33%0
-100%2
-50%7
-95.36%1
-95%8995
-99.86%7
-99.35%171
-99.82%19
-13.64%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
Updated
Updated
Updated
Updated
Updated
Updated
Updated
Updated