From e918e9e91a8f7340929284178059588436dcbe0b Mon Sep 17 00:00:00 2001 From: Anatoly Leskovets Date: Mon, 26 Aug 2024 19:39:10 -0400 Subject: [PATCH] fix(config): resolve `` to `.` in `coverageDirectory` (#26) --- lib/__tests__/getData.test.js | 19 +++++++++++++++++++ lib/getData.js | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/__tests__/getData.test.js b/lib/__tests__/getData.test.js index f1d6c7c..34060ce 100644 --- a/lib/__tests__/getData.test.js +++ b/lib/__tests__/getData.test.js @@ -117,3 +117,22 @@ it('returns parsed config and report contents when a custom coverage directory i }, }) }) + +it('resolves as current directory', async () => { + jest.mock( + '../jest.config.js', + () => ({ + coverageThreshold, + coverageDirectory: '/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', + ) +}) diff --git a/lib/getData.js b/lib/getData.js index 2c1b94a..e8f7d61 100644 --- a/lib/getData.js +++ b/lib/getData.js @@ -9,7 +9,7 @@ const getData = async configPath => { } = typeof config === 'function' ? await config() : config const reportPath = path.resolve( path.dirname(configPath), - coverageDirectory, + coverageDirectory.replace('', '.'), 'coverage-summary.json', ) const { total: coverages } = JSON.parse(fs.readFileSync(reportPath, 'utf8'))