Comparing version 5.1.1 to 5.2.0
@@ -90,2 +90,23 @@ #!/usr/bin/env node | ||
}) | ||
.option('check-coverage', { | ||
type: 'boolean', | ||
default: false, | ||
describe: '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?' | ||
}) | ||
.help('h') | ||
@@ -106,14 +127,3 @@ .alias('h', 'help') | ||
} else if (~argv._.indexOf('check-coverage')) { | ||
foreground( | ||
process.execPath, | ||
[ | ||
require.resolve('istanbul/lib/cli'), | ||
'check-coverage', | ||
'--lines=' + argv.lines, | ||
'--functions=' + argv.functions, | ||
'--branches=' + argv.branches, | ||
'--statements=' + argv.statements, | ||
path.resolve(process.cwd(), './.nyc_output/*.json') | ||
] | ||
) | ||
checkCoverage(argv) | ||
} else if (argv._.length) { | ||
@@ -127,11 +137,21 @@ // wrap subprocesses and execute argv[1] | ||
sw([__filename], { | ||
var env = { | ||
NYC_CWD: process.cwd(), | ||
NYC_REQUIRE: argv.require.join(','), | ||
NYC_CACHE: argv.cache ? 'enable' : 'disable' | ||
}) | ||
} | ||
if (argv.require.length) { | ||
env.NYC_REQUIRE = argv.require.join(',') | ||
} | ||
sw([__filename], env) | ||
foreground(nyc.mungeArgs(argv), function (done) { | ||
if (!argv.silent) report(argv) | ||
return done() | ||
if (argv.checkCoverage) { | ||
checkCoverage(argv, function (done) { | ||
if (!argv.silent) report(argv) | ||
return done() | ||
}) | ||
} else { | ||
if (!argv.silent) report(argv) | ||
return done() | ||
} | ||
}) | ||
@@ -151,1 +171,17 @@ } else { | ||
} | ||
function checkCoverage (argv, cb) { | ||
foreground( | ||
process.execPath, | ||
[ | ||
require.resolve('istanbul/lib/cli'), | ||
'check-coverage', | ||
'--lines=' + argv.lines, | ||
'--functions=' + argv.functions, | ||
'--branches=' + argv.branches, | ||
'--statements=' + argv.statements, | ||
path.resolve(process.cwd(), './.nyc_output/*.json') | ||
], | ||
cb | ||
) | ||
} |
## Change Log | ||
### v5.2.0 (2016/01/02 17:13 -08:00) | ||
- [#126](https://github.com/bcoe/nyc/pull/126) Add --check-coverage shorthand, which fails tests if coverage slips below threshold (@bcoe) | ||
- [#123](https://github.com/bcoe/nyc/pull/123) Upgrade spawn-wrap, foreground-child (@isaacs) | ||
- [#122](https://github.com/bcoe/nyc/pull/122) Use module for finding cache directory (@jamestalmage) | ||
### v5.1.1 (2015/12/30 14:52 -08:00) | ||
@@ -4,0 +10,0 @@ |
27
index.js
@@ -17,2 +17,3 @@ /* global __coverage__ */ | ||
var md5hex = require('md5-hex') | ||
var findCacheDir = require('find-cache-dir') | ||
@@ -30,3 +31,2 @@ /* istanbul ignore next */ | ||
this._tempDirectory = opts.tempDirectory || './.nyc_output' | ||
this._cacheDirectory = opts.cacheDirectory || './node_modules/.cache/nyc' | ||
this.cwd = opts.cwd || process.env.NYC_CWD || process.cwd() | ||
@@ -49,4 +49,6 @@ this.reporter = arrify(opts.reporter || 'text') | ||
this.enableCache = opts.enableCache === true || process.env.NYC_CACHE === 'enable' | ||
this.cacheDirectory = findCacheDir({name: 'nyc', cwd: this.cwd}) | ||
this.enableCache = Boolean(this.cacheDirectory && (opts.enableCache === true || process.env.NYC_CACHE === 'enable')) | ||
// require extensions can be provided as config in package.json. | ||
@@ -76,3 +78,3 @@ this.require = arrify(config.require || opts.require) | ||
factory: this._transformFactory.bind(this), | ||
cacheDir: this.cacheDirectory(), | ||
cacheDir: this.cacheDirectory, | ||
disableCache: !this.enableCache, | ||
@@ -222,3 +224,5 @@ ext: '.js' | ||
NYC.prototype.clearCache = function () { | ||
rimraf.sync(this.cacheDirectory()) | ||
if (this.enableCache) { | ||
rimraf.sync(this.cacheDirectory) | ||
} | ||
} | ||
@@ -300,3 +304,3 @@ | ||
var cacheDir = _this.cacheDirectory() | ||
var cacheDir = _this.cacheDirectory | ||
@@ -343,18 +347,5 @@ var loadedMaps = this.loadedMaps || (this.loadedMaps = {}) | ||
NYC.prototype.cacheDirectory = function () { | ||
return path.resolve(this.cwd, './', this._cacheDirectory) | ||
} | ||
NYC.prototype.mungeArgs = function (yargv) { | ||
var argv = process.argv.slice(1) | ||
argv = argv.slice(argv.indexOf(yargv._[0])) | ||
if (!/^(node|iojs)$/.test(argv[0]) && | ||
process.platform === 'win32' && | ||
(/\.js$/.test(argv[0]) || | ||
(!/\.(cmd|exe)$/.test(argv[0]) && | ||
!fs.existsSync(argv[0] + '.cmd') && | ||
!fs.existsSync(argv[0] + '.exe')))) { | ||
argv.unshift(process.execPath) | ||
} | ||
return argv | ||
@@ -361,0 +352,0 @@ } |
{ | ||
"name": "nyc", | ||
"version": "5.1.1", | ||
"version": "5.2.0", | ||
"description": "a code coverage tool that works well with subprocesses.", | ||
@@ -70,3 +70,4 @@ "main": "index.js", | ||
"convert-source-map": "^1.1.2", | ||
"foreground-child": "^1.3.0", | ||
"find-cache-dir": "^0.1.1", | ||
"foreground-child": "^1.3.3", | ||
"glob": "^6.0.2", | ||
@@ -81,3 +82,3 @@ "istanbul": "^0.4.1", | ||
"source-map": "^0.5.3", | ||
"spawn-wrap": "^1.1.0", | ||
"spawn-wrap": "^1.1.1", | ||
"strip-bom": "^2.0.0", | ||
@@ -101,3 +102,2 @@ "yargs": "^3.15.0" | ||
"tap": "^2.3.4", | ||
"win-spawn": "^2.0.0", | ||
"zero-fill": "^2.2.1" | ||
@@ -104,0 +104,0 @@ }, |
34799
15
605
18
+ Addedfind-cache-dir@^0.1.1
+ Addedcommondir@1.0.1(transitive)
+ Addedfind-cache-dir@0.1.1(transitive)
+ Addedfind-up@1.1.2(transitive)
+ Addedpath-exists@2.1.0(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedpkg-dir@1.0.0(transitive)
Updatedforeground-child@^1.3.3
Updatedspawn-wrap@^1.1.1