Skip to content

Commit

Permalink
[squash] cleanup: make ProcessTree instances nodes of the tree themse…
Browse files Browse the repository at this point in the history
…lves

This is in preparation for per-subtree coverage at some point.
  • Loading branch information
addaleax committed Aug 27, 2016
1 parent f37c90b commit 88021d0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,7 @@ NYC.prototype.report = function () {
}

NYC.prototype.showProcessTree = function () {
var processInfos = this._loadProcessInfos()

console.log(ProcessInfo.renderProcessTree(processInfos))
console.log(this._loadProcessInfoTree().render())
}

NYC.prototype.checkCoverage = function (thresholds) {
Expand All @@ -475,6 +473,10 @@ NYC.prototype.checkCoverage = function (thresholds) {
})
}

NYC.prototype._loadProcessInfoTree = function () {
return ProcessInfo.buildProcessTree(this._loadProcessInfos())
}

NYC.prototype._loadProcessInfos = function () {
var _this = this
var files = fs.readdirSync(this.processInfoDirectory())
Expand Down
23 changes: 18 additions & 5 deletions lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,25 @@ function ProcessInfo (defaults) {
this.ppid = null
this.root = null
this.coverageFilename = null
this.nodes = [] // list of children, filled by buildProcessTree()

for (var key in defaults) {
this[key] = defaults[key]
}
}

ProcessInfo.renderProcessTree = function (infos) {
var treeRoot = { label: 'nyc', nodes: [] }
Object.defineProperty(ProcessInfo.prototype, 'label', {
get: function () {
if (this._label) {
return this._label
}

return this.argv.join(' ')
}
})

ProcessInfo.buildProcessTree = function (infos) {
var treeRoot = new ProcessInfo({ _label: 'nyc' })
var nodes = { }

infos = infos.sort(function (a, b) {
Expand All @@ -28,8 +39,6 @@ ProcessInfo.renderProcessTree = function (infos) {

infos.forEach(function (p) {
nodes[p.root + ':' + p.pid] = p
p.nodes = [] // list of children
p.label = p.argv.join(' ')
})

infos.forEach(function (p) {
Expand All @@ -45,7 +54,11 @@ ProcessInfo.renderProcessTree = function (infos) {
parent.nodes.push(p)
})

return archy(treeRoot)
return treeRoot
}

ProcessInfo.prototype.render = function () {
return archy(this)
}

module.exports = ProcessInfo

0 comments on commit 88021d0

Please sign in to comment.