Skip to content

feat: find local files better #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 17, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore: refactor
  • Loading branch information
bahmutov committed Apr 17, 2020
commit d18d49be3c2b4d83cfb706635b7122c75a1f1645
33 changes: 27 additions & 6 deletions task.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ function saveCoverage(coverage) {
}

/**
* Looks at all coverage objects in the given JSON coverage file
* and if the file is relative, and exists, changes its path to
* be absolute.
* A small debug utility to inspect paths saved in NYC output JSON file
*/
function resolvePaths(nycFilename) {
function showNycInfo(nycFilename) {
const nycCoverage = JSON.parse(readFileSync(nycFilename, 'utf8'))

const coverageKeys = Object.keys(nycCoverage)
Expand All @@ -52,17 +50,39 @@ function resolvePaths(nycFilename) {
}
debug('NYC file %s has %d key(s)', nycFilename, coverageKeys.length)

let changed
const maxPrintKeys = 3
const showKeys = coverageKeys.slice(0, maxPrintKeys)

Object.keys(nycCoverage).forEach((key, k) => {
showKeys.forEach((key, k) => {
const coverage = nycCoverage[key]

// printing a few found keys and file paths from the coverage file
// will make debugging any problems much much easier
if (k < maxPrintKeys) {
debug('%d key %s file path %s', k + 1, key, coverage.path)
}
})
}

/**
* Looks at all coverage objects in the given JSON coverage file
* and if the file is relative, and exists, changes its path to
* be absolute.
*/
function resolvePaths(nycFilename) {
const nycCoverage = JSON.parse(readFileSync(nycFilename, 'utf8'))

const coverageKeys = Object.keys(nycCoverage)
if (!coverageKeys.length) {
console.error('⚠️ file %s has no coverage information', nycFilename)
return
}
debug('NYC file %s has %d key(s)', nycFilename, coverageKeys.length)

let changed

coverageKeys.forEach((key, k) => {
const coverage = nycCoverage[key]

if (coverage.path && !isAbsolute(coverage.path)) {
if (existsSync(coverage.path)) {
Expand Down Expand Up @@ -143,6 +163,7 @@ const tasks = {
return null
}

showNycInfo(nycFilename)
resolvePaths(nycFilename)

if (customNycReportScript) {
Expand Down