-
-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: adds instrument command line option #298
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,23 +16,47 @@ var yargs = require('yargs/yargs')(process.argv.slice(2)) | |
.command('report', 'run coverage report for .nyc_output', function (yargs) { | ||
return yargs | ||
.usage('$0 report [options]') | ||
.option('reporter', { | ||
alias: 'r', | ||
describe: 'coverage reporter(s) to use', | ||
default: 'text' | ||
}) | ||
.option('report-dir', { | ||
describe: 'default directory to output coverage reports in', | ||
default: 'coverage' | ||
}) | ||
.example('$0 report --reporter=lcov', 'output an HTML lcov report to ./coverage') | ||
}) | ||
.command('check-coverage', 'check whether coverage is within thresholds provided', function (yargs) { | ||
return yargs | ||
.usage('$0 check-coverage [options]') | ||
.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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. Is there a reason this is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just picking defaults based on personal preference, I tend to find a project with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. Maybe I'm misunderstanding what these numbers mean, but shouldn't that be true of the other thresholds as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you're right, just not as experienced with the other thresholds. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, me either. I only think that I sort of understand what they really mean, but I'm not certain... |
||
description: 'what % of lines must be covered?' | ||
}) | ||
.option('statements', { | ||
default: 0, | ||
description: 'what % of statements must be covered?' | ||
}) | ||
.example('$0 check-coverage --lines 95', "check whether the JSON in nyc's output folder meets the thresholds provided") | ||
}) | ||
.command(require('../lib/commands/instrument')) | ||
.option('reporter', { | ||
alias: 'r', | ||
describe: 'coverage reporter(s) to use', | ||
default: 'text', | ||
global: true | ||
default: 'text' | ||
}) | ||
.option('report-dir', { | ||
describe: 'default directory to output coverage reports in', | ||
default: 'coverage', | ||
global: true | ||
default: 'coverage' | ||
}) | ||
.option('silent', { | ||
alias: 's', | ||
|
@@ -67,7 +91,7 @@ var yargs = require('yargs/yargs')(process.argv.slice(2)) | |
type: 'boolean', | ||
describe: 'cache instrumentation results for improved performance' | ||
}) | ||
.options('extension', { | ||
.option('extension', { | ||
alias: 'e', | ||
default: [], | ||
describe: 'a list of extensions that nyc should handle in addition to .js' | ||
|
@@ -79,23 +103,19 @@ var yargs = require('yargs/yargs')(process.argv.slice(2)) | |
}) | ||
.option('branches', { | ||
default: 0, | ||
description: 'what % of branches must be covered?', | ||
global: true | ||
description: 'what % of branches must be covered?' | ||
}) | ||
.option('functions', { | ||
default: 0, | ||
description: 'what % of functions must be covered?', | ||
global: true | ||
description: 'what % of functions must be covered?' | ||
}) | ||
.option('lines', { | ||
default: 90, | ||
description: 'what % of lines must be covered?', | ||
global: true | ||
description: 'what % of lines must be covered?' | ||
}) | ||
.option('statements', { | ||
default: 0, | ||
description: 'what % of statements must be covered?', | ||
global: true | ||
description: 'what % of statements must be covered?' | ||
}) | ||
.option('source-map', { | ||
default: true, | ||
|
@@ -112,7 +132,7 @@ var yargs = require('yargs/yargs')(process.argv.slice(2)) | |
.version() | ||
.pkgConf('nyc', process.cwd()) | ||
.example('$0 npm test', 'instrument your tests with coverage') | ||
.example('$0 --require --require babel-core/register npm test', 'instrument your tests with coverage and babel') | ||
.example('$0 --require babel-core/register npm test', 'instrument your tests with coverage and babel') | ||
.example('$0 report --reporter=text-lcov', 'output lcov report after running your tests') | ||
.epilog('visit https://git.io/voHar for list of available reporters') | ||
|
||
|
@@ -125,6 +145,8 @@ if (argv._[0] === 'report') { | |
report(argv) | ||
} else if (argv._[0] === 'check-coverage') { | ||
checkCoverage(argv) | ||
} else if (argv._[0] === 'instrument') { | ||
// noop, let the command handler do its thing. | ||
} else if (argv._.length) { | ||
// wrap subprocesses and execute argv[1] | ||
argv.require = arrify(argv.require) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
var NYC = require('../../') | ||
|
||
exports.command = 'instrument <input> [output]' | ||
|
||
exports.describe = 'instruments a file or a directory tree and writes the instrumented code to the desired output location' | ||
|
||
exports.builder = function (yargs) { | ||
return yargs | ||
.usage('$0 instrument <input> [output]') | ||
.option('require', { | ||
alias: 'i', | ||
default: [], | ||
describe: 'a list of additional modules that nyc should attempt to require in its subprocess, e.g., babel-register, babel-polyfill.' | ||
}) | ||
.option('extension', { | ||
alias: 'e', | ||
default: [], | ||
describe: 'a list of extensions that nyc should handle in addition to .js' | ||
}) | ||
.option('source-map', { | ||
default: true, | ||
type: 'boolean', | ||
description: 'should nyc detect and handle source maps?' | ||
}) | ||
.option('instrument', { | ||
default: true, | ||
type: 'boolean', | ||
description: 'should nyc handle instrumentation?' | ||
}) | ||
.example('$0 instrument ./lib ./output', 'instrument all .js files in ./lib with coverage and output in ./output') | ||
} | ||
|
||
exports.handler = function (argv) { | ||
// if instrument is set to false, | ||
// enable a noop instrumenter. | ||
if (!argv.instrument) argv.instrumenter = './lib/instrumenters/noop' | ||
else argv.instrumenter = './lib/instrumenters/istanbul' | ||
|
||
var nyc = new NYC({ | ||
instrumenter: argv.instrumenter, | ||
sourceMap: argv.sourceMap, | ||
extension: argv.extension, | ||
require: argv.require | ||
}) | ||
|
||
nyc.instrumentAllFiles(argv.input, argv.output, function (err) { | ||
if (err) console.error(err.message) | ||
process.exit(1) | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this simply say:
The default is
coverage
. Ifreport-dir
is specified, it's no longer the "default".