Skip to content

Commit

Permalink
fix(config): resolve <rootDir> to . in coverageDirectory (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
anlesk committed Aug 26, 2024
1 parent 0b6c212 commit e918e9e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions lib/__tests__/getData.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,22 @@ it('returns parsed config and report contents when a custom coverage directory i
},
})
})

it('resolves <rootDir> as current directory', async () => {
jest.mock(
'../jest.config.js',
() => ({
coverageThreshold,
coverageDirectory: '<rootDir>/custom/coverage/directory',
}),
{ virtual: true },
)

await getData(configPath)

expect(fs.readFileSync).toHaveBeenCalledTimes(1)
expect(fs.readFileSync).toHaveBeenCalledWith(
`/workingDir/custom/coverage/directory/coverage-summary.json`,
'utf8',
)
})
2 changes: 1 addition & 1 deletion lib/getData.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const getData = async configPath => {
} = typeof config === 'function' ? await config() : config
const reportPath = path.resolve(
path.dirname(configPath),
coverageDirectory,
coverageDirectory.replace('<rootDir>', '.'),
'coverage-summary.json',
)
const { total: coverages } = JSON.parse(fs.readFileSync(reportPath, 'utf8'))
Expand Down

0 comments on commit e918e9e

Please sign in to comment.