All files / src/models fs-utils.js

68.75% Statements 11/16
100% Branches 3/3
100% Functions 1/1
68.75% Lines 11/16

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 17193x 193x 193x 193x 25x 25x 25x 25x 25x           25x 25x  
import { promises as fs } from 'node:fs';
import { join } from 'node:path';
 
export function findPath(dir, name) {
  const fullPath = join(dir, name);
  return fs
    .stat(fullPath)
    .then(() => dir)
    .catch((e) => {
      if (e.code === 'ENOENT' && dir !== '/') {
        const parent = join(dir, '..');
        return findPath(parent, name);
      }
      throw e;
    });
}