From 0fc6d8f781acffbe07e1c8c004bf3c52878b7877 Mon Sep 17 00:00:00 2001 From: Vincent Rouille Date: Tue, 5 Sep 2017 02:45:46 +0200 Subject: [PATCH] chore: add support for --cwd (#542) (#620) --- lib/config-util.js | 5 ++++- test/src/nyc-tap.js | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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 () {