Skip to content

Commit b34560c

Browse files
committed
feat: add tests for detecting Cobertura XML files with and without line-rate
1 parent 2d8a2b1 commit b34560c

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

src/__tests__/file-finder.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,38 @@ describe('file-finder', () => {
104104
expect(files[0].format).toBe('cobertura');
105105
});
106106

107+
it('should detect Cobertura XML files with line-rate but without cobertura keyword', async () => {
108+
// Test the line-rate branch of the Cobertura content check
109+
const filePath = path.join(testDir, 'coverage-linerate.xml');
110+
fs.writeFileSync(
111+
filePath,
112+
'<?xml version="1.0"?><coverage line-rate="0.75" branch-rate="0.5">some content</coverage>'
113+
);
114+
mockGlob.create.mockResolvedValue(createMockGlobber([filePath]));
115+
116+
const files = await findCoverageFiles('**/*.xml');
117+
118+
expect(files).toHaveLength(1);
119+
expect(files[0].path).toBe(filePath);
120+
expect(files[0].format).toBe('cobertura');
121+
});
122+
123+
it('should detect Cobertura XML files with cobertura keyword but without line-rate', async () => {
124+
// Test the cobertura keyword branch of the Cobertura content check
125+
const filePath = path.join(testDir, 'coverage-cobertura-keyword.xml');
126+
fs.writeFileSync(
127+
filePath,
128+
'<?xml version="1.0"?><coverage version="cobertura">some content</coverage>'
129+
);
130+
mockGlob.create.mockResolvedValue(createMockGlobber([filePath]));
131+
132+
const files = await findCoverageFiles('**/*.xml');
133+
134+
expect(files).toHaveLength(1);
135+
expect(files[0].path).toBe(filePath);
136+
expect(files[0].format).toBe('cobertura');
137+
});
138+
107139
it('should find and detect Clover XML files', async () => {
108140
const filePath = path.join(testDir, 'clover.xml');
109141
mockGlob.create.mockResolvedValue(createMockGlobber([filePath]));

0 commit comments

Comments
 (0)