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.3.0-candidate.3 to 3.3.0

lib/commands/check-coverage.js

45

bin/c8.js

@@ -5,46 +5,33 @@ #!/usr/bin/env node

const fs = require('fs')
const util = require('util')
const foreground = require('foreground-child')
const report = require('../lib/report')
const { outputReport } = require('../lib/commands/report')
const { checkCoverages } = require('../lib/commands/check-coverage')
const { promisify } = require('util')
const rimraf = require('rimraf')
const {
buildYargs,
hideInstrumenteeArgs,
hideInstrumenterArgs,
yargs
hideInstrumenterArgs
} = require('../lib/parse-args')
const instrumenterArgs = hideInstrumenteeArgs()
let argv = yargs.parse(instrumenterArgs)
let argv = buildYargs().parse(instrumenterArgs)
const _p = util.promisify
function outputReport () {
report({
include: argv.include,
exclude: argv.exclude,
reporter: Array.isArray(argv.reporter) ? argv.reporter : [argv.reporter],
tempDirectory: argv.tempDirectory,
watermarks: argv.watermarks,
resolve: argv.resolve,
omitRelative: argv.omitRelative,
wrapperLength: argv.wrapperLength
})
}
(async function run () {
if (argv._[0] === 'report') {
argv = yargs.parse(process.argv) // support flag arguments after "report".
outputReport()
;(async function run () {
if ([
'check-coverage', 'report'
].indexOf(argv._[0]) !== -1) {
argv = buildYargs(true).parse(process.argv.slice(2))
} else {
if (argv.clean) {
await _p(rimraf)(argv.tempDirectory)
await _p(fs.mkdir)(argv.tempDirectory, { recursive: true })
await promisify(rimraf)(argv.tempDirectory)
await promisify(fs.mkdir)(argv.tempDirectory, { recursive: true })
}
process.env.NODE_V8_COVERAGE = argv.tempDirectory
foreground(hideInstrumenterArgs(argv), () => {
outputReport()
const report = outputReport(argv)
if (argv.checkCoverage) checkCoverages(argv, report)
})
}
})()

@@ -5,2 +5,20 @@ # Change Log

<a name="3.3.0"></a>
# [3.3.0](https://github.com/bcoe/c8/compare/v3.2.1...v3.3.0) (2019-01-23)
### Bug Fixes
* file URL to system path conversion ([#46](https://github.com/bcoe/c8/issues/46)) ([e7f8cf2](https://github.com/bcoe/c8/commit/e7f8cf2))
* float patch for branch/function coverage merge bug ([#56](https://github.com/bcoe/c8/issues/56)) ([1de0cca](https://github.com/bcoe/c8/commit/1de0cca))
* snapshot ([7fd9e13](https://github.com/bcoe/c8/commit/7fd9e13))
### Features
* add thresholds for enforcing coverage percentage ([#59](https://github.com/bcoe/c8/issues/59)) ([70e8943](https://github.com/bcoe/c8/commit/70e8943))
* allow script wrapper length to be specified ([#51](https://github.com/bcoe/c8/issues/51)) ([a22c4e0](https://github.com/bcoe/c8/commit/a22c4e0))
<a name="3.2.1"></a>

@@ -7,0 +25,0 @@ ## [3.2.1](https://github.com/bcoe/c8/compare/v3.2.0...v3.2.1) (2018-10-21)

const Exclude = require('test-exclude')
const findUp = require('find-up')
const { readFileSync } = require('fs')
const yargs = require('yargs')
const Yargs = require('yargs/yargs')
const parser = require('yargs-parser')

@@ -10,47 +10,85 @@

yargs()
.usage('$0 [opts] [script] [opts]')
.option('reporter', {
alias: 'r',
describe: 'coverage reporter(s) to use',
default: 'text'
})
.option('exclude', {
alias: 'x',
default: Exclude.defaultExclude,
describe: 'a list of specific files and directories that should be excluded from coverage (glob patterns are supported)'
})
.option('include', {
alias: 'n',
default: [],
describe: 'a list of specific files that should be covered (glob patterns are supported)'
})
.option('temp-directory', {
default: './coverage/tmp',
describe: 'directory V8 coverage data is written to and read from'
})
.option('resolve', {
default: '',
describe: 'resolve paths to alternate base directory'
})
.option('wrapper-length', {
describe: 'how many bytes is the wrapper prefix on executed JavaScript',
type: 'number'
})
.option('omit-relative', {
default: true,
type: 'boolean',
describe: 'omit any paths that are not absolute, e.g., internal/net.js'
})
.option('clean', {
default: true,
type: 'boolean',
describe: 'should temp files be deleted before script execution'
})
.command('report', 'read V8 coverage data from temp and output report')
.pkgConf('c8')
.config(config)
.demandCommand(1)
.epilog('visit https://git.io/vHysA for list of available reporters')
function buildYargs (withCommands = false) {
const yargs = Yargs([])
.usage('$0 [opts] [script] [opts]')
.option('reporter', {
alias: 'r',
describe: 'coverage reporter(s) to use',
default: 'text'
})
.option('exclude', {
alias: 'x',
default: Exclude.defaultExclude,
describe: 'a list of specific files and directories that should be excluded from coverage (glob patterns are supported)'
})
.option('include', {
alias: 'n',
default: [],
describe: 'a list of specific files that should be covered (glob patterns are supported)'
})
.option('check-coverage', {
default: false,
type: 'boolean',
description: 'check whether coverage is within thresholds provided'
})
.option('branches', {
default: 0,
description: 'what % of branches must be covered?'
})
.option('functions', {
default: 0,
description: 'what % of functions must be covered?'
})
.option('lines', {
default: 90,
description: 'what % of lines must be covered?'
})
.option('statements', {
default: 0,
description: 'what % of statements must be covered?'
})
.option('per-file', {
default: false,
description: 'check thresholds per file'
})
.option('temp-directory', {
default: './coverage/tmp',
describe: 'directory V8 coverage data is written to and read from'
})
.option('resolve', {
default: '',
describe: 'resolve paths to alternate base directory'
})
.option('wrapper-length', {
describe: 'how many bytes is the wrapper prefix on executed JavaScript',
type: 'number'
})
.option('omit-relative', {
default: true,
type: 'boolean',
describe: 'omit any paths that are not absolute, e.g., internal/net.js'
})
.option('clean', {
default: true,
type: 'boolean',
describe: 'should temp files be deleted before script execution'
})
.pkgConf('c8')
.config(config)
.demandCommand(1)
.epilog('visit https://git.io/vHysA for list of available reporters')
const checkCoverage = require('./commands/check-coverage')
const report = require('./commands/report')
if (withCommands) {
yargs.command(checkCoverage)
yargs.command(report)
} else {
yargs.command(checkCoverage.command, checkCoverage.describe)
yargs.command(report.command, report.describe)
}
return yargs
}
function hideInstrumenterArgs (yargv) {

@@ -80,5 +118,5 @@ var argv = process.argv.slice(1)

module.exports = {
yargs,
buildYargs,
hideInstrumenterArgs,
hideInstrumenteeArgs
}

@@ -35,3 +35,3 @@ const Exclude = require('test-exclude')

run () {
const map = this._getCoverageMapFromAllCoverageFiles()
const map = this.getCoverageMapFromAllCoverageFiles()
var context = libReport.createContext({

@@ -49,3 +49,9 @@ dir: './coverage',

_getCoverageMapFromAllCoverageFiles () {
getCoverageMapFromAllCoverageFiles () {
// the merge process can be very expensive, and it's often the case that
// check-coverage is called immediately after a report. We memoize the
// result from getCoverageMapFromAllCoverageFiles() to address this
// use-case.
if (this._allCoverageFiles) return this._allCoverageFiles
const v8ProcessCov = this._getMergedProcessCov()

@@ -66,3 +72,4 @@

return map
this._allCoverageFiles = map
return this._allCoverageFiles
}

@@ -144,4 +151,3 @@

module.exports = function (opts) {
const report = new Report(opts)
report.run()
return new Report(opts)
}
{
"name": "c8",
"version": "3.3.0-candidate.3",
"version": "3.3.0",
"description": "output coverage reports using Node.js' built in coverage",

@@ -12,3 +12,3 @@ "main": "index.js",

"scripts": {
"test": "node ./bin/c8.js --reporter=html --reporter=text mocha ./test/*.js",
"test": "node ./bin/c8.js --reporter=html --reporter=text mocha --timeout=4000 ./test/*.js",
"test:snap": "CHAI_JEST_SNAPSHOT_UPDATE_ALL=true npm test",

@@ -46,4 +46,4 @@ "posttest": "standard",

"uuid": "^3.3.2",
"v8-to-istanbul": "^2.0.1",
"yargs": "^12.0.2",
"v8-to-istanbul": "^2.0.2",
"yargs": "^12.0.5",
"yargs-parser": "^10.1.0"

@@ -50,0 +50,0 @@ },

@@ -7,3 +7,3 @@ # c8 - native V8 code-coverage

Code-coverage using [Node.js' build in functionality](https://nodejs.org/dist/latest-v10.x/docs/api/cli.html#cli_node_v8_coverage_dir)
Code-coverage using [Node.js' built in functionality](https://nodejs.org/dist/latest-v10.x/docs/api/cli.html#cli_node_v8_coverage_dir)
that's compatible with [Istanbul's reporters](https://istanbul.js.org/docs/advanced/alternative-reporters/).

@@ -24,2 +24,26 @@

## Checking coverage
c8 can fail tests if coverage falls below a threshold.
After running your tests with c8, simply run:
```shell
c8 check-coverage --lines 95 --functions 95 --branches 95
```
c8 also accepts a `--check-coverage` shorthand, which can be used to
both run tests and check that coverage falls within the threshold provided:
```shell
c8 --check-coverage --lines 100 npm test
```
The above check fails if coverage falls below 100%.
To check thresholds on a per-file basis run:
```shell
c8 check-coverage --lines 95 --per-file
```
## Supported Node.js Versions

@@ -26,0 +50,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