Skip to content

Commit c4fcf5e

Browse files
authored
fix: Do not crash when nyc is run inside itself. (#1068)
Fixes #1067
1 parent e21721a commit c4fcf5e

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ NYC.prototype.writeProcessIndex = function () {
437437
infos.forEach(info => {
438438
if (info.parent) {
439439
const parentInfo = infoByUid.get(info.parent)
440-
if (parentInfo.children.indexOf(info.uuid) === -1) {
440+
if (parentInfo && !parentInfo.children.includes(info.uuid)) {
441441
parentInfo.children.push(info.uuid)
442442
}
443443
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"nyc": {
3+
"reporter": []
4+
}
5+
}

test/nyc-integration.js

+31
Original file line numberDiff line numberDiff line change
@@ -1839,6 +1839,37 @@ describe('the nyc cli', function () {
18391839
})
18401840
})
18411841
})
1842+
1843+
it('recursive run does not throw', done => {
1844+
const args = [
1845+
bin,
1846+
process.execPath,
1847+
bin,
1848+
process.execPath,
1849+
bin,
1850+
process.execPath,
1851+
bin,
1852+
'true'
1853+
]
1854+
const proc = spawn(process.execPath, args, {
1855+
cwd: path.resolve(__dirname, './fixtures/recursive-run')
1856+
})
1857+
1858+
let stdio = ''
1859+
proc.stderr.on('data', chunk => {
1860+
stdio += chunk
1861+
})
1862+
1863+
proc.stdout.on('data', chunk => {
1864+
stdio += chunk
1865+
})
1866+
1867+
proc.on('close', code => {
1868+
code.should.equal(0)
1869+
stdio.should.equal('')
1870+
done()
1871+
})
1872+
})
18421873
})
18431874

18441875
function stdoutShouldEqual (stdout, expected) {

0 commit comments

Comments
 (0)