Skip to content

Commit

Permalink
feat: add "instrument" option as alternative to specifying noop instr…
Browse files Browse the repository at this point in the history
…umenter (#278)

* feat: instroduce instrument option, which feels less confusing than specifying a noop instrumenter

* docs: update config example to use instrument = false
  • Loading branch information
bcoe committed Jun 14, 2016
1 parent 9680306 commit ea028b9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -87,7 +87,7 @@ the `sourceMaps` option to `inline`.
"babel-register"
],
"sourceMap": false,
"instrumenter": "./lib/instrumenters/noop"
"instrument": false
}
}
```
Expand Down
18 changes: 14 additions & 4 deletions bin/nyc.js
@@ -1,4 +1,5 @@
#!/usr/bin/env node
var arrify = require('arrify')
var foreground = require('foreground-child')
var NYC
try {
Expand Down Expand Up @@ -102,6 +103,11 @@ var yargs = require('yargs/yargs')(process.argv.slice(2))
type: 'boolean',
description: 'should nyc detect and handle source maps?'
})
.option('instrument', {
default: true,
type: 'boolean',
description: 'should nyc handle instrumentation?'
})
.option('instrumenter', {
default: './lib/instrumenters/istanbul',
type: 'string',
Expand All @@ -127,10 +133,14 @@ if (argv._[0] === 'report') {
checkCoverage(argv)
} else if (argv._.length) {
// wrap subprocesses and execute argv[1]
if (!Array.isArray(argv.require)) argv.require = [argv.require]
if (!Array.isArray(argv.extension)) argv.extension = [argv.extension]
if (!Array.isArray(argv.exclude)) argv.exclude = [argv.exclude]
if (!Array.isArray(argv.include)) argv.include = [argv.include]
argv.require = arrify(argv.require)
argv.extension = arrify(argv.extension)
argv.exclude = arrify(argv.exclude)
argv.include = arrify(argv.include)

// if instrument is set to false,
// enable a noop instrumenter.
if (!argv.instrument) argv.instrumenter = './lib/instrumenters/noop'

var nyc = (new NYC({
require: argv.require,
Expand Down
35 changes: 33 additions & 2 deletions test/src/nyc-bin.js
Expand Up @@ -208,7 +208,6 @@ describe('the nyc cli', function () {
'--extension=.js',
'--cache=true',
'--source-map=true',
'--instrumenter=./lib/instrumenters/istanbul.js',
process.execPath,
'./env.js'
]
Expand All @@ -219,7 +218,39 @@ describe('the nyc cli', function () {
NYC_EXTENSION: '.js',
NYC_CACHE: 'enable',
NYC_SOURCE_MAP: 'enable',
NYC_INSTRUMENTER: './lib/instrumenters/istanbul.js'
NYC_INSTRUMENTER: './lib/instrumenters/istanbul'
}

var proc = spawn(process.execPath, args, {
cwd: fixturesCLI,
env: env
})

var stdout = ''
proc.stdout.on('data', function (chunk) {
stdout += chunk
})

proc.on('close', function (code) {
code.should.equal(0)
var env = JSON.parse(stdout)
env.should.include(expected)
done()
})
})

it('setting instrument to "false" sets noop instrumenter', function (done) {
var args = [
bin,
'--silent',
'--no-instrument',
'--no-source-map',
process.execPath,
'./env.js'
]
var expected = {
NYC_SOURCE_MAP: 'disable',
NYC_INSTRUMENTER: './lib/instrumenters/noop'
}

var proc = spawn(process.execPath, args, {
Expand Down

0 comments on commit ea028b9

Please sign in to comment.