-
-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds instrument command line option (#298)
* feat: adds instrument command line option * fix: load instrumented version of NYC; fix option description based on @kentcdodds' code review * docs: update README.md * docs: gave README.md a once over, and made a few edits
- Loading branch information
Showing
6 changed files
with
268 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
var NYC | ||
try { | ||
NYC = require('../../index.covered.js') | ||
} catch (e) { | ||
NYC = require('../../index.js') | ||
} | ||
|
||
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) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.