Skip to content

Commit

Permalink
fix(html-spa): Filter only exact paths (#431)
Browse files Browse the repository at this point in the history
Fixes #426
  • Loading branch information
lukeapage authored and coreyfarrell committed Jul 18, 2019
1 parent 569d6cd commit bbc85f6
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions packages/istanbul-reports/lib/html-spa/src/getChildData.js
Expand Up @@ -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);
Expand Down

0 comments on commit bbc85f6

Please sign in to comment.