Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: Do not crash when nyc is run inside itself. (#1068)
Fixes #1067
  • Loading branch information
coreyfarrell committed Apr 16, 2019
1 parent e21721a commit c4fcf5e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -437,7 +437,7 @@ NYC.prototype.writeProcessIndex = function () {
infos.forEach(info => {
if (info.parent) {
const parentInfo = infoByUid.get(info.parent)
if (parentInfo.children.indexOf(info.uuid) === -1) {
if (parentInfo && !parentInfo.children.includes(info.uuid)) {
parentInfo.children.push(info.uuid)
}
}
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/recursive-run/package.json
@@ -0,0 +1,5 @@
{
"nyc": {
"reporter": []
}
}
31 changes: 31 additions & 0 deletions test/nyc-integration.js
Expand Up @@ -1839,6 +1839,37 @@ describe('the nyc cli', function () {
})
})
})

it('recursive run does not throw', done => {
const args = [
bin,
process.execPath,
bin,
process.execPath,
bin,
process.execPath,
bin,
'true'
]
const proc = spawn(process.execPath, args, {
cwd: path.resolve(__dirname, './fixtures/recursive-run')
})

let stdio = ''
proc.stderr.on('data', chunk => {
stdio += chunk
})

proc.stdout.on('data', chunk => {
stdio += chunk
})

proc.on('close', code => {
code.should.equal(0)
stdio.should.equal('')
done()
})
})
})

function stdoutShouldEqual (stdout, expected) {
Expand Down

0 comments on commit c4fcf5e

Please sign in to comment.