diff --git a/packages/istanbul-reports/lib/html-spa/src/getChildData.js b/packages/istanbul-reports/lib/html-spa/src/getChildData.js index 8b09b327..42e5de01 100644 --- a/packages/istanbul-reports/lib/html-spa/src/getChildData.js +++ b/packages/istanbul-reports/lib/html-spa/src/getChildData.js @@ -30,18 +30,21 @@ function filterByFile(nodes, fileFilter, parentPath) { for (let i = 0; i < nodes.length; i++) { const child = nodes[i]; const childFullPath = (parentPath ? parentPath + '/' : '') + child.file; - if ( - childFullPath === fileFilter || - childFullPath.indexOf(fileFilter) < 0 - ) { - if (fileFilter.indexOf(childFullPath) === 0) { - // flatten - children = [ - ...children, - ...filterByFile(child.children, fileFilter, childFullPath) - ]; - } - } else { + + const isChildUnderFilter = + fileFilter === childFullPath || + fileFilter.indexOf(childFullPath + '/') === 0; + const isChildAboveFilter = + childFullPath.indexOf(fileFilter + '/') === 0; + + if (isChildUnderFilter) { + // flatten and continue looking underneath + children = [ + ...children, + ...filterByFile(child.children, fileFilter, childFullPath) + ]; + } else if (isChildAboveFilter) { + // remove the parent path and add everything underneath const charsToRemoveFromFile = fileFilter.length - (parentPath ? parentPath.length : 0); let childFilename = child.file.slice(charsToRemoveFromFile);