Skip to content
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: add "instrument" option as alternative to specifying noop instrumenter #278

Merged
merged 2 commits into from
Jun 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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