All files find-made.js

100% Statements 14/14
85.71% Branches 12/14
100% Functions 4/4
100% Lines 14/14

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 21 22 23 24 25 26 27 28 29 301x   1x   8x 1x   7x 2x 5x           1x 8x 1x   7x 7x   5x           1x  
const {dirname} = require('path')
 
const findMade = (opts, parent, path = undefined) => {
  // we never want the 'made' return value to be a root directory
  if (path === parent)
    return Promise.resolve()
 
  return opts.statAsync(parent).then(
    st => st.isDirectory() ? path : undefined, // will fail later
    er => er.code === 'ENOENT'
      ? findMade(opts, dirname(parent), parent)
      : undefined
  )
}
 
const findMadeSync = (opts, parent, path = undefined) => {
  if (path === parent)
    return undefined
 
  try {
    return opts.statSync(parent).isDirectory() ? path : undefined
  } catch (er) {
    return er.code === 'ENOENT'
      ? findMadeSync(opts, dirname(parent), parent)
      : undefined
  }
}
 
module.exports = {findMade, findMadeSync}