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 | 2x 19x 19x 10x 19x | import path from 'path'
const FILE_EXTENSION_REGEX = /\.[0-9a-z]+$/i
/**
* Resolves the given path into a absolute path and appends the default filename as fallback when the provided path is a directory.
* @param {String} logPath relative file or directory path
* @param {String} defaultFilename default file name when filePath is a directory
* @return {String} absolute file path
*/
export default function getFilePath (filePath, defaultFilename) {
let absolutePath = path.resolve(filePath)
// test if we already have a file (e.g. selenium.txt, .log, log.txt, etc.)
// NOTE: path.extname doesn't work to detect a file, cause dotfiles are reported by node to have no extension
if (!FILE_EXTENSION_REGEX.test(path.basename(absolutePath))) {
absolutePath = path.join(absolutePath, defaultFilename)
}
return absolutePath
} |