All files / util require-search.js

100% Statements 5/5
80% Branches 4/5
100% Functions 2/2
100% Lines 4/4
1 2 3 4 5 6 7 8 9 10 11 12 13 14        8x 6x 6x 3x            
import path from 'path';
 
export default (relativeTo, paths) => {
  let result;
  for (const testPath of paths.concat(paths.map(mapPath => path.resolve(relativeTo, mapPath)))) {
    try {
      result = require(testPath);
      return typeof result === 'object' && result && result.default ? result.default : result;
    } catch (err) {
      // Ignore the error
    }
  }
};