Skip to content

Commit

Permalink
chore: Tweak arguments for async coverage data readers (#1198)
Browse files Browse the repository at this point in the history
This allows istanbul-lib-processinfo to read coverage data files using
only the `coverageFileLoad` function.
  • Loading branch information
coreyfarrell committed Oct 7, 2019
1 parent cc77e13 commit 0efc6d1
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions index.js
Expand Up @@ -475,25 +475,27 @@ class NYC {
})
}

async coverageFiles (baseDirectory) {
const files = await fs.readdir(baseDirectory)

return files.map(f => path.resolve(baseDirectory, f))
coverageFiles (baseDirectory = this.tempDirectory()) {
return fs.readdir(baseDirectory)
}

async coverageFileLoad (filename) {
async coverageFileLoad (filename, baseDirectory = this.tempDirectory()) {
try {
const report = JSON.parse(await fs.readFile(filename), 'utf8')
const report = JSON.parse(await fs.readFile(path.resolve(baseDirectory, filename)), 'utf8')
await this.sourceMaps.reloadCachedSourceMaps(report)
return report
} catch (error) {
return {}
}
}

async coverageData (baseDirectory = this.tempDirectory()) {
async coverageData (baseDirectory) {
const files = await this.coverageFiles(baseDirectory)
return pMap(files, f => this.coverageFileLoad(f), { concurrency: os.cpus().length })
return pMap(
files,
f => this.coverageFileLoad(f, baseDirectory),
{ concurrency: os.cpus().length }
)
}

/* istanbul ignore next: legacy function used by istanbul-lib-processinfo. */
Expand Down

0 comments on commit 0efc6d1

Please sign in to comment.