Skip to content

Commit

Permalink
feat: add --build-process-tree feature (#1028)
Browse files Browse the repository at this point in the history
This allows a user to build the processinfo temp files, without actually
dumping the process tree to stdout.

The goal is to use this in node-tap to see which processes covered which
files, so we know which tests to re-run on changes to the source files.
  • Loading branch information
isaacs authored and coreyfarrell committed Mar 17, 2019
1 parent 364eb33 commit 64571d3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ 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 = arrify(config.reporter || 'text')
Expand Down Expand Up @@ -325,7 +326,7 @@ NYC.prototype.createTempDirectory = function () {
mkdirp.sync(this.tempDirectory())
if (this.cache) mkdirp.sync(this.cacheDirectory)

if (this._showProcessTree) {
if (this._buildProcessTree) {
mkdirp.sync(this.processInfoDirectory())
}
}
Expand Down Expand Up @@ -384,7 +385,7 @@ NYC.prototype.writeCoverageFile = function () {
'utf-8'
)

if (!this._showProcessTree) {
if (!this._buildProcessTree) {
return
}

Expand Down
6 changes: 6 additions & 0 deletions lib/config-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ 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,
Expand Down
41 changes: 41 additions & 0 deletions test/nyc-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,47 @@ describe('the nyc cli', function () {
})
})

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('└─'))
fs.statSync(path.resolve(fixturesCLI, '.nyc_output', 'processinfo'))
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 () {
beforeEach(() => {
rimraf.sync(path.resolve(fixturesCLI, '.nyc_output'))
Expand Down

0 comments on commit 64571d3

Please sign in to comment.