Socket
Socket
Sign inDemoInstall

c8

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

c8 - npm Package Compare versions

Comparing version 3.0.0-alpha.4 to 3.0.0-candidate.0

15

bin/c8.js

@@ -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
})
})

6

lib/parse-args.js
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`.
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