Skip to content

Commit

Permalink
fix: set processinfo pid/ppid to actual numbers (#1057)
Browse files Browse the repository at this point in the history
As of Node.js v6, process.ppid is available, and a number.  So, there's
no need to pass the parent PID through the environment, which casts it
to a string.

BREAKING CHANGE: this changes the data type of the pid/ppid fields in
processinfo files
  • Loading branch information
isaacs authored and coreyfarrell committed Apr 6, 2019
1 parent 16d4315 commit 32f75b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 2 additions & 4 deletions bin/wrap.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
var sw = require('spawn-wrap')
var NYC = require('../index.js')

var parentPid = process.env.NYC_PARENT_PID || '0'
process.env.NYC_PARENT_PID = process.pid

var config = {}
if (process.env.NYC_CONFIG) config = JSON.parse(process.env.NYC_CONFIG)
config.isChildProcess = true

config._processInfo = {
ppid: parentPid,
pid: process.pid,
ppid: process.ppid,
root: process.env.NYC_ROOT_ID
}

Expand Down
8 changes: 7 additions & 1 deletion test/nyc-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,13 @@ describe('the nyc cli', function () {
proc.on('close', function (code) {
code.should.equal(0)
stdout.should.not.match(new RegExp('└─'))
fs.statSync(path.resolve(fixturesCLI, '.nyc_output', 'processinfo'))
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()
})
})
Expand Down

0 comments on commit 32f75b0

Please sign in to comment.