nyc 11.7.3 → 11.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ <a name="11.8.0"></a>
6
+ # [11.8.0](https://github.com/istanbuljs/nyc/compare/v11.7.3...v11.8.0) (2018-05-14)
7
+
8
+
9
+ ### Features
10
+
11
+ * merge together multiple istanbul format reports ([#840](https://github.com/istanbuljs/nyc/issues/840)) ([9def3eb](https://github.com/istanbuljs/nyc/commit/9def3eb))
12
+
13
+
14
+
5
15
  <a name="11.7.3"></a>
6
16
  ## [11.7.3](https://github.com/istanbuljs/nyc/compare/v11.7.2...v11.7.3) (2018-05-10)
7
17
 
package/bin/nyc.js CHANGED
@@ -23,12 +23,10 @@ const config = configUtil.loadConfig(yargs.parse(instrumenterArgs))
23
23
  configUtil.addCommandsAndHelp(yargs)
24
24
  const argv = yargs.config(config).parse(instrumenterArgs)
25
25
 
26
- if (argv._[0] === 'report') {
27
- // look in lib/commands/report.js for logic.
28
- } else if (argv._[0] === 'check-coverage') {
29
- // look in lib/commands/check-coverage.js for logic.
30
- } else if (argv._[0] === 'instrument') {
31
- // look in lib/commands/instrument.js for logic.
26
+ if ([
27
+ 'check-coverage', 'report', 'instrument', 'merge'
28
+ ].indexOf(argv._[0]) !== -1) {
29
+ // look in lib/commands for logic.
32
30
  } else if (argv._.length) {
33
31
  // if instrument is set to false,
34
32
  // enable a noop instrumenter.
package/index.js CHANGED
@@ -421,13 +421,13 @@ function coverageFinder () {
421
421
  return coverage
422
422
  }
423
423
 
424
- NYC.prototype._getCoverageMapFromAllCoverageFiles = function () {
424
+ NYC.prototype.getCoverageMapFromAllCoverageFiles = function (baseDirectory) {
425
425
  var _this = this
426
426
  var map = libCoverage.createCoverageMap({})
427
427
 
428
- this.eachReport(function (report) {
428
+ this.eachReport(undefined, (report) => {
429
429
  map.merge(report)
430
- })
430
+ }, baseDirectory)
431
431
  // depending on whether source-code is pre-instrumented
432
432
  // or instrumented using a JIT plugin like babel-require
433
433
  // you may opt to exclude files after applying
@@ -443,7 +443,7 @@ NYC.prototype._getCoverageMapFromAllCoverageFiles = function () {
443
443
 
444
444
  NYC.prototype.report = function () {
445
445
  var tree
446
- var map = this._getCoverageMapFromAllCoverageFiles()
446
+ var map = this.getCoverageMapFromAllCoverageFiles()
447
447
  var context = libReport.createContext({
448
448
  dir: this.reportDirectory(),
449
449
  watermarks: this.config.watermarks
@@ -469,7 +469,7 @@ NYC.prototype.showProcessTree = function () {
469
469
  }
470
470
 
471
471
  NYC.prototype.checkCoverage = function (thresholds, perFile) {
472
- var map = this._getCoverageMapFromAllCoverageFiles()
472
+ var map = this.getCoverageMapFromAllCoverageFiles()
473
473
  var nyc = this
474
474
 
475
475
  if (perFile) {
@@ -516,20 +516,22 @@ NYC.prototype._loadProcessInfos = function () {
516
516
  })
517
517
  }
518
518
 
519
- NYC.prototype.eachReport = function (filenames, iterator) {
519
+ NYC.prototype.eachReport = function (filenames, iterator, baseDirectory) {
520
+ baseDirectory = baseDirectory || this.tempDirectory()
521
+
520
522
  if (typeof filenames === 'function') {
521
523
  iterator = filenames
522
524
  filenames = undefined
523
525
  }
524
526
 
525
527
  var _this = this
526
- var files = filenames || fs.readdirSync(this.tempDirectory())
528
+ var files = filenames || fs.readdirSync(baseDirectory)
527
529
 
528
530
  files.forEach(function (f) {
529
531
  var report
530
532
  try {
531
533
  report = JSON.parse(fs.readFileSync(
532
- path.resolve(_this.tempDirectory(), f),
534
+ path.resolve(baseDirectory, f),
533
535
  'utf-8'
534
536
  ))
535
537
 
@@ -545,7 +547,7 @@ NYC.prototype.eachReport = function (filenames, iterator) {
545
547
  NYC.prototype.loadReports = function (filenames) {
546
548
  var reports = []
547
549
 
548
- this.eachReport(filenames, function (report) {
550
+ this.eachReport(filenames, (report) => {
549
551
  reports.push(report)
550
552
  })
551
553
 
@@ -0,0 +1,51 @@
1
+ 'use strict'
2
+ const fs = require('fs')
3
+
4
+ var NYC
5
+ try {
6
+ NYC = require('../../index.covered.js')
7
+ } catch (e) {
8
+ NYC = require('../../index.js')
9
+ }
10
+
11
+ exports.command = 'merge <input-directory> [output-file]'
12
+
13
+ exports.describe = 'merge istanbul format coverage output in a given folder'
14
+
15
+ exports.builder = function (yargs) {
16
+ return yargs
17
+ .positional('input-directory', {
18
+ describe: 'directory containing multiple istanbul coverage files',
19
+ type: 'text',
20
+ default: './.nyc_output'
21
+ })
22
+ .positional('output-file', {
23
+ describe: 'file to output combined istanbul format coverage to',
24
+ type: 'text',
25
+ default: 'coverage.json'
26
+ })
27
+ .option('temp-directory', {
28
+ describe: 'directory to read raw coverage information from',
29
+ default: './.nyc_output'
30
+ })
31
+ .example('$0 merge ./out coverage.json', 'merge together reports in ./out and output as coverage.json')
32
+ }
33
+
34
+ exports.handler = function (argv) {
35
+ process.env.NYC_CWD = process.cwd()
36
+ const nyc = new NYC(argv)
37
+ let inputStat
38
+ try {
39
+ inputStat = fs.statSync(argv.inputDirectory)
40
+ if (!inputStat.isDirectory()) {
41
+ console.error(`${argv.inputDirectory} was not a directory`)
42
+ process.exit(1)
43
+ }
44
+ } catch (err) {
45
+ console.error(`failed access input directory ${argv.inputDirectory} with error:\n\n${err.message}`)
46
+ process.exit(1)
47
+ }
48
+ const map = nyc.getCoverageMapFromAllCoverageFiles(argv.inputDirectory)
49
+ fs.writeFileSync(argv.outputFile, JSON.stringify(map, null, 2), 'utf8')
50
+ console.info(`coverage files in ${argv.inputDirectory} merged into ${argv.outputFile}`)
51
+ }
@@ -243,6 +243,7 @@ Config.addCommandsAndHelp = function (yargs) {
243
243
  .command(require('../lib/commands/check-coverage'))
244
244
  .command(require('../lib/commands/instrument'))
245
245
  .command(require('../lib/commands/report'))
246
+ .command(require('../lib/commands/merge'))
246
247
  }
247
248
 
248
249
  module.exports = Config
@@ -2,7 +2,8 @@ const parser = require('yargs-parser')
2
2
  const commands = [
3
3
  'report',
4
4
  'check-coverage',
5
- 'instrument'
5
+ 'instrument',
6
+ 'merge'
6
7
  ]
7
8
 
8
9
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nyc",
3
- "version": "11.7.3",
3
+ "version": "11.8.0",
4
4
  "description": "the Istanbul command line interface",
5
5
  "main": "index.js",
6
6
  "scripts": {