refactor(core): Refactored and removed redundant test lines in teleme… (#12284)

This commit is contained in:
Jainam M
2025-10-31 13:03:33 +05:30
committed by GitHub
parent 85c2ac26c5
commit d018c2ef4d
3 changed files with 155 additions and 229 deletions
@@ -8,39 +8,41 @@ import { describe, it, expect } from 'vitest';
import { getProgrammingLanguage } from './telemetry-utils.js';
describe('getProgrammingLanguage', () => {
it('should return the programming language when file_path is present', () => {
const args = { file_path: 'src/test.ts' };
const language = getProgrammingLanguage(args);
expect(language).toBe('TypeScript');
});
type ProgrammingLanguageTestCase = {
name: string;
args: Record<string, string>;
expected: string | undefined;
};
it('should return the programming language when absolute_path is present', () => {
const args = { absolute_path: 'src/test.py' };
it.each<ProgrammingLanguageTestCase>([
{
name: 'file_path is present',
args: { file_path: 'src/test.ts' },
expected: 'TypeScript',
},
{
name: 'absolute_path is present',
args: { absolute_path: 'src/test.py' },
expected: 'Python',
},
{ name: 'path is present', args: { path: 'src/test.go' }, expected: 'Go' },
{
name: 'no file path is present',
args: {},
expected: undefined,
},
{
name: 'unknown file extensions',
args: { file_path: 'src/test.unknown' },
expected: undefined,
},
{
name: 'files with no extension',
args: { file_path: 'src/test' },
expected: undefined,
},
])('should return $expected when $name', ({ args, expected }) => {
const language = getProgrammingLanguage(args);
expect(language).toBe('Python');
});
it('should return the programming language when path is present', () => {
const args = { path: 'src/test.go' };
const language = getProgrammingLanguage(args);
expect(language).toBe('Go');
});
it('should return undefined when no file path is present', () => {
const args = {};
const language = getProgrammingLanguage(args);
expect(language).toBeUndefined();
});
it('should handle unknown file extensions gracefully', () => {
const args = { file_path: 'src/test.unknown' };
const language = getProgrammingLanguage(args);
expect(language).toBeUndefined();
});
it('should handle files with no extension', () => {
const args = { file_path: 'src/test' };
const language = getProgrammingLanguage(args);
expect(language).toBeUndefined();
expect(language).toBe(expected);
});
});