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.js82
-rw-r--r--node_modules/nyc/lib/commands/report.js45
-rw-r--r--node_modules/nyc/lib/config-util.js249
-rw-r--r--node_modules/nyc/lib/hash.js14
-rw-r--r--node_modules/nyc/lib/instrumenters/istanbul.js51
-rw-r--r--node_modules/nyc/lib/instrumenters/noop.js21
-rw-r--r--node_modules/nyc/lib/process-args.js37
-rw-r--r--node_modules/nyc/lib/process.js98
-rw-r--r--node_modules/nyc/lib/self-coverage-helper.js20
-rw-r--r--node_modules/nyc/lib/source-maps.js57
11 files changed, 0 insertions, 720 deletions
diff --git a/node_modules/nyc/lib/commands/check-coverage.js b/node_modules/nyc/lib/commands/check-coverage.js
deleted file mode 100644
index c12667bbe..000000000
--- a/node_modules/nyc/lib/commands/check-coverage.js
+++ /dev/null
@@ -1,46 +0,0 @@
-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
deleted file mode 100644
index b24c0bb56..000000000
--- a/node_modules/nyc/lib/commands/instrument.js
+++ /dev/null
@@ -1,82 +0,0 @@
-var NYC
-try {
- NYC = require('../../index.covered.js')
-} catch (e) {
- NYC = require('../../index.js')
-}
-
-exports.command = 'instrument <input> [output]'
-
-exports.describe = 'instruments a file or a directory tree and writes the instrumented code to the desired output location'
-
-exports.builder = function (yargs) {
- return yargs
- .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.'
- })
- .option('extension', {
- alias: 'e',
- default: [],
- describe: 'a list of extensions that nyc should handle in addition to .js'
- })
- .option('source-map', {
- default: true,
- 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('compact', {
- default: true,
- type: 'boolean',
- description: 'should the output be compacted?'
- })
- .option('preserve-comments', {
- default: true,
- type: 'boolean',
- description: 'should comments be preserved in the output?'
- })
- .option('instrument', {
- default: true,
- type: 'boolean',
- description: 'should nyc handle instrumentation?'
- })
- .option('exit-on-error', {
- default: false,
- type: 'boolean',
- description: 'should nyc exit when an instrumentation failure occurs?'
- })
- .example('$0 instrument ./lib ./output', 'instrument all .js files in ./lib with coverage and output in ./output')
-}
-
-exports.handler = function (argv) {
- // if instrument is set to false,
- // enable a noop instrumenter.
- if (!argv.instrument) argv.instrumenter = './lib/instrumenters/noop'
- else argv.instrumenter = './lib/instrumenters/istanbul'
-
- var nyc = new NYC({
- instrumenter: argv.instrumenter,
- sourceMap: argv.sourceMap,
- produceSourceMap: argv.produceSourceMap,
- extension: argv.extension,
- require: argv.require,
- compact: argv.compact,
- preserveComments: argv.preserveComments,
- exitOnError: argv.exitOnError
- })
-
- nyc.instrumentAllFiles(argv.input, argv.output, function (err) {
- if (err) {
- console.error(err.message)
- process.exit(1)
- } else {
- process.exit(0)
- }
- })
-}
diff --git a/node_modules/nyc/lib/commands/report.js b/node_modules/nyc/lib/commands/report.js
deleted file mode 100644
index ff89da3f8..000000000
--- a/node_modules/nyc/lib/commands/report.js
+++ /dev/null
@@ -1,45 +0,0 @@
-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'
- })
- .option('skip-empty', {
- describe: 'don\'t show empty files (no lines of code) in report',
- default: false,
- type: 'boolean',
- global: false
- })
- .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
deleted file mode 100644
index b202ab445..000000000
--- a/node_modules/nyc/lib/config-util.js
+++ /dev/null
@@ -1,249 +0,0 @@
-'use strict'
-
-const arrify = require('arrify')
-const fs = require('fs')
-const path = require('path')
-const findUp = require('find-up')
-const testExclude = require('test-exclude')
-const Yargs = require('yargs/yargs')
-
-var Config = {}
-
-function guessCWD (cwd) {
- cwd = cwd || process.env.NYC_CWD || process.cwd()
- const pkgPath = findUp.sync('package.json', {cwd: cwd})
- if (pkgPath) {
- cwd = path.dirname(pkgPath)
- }
- return cwd
-}
-
-Config.loadConfig = function (argv, cwd) {
- const rcPath = findUp.sync([argv.nycrcPath || '.nycrc', '.nycrc.json'], {cwd: guessCWD(cwd)})
- let config = {}
-
- if (rcPath) {
- config = JSON.parse(
- fs.readFileSync(rcPath, 'utf-8')
- )
- }
-
- 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
-}
-
-// build a yargs object, omitting any settings
-// that would cause the application to exit early.
-Config.buildYargs = function (cwd) {
- cwd = guessCWD(cwd)
- return Yargs([])
- .usage('$0 [command] [options]')
- .usage('$0 [options] [bin-to-instrument]')
- .option('reporter', {
- alias: 'r',
- describe: 'coverage reporter(s) to use',
- default: 'text',
- global: false
- })
- .option('report-dir', {
- describe: 'directory to output coverage reports in',
- default: 'coverage',
- global: false
- })
- .option('silent', {
- alias: 's',
- default: false,
- type: 'boolean',
- describe: "don't output a report after tests finish running",
- global: false
- })
- .option('all', {
- alias: 'a',
- default: false,
- type: 'boolean',
- describe: 'whether or not to instrument all files of the project (not just the ones touched by your test suite)',
- global: false
- })
- .option('exclude', {
- alias: 'x',
- default: testExclude.defaultExclude,
- 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: [],
- describe: 'a list of specific files that should be covered, glob patterns are supported',
- global: false
- })
- .option('cwd', {
- describe: 'working directory used when resolving paths',
- default: 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',
- global: false
- })
- .option('eager', {
- default: false,
- type: 'boolean',
- describe: 'instantiate the instrumenter at startup (see https://git.io/vMKZ9)',
- global: false
- })
- .option('cache', {
- alias: 'c',
- default: true,
- type: 'boolean',
- describe: 'cache instrumentation results for improved performance',
- global: false
- })
- .option('babel-cache', {
- default: false,
- type: 'boolean',
- describe: 'cache babel transpilation results for improved performance',
- global: false
- })
- .option('extension', {
- alias: 'e',
- default: [],
- describe: 'a list of extensions that nyc should handle in addition to .js',
- global: false
- })
- .option('check-coverage', {
- type: 'boolean',
- default: false,
- describe: 'check whether coverage is within thresholds provided',
- global: false
- })
- .option('branches', {
- default: 0,
- description: 'what % of branches must be covered?',
- global: false
- })
- .option('functions', {
- default: 0,
- description: 'what % of functions must be covered?',
- global: false
- })
- .option('lines', {
- default: 90,
- description: 'what % of lines must be covered?',
- global: false
- })
- .option('statements', {
- default: 0,
- description: 'what % of statements must be covered?',
- global: false
- })
- .option('source-map', {
- default: true,
- type: 'boolean',
- description: 'should nyc detect and handle source maps?',
- global: false
- })
- .option('per-file', {
- default: false,
- type: 'boolean',
- description: 'check thresholds per file',
- global: false
- })
- .option('produce-source-map', {
- default: false,
- type: 'boolean',
- description: "should nyc's instrumenter produce source maps?",
- global: false
- })
- .option('compact', {
- default: true,
- type: 'boolean',
- description: 'should the output be compacted?'
- })
- .option('preserve-comments', {
- default: true,
- type: 'boolean',
- description: 'should comments be preserved in the output?'
- })
- .option('instrument', {
- default: true,
- type: 'boolean',
- description: 'should nyc handle instrumentation?',
- global: false
- })
- .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
- })
- .option('show-process-tree', {
- describe: 'display the tree of spawned processes',
- default: false,
- type: 'boolean',
- global: false
- })
- .option('clean', {
- describe: 'should the .nyc_output folder be cleaned before executing tests',
- default: true,
- type: 'boolean',
- global: false
- })
- .option('nycrc-path', {
- default: '.nycrc',
- description: 'specify a different .nycrc path',
- global: false
- })
- .option('temp-directory', {
- describe: 'directory to output raw coverage information to',
- default: './.nyc_output',
- global: false
- })
- .option('skip-empty', {
- describe: 'don\'t show empty files (no lines of code) in report',
- default: false,
- type: 'boolean',
- global: false
- })
- .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 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('h')
- .boolean('version')
- .help(false)
- .version(false)
-}
-
-// 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'))
- .command(require('../lib/commands/merge'))
-}
-
-module.exports = Config
diff --git a/node_modules/nyc/lib/hash.js b/node_modules/nyc/lib/hash.js
deleted file mode 100644
index a36372071..000000000
--- a/node_modules/nyc/lib/hash.js
+++ /dev/null
@@ -1,14 +0,0 @@
-const CACHE_VERSION = require('../package.json').version
-const md5hex = require('md5-hex')
-const salt = JSON.stringify({
- istanbul: require('istanbul-lib-coverage/package.json').version,
- nyc: CACHE_VERSION
-})
-
-function Hash (code, filename) {
- return md5hex([code, filename, salt]) + '_' + CACHE_VERSION
-}
-
-Hash.salt = salt
-
-module.exports = Hash
diff --git a/node_modules/nyc/lib/instrumenters/istanbul.js b/node_modules/nyc/lib/instrumenters/istanbul.js
deleted file mode 100644
index 2cc1209aa..000000000
--- a/node_modules/nyc/lib/instrumenters/istanbul.js
+++ /dev/null
@@ -1,51 +0,0 @@
-'use strict'
-
-var convertSourceMap = require('convert-source-map')
-var mergeSourceMap = require('merge-source-map')
-
-function InstrumenterIstanbul (cwd, options) {
- var istanbul = InstrumenterIstanbul.istanbul()
- var instrumenter = istanbul.createInstrumenter({
- autoWrap: true,
- coverageVariable: '__coverage__',
- embedSource: true,
- compact: options.compact,
- preserveComments: options.preserveComments,
- produceSourceMap: options.produceSourceMap,
- ignoreClassMethods: options.ignoreClassMethods,
- esModules: true
- })
-
- return {
- instrumentSync: function (code, filename, sourceMap) {
- var instrumented = instrumenter.instrumentSync(code, filename)
- // the instrumenter can optionally produce source maps,
- // this is useful for features like remapping stack-traces.
- // TODO: test source-map merging logic.
- if (options.produceSourceMap) {
- var lastSourceMap = instrumenter.lastSourceMap()
- if (lastSourceMap) {
- if (sourceMap) {
- lastSourceMap = mergeSourceMap(
- sourceMap.toObject(),
- lastSourceMap
- )
- }
- instrumented += '\n' + convertSourceMap.fromObject(lastSourceMap).toComment()
- }
- }
- return instrumented
- },
- lastFileCoverage: function () {
- return instrumenter.lastFileCoverage()
- }
- }
-}
-
-InstrumenterIstanbul.istanbul = function () {
- InstrumenterIstanbul._istanbul || (InstrumenterIstanbul._istanbul = require('istanbul-lib-instrument'))
-
- return InstrumenterIstanbul._istanbul || (InstrumenterIstanbul._istanbul = require('istanbul'))
-}
-
-module.exports = InstrumenterIstanbul
diff --git a/node_modules/nyc/lib/instrumenters/noop.js b/node_modules/nyc/lib/instrumenters/noop.js
deleted file mode 100644
index 935b587c0..000000000
--- a/node_modules/nyc/lib/instrumenters/noop.js
+++ /dev/null
@@ -1,21 +0,0 @@
-var FileCoverage = require('istanbul-lib-coverage').classes.FileCoverage
-var readInitialCoverage = require('istanbul-lib-instrument').readInitialCoverage
-
-function NOOP () {
- return {
- instrumentSync: function (code, filename) {
- var extracted = readInitialCoverage(code)
- if (extracted) {
- this.fileCoverage = new FileCoverage(extracted.coverageData)
- } else {
- this.fileCoverage = null
- }
- return code
- },
- lastFileCoverage: function () {
- return this.fileCoverage
- }
- }
-}
-
-module.exports = NOOP
diff --git a/node_modules/nyc/lib/process-args.js b/node_modules/nyc/lib/process-args.js
deleted file mode 100644
index 695f8e62a..000000000
--- a/node_modules/nyc/lib/process-args.js
+++ /dev/null
@@ -1,37 +0,0 @@
-const parser = require('yargs-parser')
-const commands = [
- 'report',
- 'check-coverage',
- 'instrument',
- 'merge'
-]
-
-module.exports = {
- // don't pass arguments that are meant
- // for nyc to the bin being instrumented.
- hideInstrumenterArgs: function (yargv) {
- var argv = process.argv.slice(1)
- argv = argv.slice(argv.indexOf(yargv._[0]))
- if (argv[0][0] === '-') {
- argv.unshift(process.execPath)
- }
- return argv
- },
- // don't pass arguments for the bin being
- // instrumented to nyc.
- hideInstrumenteeArgs: function () {
- var argv = process.argv.slice(2)
- var yargv = parser(argv)
- if (!yargv._.length) return argv
- for (var i = 0, command; (command = yargv._[i]) !== undefined; i++) {
- if (~commands.indexOf(command)) return argv
- }
-
- // drop all the arguments after the bin being
- // instrumented by nyc.
- argv = argv.slice(0, argv.indexOf(yargv._[0]))
- argv.push(yargv._[0])
-
- return argv
- }
-}
diff --git a/node_modules/nyc/lib/process.js b/node_modules/nyc/lib/process.js
deleted file mode 100644
index c77ca503f..000000000
--- a/node_modules/nyc/lib/process.js
+++ /dev/null
@@ -1,98 +0,0 @@
-const archy = require('archy')
-const libCoverage = require('istanbul-lib-coverage')
-
-function ProcessInfo (defaults) {
- defaults = defaults || {}
-
- this.pid = String(process.pid)
- this.argv = process.argv
- this.execArgv = process.execArgv
- this.cwd = process.cwd()
- this.time = Date.now()
- this.ppid = null
- this.root = null
- this.coverageFilename = null
- this.nodes = [] // list of children, filled by buildProcessTree()
-
- this._coverageMap = null
-
- for (var key in defaults) {
- this[key] = defaults[key]
- }
-}
-
-Object.defineProperty(ProcessInfo.prototype, 'label', {
- get: function () {
- if (this._label) {
- return this._label
- }
-
- var covInfo = ''
- if (this._coverageMap) {
- covInfo = '\n ' + this._coverageMap.getCoverageSummary().lines.pct + ' % Lines'
- }
- return this.argv.join(' ') + covInfo
- }
-})
-
-ProcessInfo.buildProcessTree = function (infos) {
- var treeRoot = new ProcessInfo({ _label: 'nyc' })
- var nodes = { }
-
- infos = infos.sort(function (a, b) {
- return a.time - b.time
- })
-
- infos.forEach(function (p) {
- nodes[p.root + ':' + p.pid] = p
- })
-
- infos.forEach(function (p) {
- if (!p.ppid) {
- return
- }
-
- var parent = nodes[p.root + ':' + p.ppid]
- if (!parent) {
- parent = treeRoot
- }
-
- parent.nodes.push(p)
- })
-
- return treeRoot
-}
-
-ProcessInfo.prototype.getCoverageMap = function (merger) {
- if (this._coverageMap) {
- return this._coverageMap
- }
-
- var childMaps = this.nodes.map(function (child) {
- return child.getCoverageMap(merger)
- })
-
- this._coverageMap = merger([this.coverageFilename], childMaps)
-
- return this._coverageMap
-}
-
-ProcessInfo.prototype.render = function (nyc) {
- this.getCoverageMap(function (filenames, maps) {
- var map = libCoverage.createCoverageMap({})
-
- nyc.eachReport(filenames, function (report) {
- map.merge(report)
- })
-
- maps.forEach(function (otherMap) {
- map.merge(otherMap)
- })
-
- return map
- })
-
- return archy(this)
-}
-
-module.exports = ProcessInfo
diff --git a/node_modules/nyc/lib/self-coverage-helper.js b/node_modules/nyc/lib/self-coverage-helper.js
deleted file mode 100644
index 675f9bea9..000000000
--- a/node_modules/nyc/lib/self-coverage-helper.js
+++ /dev/null
@@ -1,20 +0,0 @@
-/* global ___NYC_SELF_COVERAGE___ */
-
-const path = require('path')
-const fs = require('fs')
-const mkdirp = require('mkdirp')
-const onExit = require('signal-exit')
-
-onExit(function () {
- var coverage = global.___NYC_SELF_COVERAGE___
- if (typeof ___NYC_SELF_COVERAGE___ === 'object') coverage = ___NYC_SELF_COVERAGE___
- if (!coverage) return
-
- var selfCoverageDir = path.join(__dirname, '../.self_coverage')
- mkdirp.sync(selfCoverageDir)
- fs.writeFileSync(
- path.join(selfCoverageDir, process.pid + '.json'),
- JSON.stringify(coverage),
- 'utf-8'
- )
-})
diff --git a/node_modules/nyc/lib/source-maps.js b/node_modules/nyc/lib/source-maps.js
deleted file mode 100644
index c3238544c..000000000
--- a/node_modules/nyc/lib/source-maps.js
+++ /dev/null
@@ -1,57 +0,0 @@
-const convertSourceMap = require('convert-source-map')
-const libCoverage = require('istanbul-lib-coverage')
-const libSourceMaps = require('istanbul-lib-source-maps')
-const fs = require('fs')
-const path = require('path')
-
-// TODO: write some unit tests for this class.
-function SourceMaps (opts) {
- this.cache = opts.cache
- this.cacheDirectory = opts.cacheDirectory
- this.sourceMapCache = libSourceMaps.createSourceMapStore()
- this.loadedMaps = {}
-}
-
-SourceMaps.prototype.extractAndRegister = function (code, filename, hash) {
- var sourceMap = convertSourceMap.fromSource(code) || convertSourceMap.fromMapFileSource(code, path.dirname(filename))
- if (sourceMap) {
- if (this.cache && hash) {
- var mapPath = path.join(this.cacheDirectory, hash + '.map')
- fs.writeFileSync(mapPath, sourceMap.toJSON())
- } else {
- this.sourceMapCache.registerMap(filename, sourceMap.sourcemap)
- }
- }
- return sourceMap
-}
-
-SourceMaps.prototype.remapCoverage = function (obj) {
- var transformed = this.sourceMapCache.transformCoverage(
- libCoverage.createCoverageMap(obj)
- )
- return transformed.map.data
-}
-
-SourceMaps.prototype.reloadCachedSourceMaps = function (report) {
- var _this = this
- Object.keys(report).forEach(function (absFile) {
- var fileReport = report[absFile]
- if (fileReport && fileReport.contentHash) {
- var hash = fileReport.contentHash
- if (!(hash in _this.loadedMaps)) {
- try {
- var mapPath = path.join(_this.cacheDirectory, hash + '.map')
- _this.loadedMaps[hash] = JSON.parse(fs.readFileSync(mapPath, 'utf8'))
- } catch (e) {
- // set to false to avoid repeatedly trying to load the map
- _this.loadedMaps[hash] = false
- }
- }
- if (_this.loadedMaps[hash]) {
- _this.sourceMapCache.registerMap(absFile, _this.loadedMaps[hash])
- }
- }
- })
-}
-
-module.exports = SourceMaps