All files / src/__tests__ helpers.ts

100% Statements 3/3
75% Branches 3/4
100% Functions 3/3
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20              7x 49x   40x                  
/**
 * Filters out only these files that belong to given rootDir and removes files that are `nulls`, because that the way that `memfs` marks file deletion
 * Each file path is then converted to relative (without starting `/` or `./`)
 * @param fsJSON
 * @param rootDir
 */
export function getDirFromFS(fsJSON: Record<string, string>, rootDir: string) {
  return Object.entries(fsJSON)
    .filter(([path, value]) => value !== null && path.startsWith(rootDir))
    .reduce<Record<string, string>>(
      (acc, [path, fileContent]) => ({
        ...acc,
        [path.substring(rootDir.length).startsWith('/')
          ? path.substring(rootDir.length + 1)
          : path.substring(rootDir.length)]: fileContent,
      }),
      {}
    );
}