diff --git a/index.js b/index.js index f38645e6b..e0d67c3b3 100755 --- a/index.js +++ b/index.js @@ -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) } } diff --git a/test/fixtures/recursive-run/package.json b/test/fixtures/recursive-run/package.json new file mode 100644 index 000000000..ad0d28273 --- /dev/null +++ b/test/fixtures/recursive-run/package.json @@ -0,0 +1,5 @@ +{ + "nyc": { + "reporter": [] + } +} diff --git a/test/nyc-integration.js b/test/nyc-integration.js index 792fc1293..8b6d45d01 100644 --- a/test/nyc-integration.js +++ b/test/nyc-integration.js @@ -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) {