Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not crash when nyc is run inside itself. #1068

Merged
merged 1 commit into from Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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