Skip to content

Commit b29bb39

Browse files
ASAS
authored andcommitted
test: fix mr comments
1 parent 54da005 commit b29bb39

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

packages/plugin-coverage/src/lib/runner/lcov/lcov-runner.unit.test.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { getGitRoot, ui } from '@code-pushup/utils';
55
import type { CoverageResult, CoverageType } from '../../config.js';
66
import { lcovResultsToAuditOutputs, parseLcovFiles } from './lcov-runner.js';
77

8-
// Mock getGitRoot
98
vi.mock('@code-pushup/utils', async () => {
109
const actual = await vi.importActual('@code-pushup/utils');
1110
return {
@@ -140,14 +139,13 @@ end_of_record
140139
});
141140

142141
it('should warn about an empty lcov file', async () => {
143-
const warningSpy = vi.spyOn(ui().logger, 'warning');
144-
145142
await parseLcovFiles([
146143
path.join('coverage', 'integration-tests', 'lcov.info'),
147144
path.join('coverage', 'lcov.info'),
148145
]);
149146

150-
expect(warningSpy).toHaveBeenCalledWith(
147+
expect(ui()).toHaveLogged(
148+
'warn',
151149
`Coverage plugin: Empty lcov report file detected at ${path.join(
152150
'coverage',
153151
'lcov.info',
@@ -172,7 +170,7 @@ end_of_record
172170
]);
173171
});
174172

175-
it('should handle invalid stats where hit > found', async () => {
173+
it('should sanitize hit values to not exceed found values when invalid stats are encountered', async () => {
176174
const invalidReport = `
177175
TN:
178176
SF:${path.join('invalid', 'file.ts')}
@@ -261,9 +259,8 @@ describe('lcovResultsToAuditOutputs', () => {
261259

262260
beforeEach(() => {
263261
vi.clearAllMocks();
264-
(getGitRoot as any).mockResolvedValue('/mock/git/root');
262+
vi.mocked(getGitRoot).mockResolvedValue('/mock/git/root');
265263

266-
// Setup mock LCOV file for testing
267264
const testReport = `
268265
TN:
269266
SF:${path.join('src', 'test.ts')}
@@ -311,7 +308,7 @@ end_of_record
311308
});
312309

313310
it('should handle getGitRoot failure gracefully', async () => {
314-
(getGitRoot as any).mockRejectedValue(new Error('Git root not found'));
311+
vi.mocked(getGitRoot).mockRejectedValue(new Error('Git root not found'));
315312

316313
await expect(
317314
lcovResultsToAuditOutputs(mockResults, mockCoverageTypes),

0 commit comments

Comments
 (0)