aboutsummaryrefslogtreecommitdiff
path: root/node_modules/nyc/lib
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/nyc/lib')
-rw-r--r--node_modules/nyc/lib/commands/check-coverage.js46
-rw-r--r--node_modules/nyc/lib/commands/instrument.js7
-rw-r--r--node_modules/nyc/lib/commands/report.js39
-rw-r--r--node_modules/nyc/lib/config-util.js126
4 files changed, 137 insertions, 81 deletions
diff --git a/node_modules/nyc/lib/commands/check-coverage.js b/node_modules/nyc/lib/commands/check-coverage.js
new file mode 100644
index 000000000..c12667bbe
--- /dev/null
+++ b/node_modules/nyc/lib/commands/check-coverage.js
@@ -0,0 +1,46 @@
+var NYC
+try {
+ NYC = require('../../index.covered.js')
+} catch (e) {
+ NYC = require('../../index.js')
+}
+
+exports.command = 'check-coverage'
+
+exports.describe = 'check whether coverage is within thresholds provided'
+
+exports.builder = function (yargs) {
+ yargs
+ .option('branches', {
+ default: 0,
+ description: 'what % of branches must be covered?'
+ })
+ .option('functions', {
+ default: 0,
+ description: 'what % of functions must be covered?'
+ })
+ .option('lines', {
+ default: 90,
+ description: 'what % of lines must be covered?'
+ })
+ .option('statements', {
+ default: 0,
+ description: 'what % of statements must be covered?'
+ })
+ .option('per-file', {
+ default: false,
+ description: 'check thresholds per file'
+ })
+ .example('$0 check-coverage --lines 95', "check whether the JSON in nyc's output folder meets the thresholds provided")
+}
+
+exports.handler = function (argv) {
+ process.env.NYC_CWD = process.cwd()
+
+ ;(new NYC(argv)).checkCoverage({
+ lines: argv.lines,
+ functions: argv.functions,
+ branches: argv.branches,
+ statements: argv.statements
+ }, argv['per-file'])
+}
diff --git a/node_modules/nyc/lib/commands/instrument.js b/node_modules/nyc/lib/commands/instrument.js
index 6ff4a5222..cf1e97461 100644
--- a/node_modules/nyc/lib/commands/instrument.js
+++ b/node_modules/nyc/lib/commands/instrument.js
@@ -11,7 +11,6 @@ exports.describe = 'instruments a file or a directory tree and writes the instru
exports.builder = function (yargs) {
return yargs
- .usage('$0 instrument <input> [output]')
.option('require', {
alias: 'i',
default: [],
@@ -27,6 +26,11 @@ exports.builder = function (yargs) {
type: 'boolean',
description: 'should nyc detect and handle source maps?'
})
+ .option('produce-source-map', {
+ default: false,
+ type: 'boolean',
+ description: "should nyc's instrumenter produce source maps?"
+ })
.option('instrument', {
default: true,
type: 'boolean',
@@ -44,6 +48,7 @@ exports.handler = function (argv) {
var nyc = new NYC({
instrumenter: argv.instrumenter,
sourceMap: argv.sourceMap,
+ produceSourceMap: argv.produceSourceMap,
extension: argv.extension,
require: argv.require
})
diff --git a/node_modules/nyc/lib/commands/report.js b/node_modules/nyc/lib/commands/report.js
new file mode 100644
index 000000000..8289980b9
--- /dev/null
+++ b/node_modules/nyc/lib/commands/report.js
@@ -0,0 +1,39 @@
+var NYC
+try {
+ NYC = require('../../index.covered.js')
+} catch (e) {
+ NYC = require('../../index.js')
+}
+
+exports.command = 'report'
+
+exports.describe = 'run coverage report for .nyc_output'
+
+exports.builder = function (yargs) {
+ return yargs
+ .option('reporter', {
+ alias: 'r',
+ describe: 'coverage reporter(s) to use',
+ default: 'text'
+ })
+ .option('report-dir', {
+ describe: 'directory to output coverage reports in',
+ default: 'coverage'
+ })
+ .option('temp-directory', {
+ describe: 'directory to read raw coverage information from',
+ default: './.nyc_output'
+ })
+ .option('show-process-tree', {
+ describe: 'display the tree of spawned processes',
+ default: false,
+ type: 'boolean'
+ })
+ .example('$0 report --reporter=lcov', 'output an HTML lcov report to ./coverage')
+}
+
+exports.handler = function (argv) {
+ process.env.NYC_CWD = process.cwd()
+ var nyc = new NYC(argv)
+ nyc.report()
+}
diff --git a/node_modules/nyc/lib/config-util.js b/node_modules/nyc/lib/config-util.js
index 3c733e083..2c55a3a11 100644
--- a/node_modules/nyc/lib/config-util.js
+++ b/node_modules/nyc/lib/config-util.js
@@ -1,3 +1,5 @@
+'use strict'
+
const arrify = require('arrify')
const fs = require('fs')
const path = require('path')
@@ -7,37 +9,29 @@ const Yargs = require('yargs/yargs')
var Config = {}
-// load config from a cascade of sources:
-// * command line arguments
-// * package.json
-// * .nycrc
-Config.loadConfig = function (argv, cwd) {
+function guessCWD (cwd) {
cwd = cwd || process.env.NYC_CWD || process.cwd()
- var pkgPath = findUp.sync('package.json', {cwd: cwd})
- var rcPath = findUp.sync(['.nycrc', '.nycrc.json'], {cwd: cwd})
- var rcConfig = null
+ const pkgPath = findUp.sync('package.json', {cwd: cwd})
+ if (pkgPath) {
+ cwd = path.dirname(pkgPath)
+ }
+ return cwd
+}
+
+function loadConfig (argv, cwd) {
+ const rcPath = findUp.sync(['.nycrc', '.nycrc.json'], {cwd: cwd})
+ let config = {}
if (rcPath) {
- rcConfig = JSON.parse(
+ config = JSON.parse(
fs.readFileSync(rcPath, 'utf-8')
)
}
- if (pkgPath) {
- cwd = path.dirname(pkgPath)
- }
-
- var config = Config.buildYargs(cwd)
- if (rcConfig) config.config(rcConfig)
- config = config.parse(argv || [])
-
- // post-hoc, we convert several of the
- // configuration settings to arrays, providing
- // a consistent contract to index.js.
- config.require = arrify(config.require)
- config.extension = arrify(config.extension)
- config.exclude = arrify(config.exclude)
- config.include = arrify(config.include)
+ if (config.require) config.require = arrify(config.require)
+ if (config.extension) config.extension = arrify(config.extension)
+ if (config.exclude) config.exclude = arrify(config.exclude)
+ if (config.include) config.include = arrify(config.include)
return config
}
@@ -45,56 +39,11 @@ Config.loadConfig = function (argv, cwd) {
// build a yargs object, omitting any settings
// that would cause the application to exit early.
Config.buildYargs = function (cwd) {
+ cwd = guessCWD(cwd)
+ const config = loadConfig()
return Yargs([])
- .usage('$0 [command] [options]\n\nrun your tests with the nyc bin to instrument them with coverage')
- .command('report', 'run coverage report for .nyc_output', function (yargs) {
- return yargs
- .usage('$0 report [options]')
- .option('reporter', {
- alias: 'r',
- describe: 'coverage reporter(s) to use',
- default: 'text'
- })
- .option('report-dir', {
- describe: 'directory to output coverage reports in',
- default: 'coverage'
- })
- .option('temp-directory', {
- describe: 'directory to read raw coverage information from',
- default: './.nyc_output'
- })
- .option('show-process-tree', {
- describe: 'display the tree of spawned processes',
- default: false,
- type: 'boolean'
- })
- .example('$0 report --reporter=lcov', 'output an HTML lcov report to ./coverage')
- })
- .command('check-coverage', 'check whether coverage is within thresholds provided', function (yargs) {
- return yargs
- .usage('$0 check-coverage [options]')
- .option('branches', {
- default: 0,
- description: 'what % of branches must be covered?'
- })
- .option('functions', {
- default: 0,
- description: 'what % of functions must be covered?'
- })
- .option('lines', {
- default: 90,
- description: 'what % of lines must be covered?'
- })
- .option('statements', {
- default: 0,
- description: 'what % of statements must be covered?'
- })
- .option('per-file', {
- default: false,
- description: 'check thresholds per file'
- })
- .example('$0 check-coverage --lines 95', "check whether the JSON in nyc's output folder meets the thresholds provided")
- })
+ .usage('$0 [command] [options]')
+ .usage('$0 [options] [bin-to-instrument]')
.option('reporter', {
alias: 'r',
describe: 'coverage reporter(s) to use',
@@ -126,6 +75,12 @@ Config.buildYargs = function (cwd) {
describe: 'a list of specific files and directories that should be excluded from coverage, glob patterns are supported, node_modules is always excluded',
global: false
})
+ .option('exclude-after-remap', {
+ default: true,
+ type: 'boolean',
+ description: 'should exclude logic be performed after the source-map remaps filenames?',
+ global: false
+ })
.option('include', {
alias: 'n',
default: [],
@@ -139,7 +94,7 @@ Config.buildYargs = function (cwd) {
.option('require', {
alias: 'i',
default: [],
- describe: 'a list of additional modules that nyc should attempt to require in its subprocess, e.g., babel-register, babel-polyfill.',
+ describe: 'a list of additional modules that nyc should attempt to require in its subprocess, e.g., babel-register, babel-polyfill',
global: false
})
.option('eager', {
@@ -220,6 +175,12 @@ Config.buildYargs = function (cwd) {
.option('hook-run-in-context', {
default: true,
type: 'boolean',
+ description: 'should nyc wrap vm.runInContext?',
+ global: false
+ })
+ .option('hook-run-in-this-context', {
+ default: true,
+ type: 'boolean',
description: 'should nyc wrap vm.runInThisContext?',
global: false
})
@@ -240,24 +201,29 @@ Config.buildYargs = function (cwd) {
default: './.nyc_output',
global: false
})
- .pkgConf('nyc', cwd || process.cwd())
+ .pkgConf('nyc', cwd)
.example('$0 npm test', 'instrument your tests with coverage')
- .example('$0 --require babel-core/register npm test', 'instrument your tests with coverage and babel')
+ .example('$0 --require babel-core/register npm test', 'instrument your tests with coverage and transpile with Babel')
.example('$0 report --reporter=text-lcov', 'output lcov report after running your tests')
.epilog('visit https://git.io/vHysA for list of available reporters')
- .boolean('help')
.boolean('h')
.boolean('version')
+ .config(config)
+ .help(false)
+ .version(false)
}
-// decorate yargs with all the actions
-// that would make it exit: help, version, command.
-Config.decorateYargs = function (yargs) {
+// we add operations that would make yargs
+// exit post-hoc, allowing for a multi-pass
+// parsing step.
+Config.addCommandsAndHelp = function (yargs) {
return yargs
.help('h')
.alias('h', 'help')
.version()
+ .command(require('../lib/commands/check-coverage'))
.command(require('../lib/commands/instrument'))
+ .command(require('../lib/commands/report'))
}
module.exports = Config