Skip to content

Commit

Permalink
refactor: slight tweak to how we extract the --nycrc-path
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin committed Nov 27, 2017
1 parent 785fccb commit 879631a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 35 deletions.
19 changes: 10 additions & 9 deletions bin/nyc.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
#!/usr/bin/env node

var configUtil = require('../lib/config-util')
var foreground = require('foreground-child')
const configUtil = require('../lib/config-util')
const foreground = require('foreground-child')
var NYC
try {
NYC = require('../index.covered.js')
} catch (e) {
NYC = require('../index.js')
}
var processArgs = require('../lib/process-args')
const processArgs = require('../lib/process-args')

var sw = require('spawn-wrap')
var wrapper = require.resolve('./wrap.js')
const sw = require('spawn-wrap')
const wrapper = require.resolve('./wrap.js')

// parse configuration and command-line arguments;
// we keep these values in a few different forms,
// used in the various execution contexts of nyc:
// reporting, instrumenting subprocesses, etc.
var yargs = configUtil.addCommandsAndHelp(configUtil.buildYargs())
var instrumenterArgs = processArgs.hideInstrumenteeArgs()
var config = configUtil.loadConfig(processArgs.parseArgs())
var argv = yargs.config(config).parse(instrumenterArgs)
const yargs = configUtil.buildYargs()
const instrumenterArgs = processArgs.hideInstrumenteeArgs()
const config = configUtil.loadConfig(yargs.parse(instrumenterArgs))
configUtil.addCommandsAndHelp(yargs)
const argv = yargs.config(config).parse(instrumenterArgs)

if (argv._[0] === 'report') {
// look in lib/commands/report.js for logic.
Expand Down
5 changes: 0 additions & 5 deletions lib/process-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ module.exports = {
}
return argv
},
parseArgs: function () {
var argv = process.argv.slice(2)
var yargv = parser(argv)
return yargv
},
// don't pass arguments for the bin being
// instrumented to nyc.
hideInstrumenteeArgs: function () {
Expand Down
21 changes: 0 additions & 21 deletions test/process-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,4 @@ describe('process-args', function () {
munged.should.eql(['--version'])
})
})

describe('parseArgs', function () {
it('parses arguments such as --nycrc-path --reporter --arg', function () {
process.argv = ['/Users/benjamincoe/bin/iojs',
'/Users/benjamincoe/bin/nyc.js',
'--nycrc-path',
'./.nycrc-config.json',
'--reporter',
'lcov',
'node',
'test/nyc-tap.js',
'--arg',
'--'
]

var munged = processArgs.parseArgs()
munged.nycrcPath.should.eql('./.nycrc-config.json')
munged.reporter.should.eql('lcov')
munged.arg.should.eql(true)
})
})
})

0 comments on commit 879631a

Please sign in to comment.