Repository: istanbuljs/nyc
Pull request #1061 (2019-04-07 01:19:51)

feat: always build the processinfo temp dir
Always build the processinfo data directory (with index) in
${tmpdir}/processinfo.  This more easily supports cases where the
processinfo index may be useful for later analysis, or generating the
process tree post hoc.

BREAKING CHANGE: this removes the --build-process-tree option, which
appeared in previous 14.0.0 prerelease versions.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/22646727/badge)](https://coveralls.io/builds/22646727)

Coverage increased (+0.5%) to 96.627% when pulling **f49731bee8d7d83d0025c874970e3a2d1faa23a8 on isaacs:processinfo-always** into **e597c46ab33d47531119d66398e678ee8eb0265c on istanbuljs:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/22646727/badge)](https://coveralls.io/builds/22646727)

Coverage increased (+0.5%) to 96.627% when pulling **f49731bee8d7d83d0025c874970e3a2d1faa23a8 on isaacs:processinfo-always** into **e597c46ab33d47531119d66398e678ee8eb0265c on istanbuljs:master**.

coreyfarrell: All of my comments below the line assume nobody has objections to always building the processinfo files.  I'm OK with it but want to give others a chance to speak.  @bcoe @JaKXz @addaleax?

---

This will not be labeled as a breaking change.  I plan to delete "add `--build-process-tree` feature" from the new features section of the changelog to prevent confusion.  14.0.0-alpha.0 was a non-tagged release so when we eventually do the final 14.0.0 release the changelog will be generated as if no pre-release versions were created (all changes between 13.3.0 and 14.0.0 will be listed as new to 14.0.0).

The cleanest way to handle this would be to revert #1028 in a separate commit to master and merge those changes into this PR.  Then when `standard-version` generates the changelog it would see the revert and ignore #1028.

Further detail: we don't have strictness enabled in yargs, so `nyc --build-process-tree` will continue to work without error and the process tree will be build.

Patch:
diff --git a/bin/nyc.js b/bin/nyc.js
index 80f97c4..cd22584 100755
--- a/bin/nyc.js
+++ b/bin/nyc.js
@@ -65,9 +65,7 @@ if ([
   ), function (done) {
     var mainChildExitCode = process.exitCode
 
-    if (argv.showProcessTree || argv.buildProcessTree) {
-      nyc.writeProcessIndex()
-    }
+    nyc.writeProcessIndex()
 
     if (argv.checkCoverage) {
       nyc.checkCoverage({
diff --git a/index.js b/index.js
index 2502c17..4936859 100755
--- a/index.js
+++ b/index.js
@@ -40,7 +40,6 @@ function NYC (config) {
   this._reportDir = config.reportDir || 'coverage'
   this._sourceMap = typeof config.sourceMap === 'boolean' ? config.sourceMap : true
   this._showProcessTree = config.showProcessTree || false
-  this._buildProcessTree = this._showProcessTree || config.buildProcessTree
   this._eagerInstantiation = config.eager || false
   this.cwd = config.cwd || process.cwd()
   this.reporter = [].concat(config.reporter || 'text')
@@ -293,9 +292,7 @@ NYC.prototype.createTempDirectory = function () {
   mkdirp.sync(this.tempDirectory())
   if (this.cache) mkdirp.sync(this.cacheDirectory)
 
-  if (this._buildProcessTree) {
-    mkdirp.sync(this.processInfoDirectory())
-  }
+  mkdirp.sync(this.processInfoDirectory())
 }
 
 NYC.prototype.reset = function () {
@@ -351,10 +348,6 @@ NYC.prototype.writeCoverageFile = function () {
     'utf-8'
   )
 
-  if (!this._buildProcessTree) {
-    return
-  }
-
   this.processInfo.coverageFilename = coverageFilename
   this.processInfo.files = Object.keys(coverage)
 
diff --git a/lib/config-util.js b/lib/config-util.js
index bcaf223..5ca4043 100644
--- a/lib/config-util.js
+++ b/lib/config-util.js
@@ -229,12 +229,6 @@ Config.buildYargs = function (cwd) {
       type: 'boolean',
       global: false
     })
-    .option('build-process-tree', {
-      describe: 'create files for 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,


Test patch:
diff --git a/test/nyc-integration.js b/test/nyc-integration.js
index 88155a6..2198afd 100644
--- a/test/nyc-integration.js
+++ b/test/nyc-integration.js
@@ -1090,70 +1090,6 @@ describe('the nyc cli', function () {
         done()
       })
     })
-
-    it('doesn’t create the temp directory for process info files when not present', function (done) {
-      var args = [bin, process.execPath, 'selfspawn-fibonacci.js', '5']
-
-      var proc = spawn(process.execPath, args, {
-        cwd: fixturesCLI,
-        env: env
-      })
-
-      proc.on('exit', function (code) {
-        code.should.equal(0)
-        fs.stat(path.resolve(fixturesCLI, '.nyc_output', 'processinfo'), function (err, stat) {
-          err.code.should.equal('ENOENT')
-          done()
-        })
-      })
-    })
-  })
-
-  describe('--build-process-tree', function () {
-    it('builds, but does not display, a tree of spawned processes', function (done) {
-      var args = [bin, '--build-process-tree', process.execPath, 'selfspawn-fibonacci.js', '5']
-
-      var proc = spawn(process.execPath, args, {
-        cwd: fixturesCLI,
-        env: env
-      })
-
-      var stdout = ''
-      proc.stdout.setEncoding('utf8')
-      proc.stdout.on('data', function (chunk) {
-        stdout += chunk
-      })
-
-      proc.on('close', function (code) {
-        code.should.equal(0)
-        stdout.should.not.match(new RegExp('└─'))
-        const dir = path.resolve(fixturesCLI, '.nyc_output', 'processinfo')
-        fs.statSync(dir)
-        // make sure that the processinfo file has a numeric pid and ppid
-        const files = fs.readdirSync(dir).filter(f => f !== 'index.json')
-        const data = JSON.parse(fs.readFileSync(dir + '/' + files[0], 'utf8'))
-        data.pid.should.be.a('number')
-        data.ppid.should.be.a('number')
-        done()
-      })
-    })
-
-    it('doesn’t create the temp directory for process info files when not present', function (done) {
-      var args = [bin, process.execPath, 'selfspawn-fibonacci.js', '5']
-
-      var proc = spawn(process.execPath, args, {
-        cwd: fixturesCLI,
-        env: env
-      })
-
-      proc.on('exit', function (code) {
-        code.should.equal(0)
-        fs.stat(path.resolve(fixturesCLI, '.nyc_output', 'processinfo'), function (err, stat) {
-          err.code.should.equal('ENOENT')
-          done()
-        })
-      })
-    })
   })
 
   describe('--temp-dir', function () {
@@ -1174,7 +1110,7 @@ describe('the nyc cli', function () {
       proc.on('close', function (code) {
         code.should.equal(0)
         var tempFiles = fs.readdirSync(path.resolve(fixturesCLI, '.nyc_output'))
-        tempFiles.length.should.equal(1)
+        tempFiles.length.should.equal(2) // the coverage file, and processinfo
         var cliFiles = fs.readdirSync(path.resolve(fixturesCLI))
         cliFiles.should.include('.nyc_output')
         cliFiles.should.not.include('.temp_dir')
@@ -1194,7 +1130,7 @@ describe('the nyc cli', function () {
       proc.on('exit', function (code) {
         code.should.equal(0)
         var tempFiles = fs.readdirSync(path.resolve(fixturesCLI, '.temp_directory'))
-        tempFiles.length.should.equal(1)
+        tempFiles.length.should.equal(2)
         var cliFiles = fs.readdirSync(path.resolve(fixturesCLI))
         cliFiles.should.not.include('.nyc_output')
         cliFiles.should.not.include('.temp_dir')
@@ -1214,7 +1150,7 @@ describe('the nyc cli', function () {
       proc.on('exit', function (code) {
         code.should.equal(0)
         var tempFiles = fs.readdirSync(path.resolve(fixturesCLI, '.temp_dir'))
-        tempFiles.length.should.equal(1)
+        tempFiles.length.should.equal(2)
         var cliFiles = fs.readdirSync(path.resolve(fixturesCLI))
         cliFiles.should.not.include('.nyc_output')
         cliFiles.should.include('.temp_dir')
diff --git a/test/processinfo.js b/test/processinfo.js
index 7117bee..9fbf035 100644
--- a/test/processinfo.js
+++ b/test/processinfo.js
@@ -14,7 +14,7 @@ t.teardown(() => rimraf.sync(resolve(fixturesCLI, tmp)))
 
 t.test('build some processinfo', t => {
   var args = [
-    bin, '-t', tmp, '--build-process-tree',
+    bin, '-t', tmp,
     node, 'selfspawn-fibonacci.js', '5'
   ]
   var proc = spawn(process.execPath, args, {