Skip to content

Commit df8807f

Browse files
committed
Refactor getCoverageFiles
1 parent 2759e27 commit df8807f

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/helpers/files.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-check
22
const childProcess = require('child_process')
3+
const glob = require('fast-glob')
34
const fs = require('fs')
4-
const glob = require('glob')
55
const path = require('path').posix
66
const { logAndThrow } = require('./util')
77
const { error, info, verbose } = require('./logger')
@@ -160,15 +160,14 @@ function coverageFilePatterns() {
160160
*
161161
* @param {string} projectRoot
162162
* @param {string[]} coverageFilePatterns
163-
* @returns {string[]}
163+
* @returns {Promise<string[]>}
164164
*/
165-
function getCoverageFiles(projectRoot, coverageFilePatterns) {
166-
return coverageFilePatterns.flatMap(
167-
/** @type {string} */ pattern => {
168-
return glob.sync(`**/${pattern}`, {
169-
cwd: projectRoot,
170-
ignore: globBlacklist(),
171-
})
165+
async function getCoverageFiles(projectRoot, coverageFilePatterns) {
166+
return glob(
167+
coverageFilePatterns.map(pattern => `**/${pattern}`),
168+
{
169+
cwd: projectRoot,
170+
ignore: globBlacklist(),
172171
},
173172
)
174173
}

test/helpers/files.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ describe('File Helpers', () => {
8181
expect(reportContents).toBe('I am test coverage data')
8282
})
8383

84-
it('can return a list of coverage files', () => {
85-
const results = fileHelpers.getCoverageFiles(
84+
it('can return a list of coverage files', async () => {
85+
const results = await fileHelpers.getCoverageFiles(
8686
'.',
8787
fileHelpers.coverageFilePatterns(),
8888
)
@@ -94,9 +94,9 @@ describe('File Helpers', () => {
9494
expect(results).toContain('test/fixtures/other/fake.codecov.txt')
9595
})
9696

97-
it('can return a list of coverage files with a pattern', () => {
97+
it('can return a list of coverage files with a pattern', async () => {
9898
expect(
99-
fileHelpers.getCoverageFiles('.', ['index.test.js']),
99+
await fileHelpers.getCoverageFiles('.', ['index.test.js']),
100100
).toStrictEqual(['test/index.test.js', 'test/providers/index.test.js'])
101101
})
102102
describe('coverage file patterns', () => {

0 commit comments

Comments
 (0)