Comparing version 2.3.0 to 2.4.0
#!/usr/bin/env node | ||
var foreground = require('foreground-child'), | ||
sw = require('spawn-wrap') | ||
var foreground = require('foreground-child') | ||
var path = require('path') | ||
var sw = require('spawn-wrap') | ||
@@ -16,26 +17,49 @@ if (process.env.NYC_CWD) { | ||
} else { | ||
var NYC = require('../'), | ||
yargs = require('yargs') | ||
.usage('$0 [command] [options]\n\nrun with a file as the first argument, to instrument it with coverage') | ||
.command('report', 'run coverage report for .nyc_output', function (yargs) { | ||
yargs | ||
.option('r', { | ||
alias: 'reporter', | ||
describe: 'coverage reporter(s) to use', | ||
default: 'text', | ||
array: true | ||
}) | ||
.help('h') | ||
.example('$0 report --reporter=lcov', 'output an HTML lcov report to ./coverage') | ||
.alias('h', 'help') | ||
}) | ||
.help('h') | ||
.alias('h', 'help') | ||
.version(require('../package.json').version) | ||
.example('$0 npm test', 'instrument your tests with coverage') | ||
.example('$0 report --reporter=text-lcov', 'output lcov report after running your tests') | ||
.epilog('visit http://git.io/vTJJB for list of available reporters'), | ||
argv = yargs.argv | ||
var NYC = require('../') | ||
var yargs = require('yargs') | ||
.usage('$0 [command] [options]\n\nrun your tests with the nyc bin to instrument them with coverage') | ||
.command('report', 'run coverage report for .nyc_output', function (yargs) { | ||
yargs | ||
.usage('$0 report [options]') | ||
.option('r', { | ||
alias: 'reporter', | ||
describe: 'coverage reporter(s) to use', | ||
default: 'text', | ||
array: true | ||
}) | ||
.help('h') | ||
.alias('h', 'help') | ||
.example('$0 report --reporter=lcov', 'output an HTML lcov report to ./coverage') | ||
}) | ||
.command('check-coverage', 'check whether coverage is within thresholds provided', function (yargs) { | ||
yargs | ||
.usage('$0 check-coverage [options]') | ||
.option('b', { | ||
alias: 'branches', | ||
default: 0, | ||
description: 'what % of branches must be covered?' | ||
}) | ||
.option('f', { | ||
alias: 'functions', | ||
default: 0, | ||
description: 'what % of functions must be covered?' | ||
}) | ||
.option('l', { | ||
alias: 'lines', | ||
default: 90, | ||
description: 'what % of lines must be covered?' | ||
}) | ||
.help('h') | ||
.alias('h', 'help') | ||
.example('$0 check-coverage --lines 95', "check whether the JSON in nyc's output folder meets the thresholds provided") | ||
}) | ||
.help('h') | ||
.alias('h', 'help') | ||
.version(require('../package.json').version) | ||
.example('$0 npm test', 'instrument your tests with coverage') | ||
.example('$0 report --reporter=text-lcov', 'output lcov report after running your tests') | ||
.epilog('visit http://git.io/vTJJB for list of available reporters') | ||
var argv = yargs.argv | ||
if (argv._.length && ~argv._.indexOf('report')) { | ||
if (~argv._.indexOf('report')) { | ||
// run a report. | ||
@@ -47,2 +71,13 @@ process.env.NYC_CWD = process.cwd() | ||
})).report() | ||
} else if (~argv._.indexOf('check-coverage')) { | ||
foreground( | ||
path.resolve(__dirname, '../node_modules/.bin/istanbul'), | ||
[ | ||
'check-coverage', | ||
'--lines=' + argv.lines, | ||
'--functions=' + argv.functions, | ||
'--branches=' + argv.branches, | ||
path.resolve(process.cwd(), './.nyc_output/*.json') | ||
] | ||
) | ||
} else if (argv._.length) { | ||
@@ -49,0 +84,0 @@ // wrap subprocesses and execute argv[1] |
## Change Log | ||
### v2.4.0 (2015/06/24 15:57 +00:00) | ||
- [#30](https://github.com/bcoe/nyc/pull/30) Added check-coverage functionality, thanks | ||
@Raynos! (@bcoe) | ||
### v2.3.0 (2015/06/04 06:43 +00:00) | ||
- [#27](https://github.com/bcoe/nyc/pull/27) upgraded tap, and switched tests to using tap --coverage (@bcoe) | ||
- [#25](https://github.com/bcoe/nyc/pull/25) support added for multiple reporters, thanks @jasisk! (@jasisk) | ||
### v2.2.0 (2015/05/25 21:05 +00:00) | ||
@@ -4,0 +12,0 @@ - [b2e4707](https://github.com/bcoe/nyc/commit/b2e4707ca16750fe274f61039baf1cabdd6b0149) change location of nyc_output to .nyc_output. Added note about coveralls comments. (@sindresorhus) |
45
index.js
/* global __coverage__ */ | ||
var _ = require('lodash') | ||
var fs = require('fs') | ||
var mkdirp = require('mkdirp') | ||
var path = require('path') | ||
var rimraf = require('rimraf') | ||
var onExit = require('signal-exit') | ||
var stripBom = require('strip-bom') | ||
var _ = require('lodash'), | ||
fs = require('fs'), | ||
mkdirp = require('mkdirp'), | ||
path = require('path'), | ||
rimraf = require('rimraf'), | ||
onExit = require('signal-exit'), | ||
stripBom = require('strip-bom') | ||
function NYC (opts) { | ||
@@ -82,14 +81,14 @@ _.extend(this, { | ||
NYC.prototype._wrapExit = function () { | ||
var _this = this, | ||
outputCoverage = function () { | ||
var coverage = global.__coverage__ | ||
if (typeof __coverage__ === 'object') coverage = __coverage__ | ||
if (!coverage) return | ||
var _this = this | ||
var outputCoverage = function () { | ||
var coverage = global.__coverage__ | ||
if (typeof __coverage__ === 'object') coverage = __coverage__ | ||
if (!coverage) return | ||
fs.writeFileSync( | ||
path.resolve(_this.tmpDirectory(), './', process.pid + '.json'), | ||
JSON.stringify(coverage), | ||
'utf-8' | ||
) | ||
} | ||
fs.writeFileSync( | ||
path.resolve(_this.tmpDirectory(), './', process.pid + '.json'), | ||
JSON.stringify(coverage), | ||
'utf-8' | ||
) | ||
} | ||
@@ -110,4 +109,4 @@ // we always want to write coverage | ||
NYC.prototype.report = function (_collector, _reporter) { | ||
var collector = _collector || new this.istanbul.Collector(), | ||
reporter = _reporter || new this.istanbul.Reporter() | ||
var collector = _collector || new this.istanbul.Collector() | ||
var reporter = _reporter || new this.istanbul.Reporter() | ||
@@ -126,4 +125,4 @@ this._loadReports().forEach(function (report) { | ||
NYC.prototype._loadReports = function () { | ||
var _this = this, | ||
files = fs.readdirSync(this.tmpDirectory()) | ||
var _this = this | ||
var files = fs.readdirSync(this.tmpDirectory()) | ||
@@ -130,0 +129,0 @@ return _.map(files, function (f) { |
{ | ||
"name": "nyc", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "a code coverage tool that works well with subprocesses.", | ||
@@ -39,16 +39,16 @@ "main": "index.js", | ||
"foreground-child": "^1.2.0", | ||
"istanbul": "^0.3.14", | ||
"istanbul": "^0.3.16", | ||
"lodash": "^3.8.0", | ||
"mkdirp": "^0.5.0", | ||
"rimraf": "^2.3.3", | ||
"rimraf": "^2.4.0", | ||
"signal-exit": "^2.1.1", | ||
"spawn-wrap": "^1.0.1", | ||
"strip-bom": "^1.0.0", | ||
"yargs": "^3.8.0" | ||
"yargs": "^3.12.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.0.0", | ||
"sinon": "^1.14.1", | ||
"standard": "^4.0.1", | ||
"tap": "^1.2.0" | ||
"sinon": "^1.15.3", | ||
"standard": "^4.3.2", | ||
"tap": "^1.3.0" | ||
}, | ||
@@ -55,0 +55,0 @@ "repository": { |
@@ -7,4 +7,8 @@ # nyc | ||
```shell | ||
nyc npm test | ||
``` | ||
a code coverage tool built on [istanbul](https://www.npmjs.com/package/istanbul) | ||
that works well for applications that spawn subprocesses. | ||
that works for applications that spawn subprocesses. | ||
@@ -30,2 +34,13 @@ ## Instrumenting Your Code | ||
## Checking Coverage | ||
nyc exposes istanbul's check-coverage tool. After running your tests with nyc, | ||
simply run: | ||
```shell | ||
nyc check-coverage --lines 95 --functions 95 --branches 95 | ||
``` | ||
This feature makes it easy to fail your tests if coverage drops below a given threshold. | ||
## Running Reports | ||
@@ -32,0 +47,0 @@ |
/* global describe, it */ | ||
var _ = require('lodash'), | ||
fs = require('fs'), | ||
NYC = require('../'), | ||
path = require('path'), | ||
rimraf = require('rimraf'), | ||
sinon = require('sinon'), | ||
spawn = require('child_process').spawn | ||
var _ = require('lodash') | ||
var fs = require('fs') | ||
var NYC = require('../') | ||
var path = require('path') | ||
var rimraf = require('rimraf') | ||
var sinon = require('sinon') | ||
var spawn = require('child_process').spawn | ||
@@ -97,10 +97,10 @@ require('chai').should() | ||
var nyc = new NYC({ | ||
cwd: process.cwd() | ||
}), | ||
proc = spawn(process.execPath, ['./test/fixtures/sigint.js'], { | ||
cwd: process.cwd(), | ||
env: process.env, | ||
stdio: 'inherit' | ||
}), | ||
start = fs.readdirSync(nyc.tmpDirectory()).length | ||
cwd: process.cwd() | ||
}) | ||
var proc = spawn(process.execPath, ['./test/fixtures/sigint.js'], { | ||
cwd: process.cwd(), | ||
env: process.env, | ||
stdio: 'inherit' | ||
}) | ||
var start = fs.readdirSync(nyc.tmpDirectory()).length | ||
@@ -134,9 +134,9 @@ proc.on('close', function () { | ||
var nyc = new NYC({ | ||
cwd: process.cwd() | ||
}), | ||
proc = spawn(process.execPath, ['./test/fixtures/sigint.js'], { | ||
cwd: process.cwd(), | ||
env: process.env, | ||
stdio: 'inherit' | ||
}) | ||
cwd: process.cwd() | ||
}) | ||
var proc = spawn(process.execPath, ['./test/fixtures/sigint.js'], { | ||
cwd: process.cwd(), | ||
env: process.env, | ||
stdio: 'inherit' | ||
}) | ||
@@ -162,9 +162,9 @@ fs.writeFileSync('./.nyc_output/bad.json', '}', 'utf-8') | ||
it('handles multiple reporters', function (done) { | ||
var reporters = ['text-summary', 'text-lcov'], | ||
incr = 0, | ||
nyc = new NYC({ | ||
var reporters = ['text-summary', 'text-lcov'] | ||
var incr = 0 | ||
var nyc = new NYC({ | ||
cwd: process.cwd(), | ||
reporter: reporters | ||
}), | ||
proc = spawn(process.execPath, ['./test/fixtures/sigint.js'], { | ||
}) | ||
var proc = spawn(process.execPath, ['./test/fixtures/sigint.js'], { | ||
cwd: process.cwd(), | ||
@@ -171,0 +171,0 @@ env: process.env, |
24373
420
139
Updatedistanbul@^0.3.16
Updatedrimraf@^2.4.0
Updatedyargs@^3.12.0