diff --git a/lib/config-util.js b/lib/config-util.js index e355d8720..42cad87b0 100644 --- a/lib/config-util.js +++ b/lib/config-util.js @@ -41,7 +41,6 @@ Config.loadConfig = function (argv, cwd) { config.extension = arrify(config.extension) config.exclude = arrify(config.exclude) config.include = arrify(config.include) - config.cwd = cwd return config } @@ -136,6 +135,10 @@ Config.buildYargs = function (cwd) { describe: 'a list of specific files that should be covered, glob patterns are supported', global: false }) + .option('cwd', { + describe: 'working directory to lookup for files', + global: false + }) .option('require', { alias: 'i', default: [], diff --git a/test/src/nyc-tap.js b/test/src/nyc-tap.js index 7f123fec3..bb57388d5 100644 --- a/test/src/nyc-tap.js +++ b/test/src/nyc-tap.js @@ -61,6 +61,11 @@ describe('nyc', function () { var nyc = new NYC(configUtil.loadConfig([], __dirname)) nyc.cwd.should.eql(path.join(__dirname, '../..')) }) + + it('uses --cwd for cwd if it is set (highest priority and no look upwards for package.json) ', function () { + var nyc = new NYC(configUtil.loadConfig(['--cwd', __dirname], __dirname)) + nyc.cwd.should.eql(__dirname) + }) }) describe('config', function () {