spb/spbgit Public MIT
SPB Git — the platform hosting itself
JavaScript 73.9%
CSS 11.7%
Nunjucks 11.6%
Shell 2.7%
1/**2 * ─────────────────────────────────────────────3 * SPB Git — Personal Git Platform4 * ─────────────────────────────────────────────5 * Author : Simon-Pierre Boucher6 * Contact : contact@spboucher.ai7 * File : test/unit/languages.test.mjs8 * Purpose : Unit tests — language detection + percentages9 * License : MIT © Simon-Pierre Boucher10 * ─────────────────────────────────────────────11 */1213import { describe, it, expect } from 'vitest';14import { detectLanguage, computeLanguages, languageColor } from '../../src/stats/languages.mjs';1516describe('detectLanguage', () => {17 it('maps common extensions', () => {18 expect(detectLanguage('src/index.mjs')).toBe('JavaScript');19 expect(detectLanguage('main.py')).toBe('Python');20 expect(detectLanguage('lib.rs')).toBe('Rust');21 expect(detectLanguage('Dockerfile')).toBe('Dockerfile');22 expect(detectLanguage('CMakeLists.txt')).toBe('CMake');23 expect(detectLanguage('notes.md')).toBe('Markdown');24 });25 it('returns null for unknown files', () => {26 expect(detectLanguage('data.unknownext')).toBe(null);27 expect(detectLanguage('LICENSE')).toBe(null);28 });29});3031describe('computeLanguages', () => {32 it('computes byte percentages, programming+markup only', () => {33 const { languages, totalBytes } = computeLanguages([34 { path: 'a.py', size: 750 },35 { path: 'b.js', size: 250 },36 { path: 'README.md', size: 5000 }, // prose → excluded37 { path: 'data.json', size: 9000 }, // data → excluded38 { path: 'node_modules/x.js', size: 4000 },// vendored → excluded39 { path: 'app.min.js', size: 12000 }, // minified → excluded40 ]);41 expect(totalBytes).toBe(1000);42 expect(languages[0]).toMatchObject({ name: 'Python', percent: 75 });43 expect(languages[1]).toMatchObject({ name: 'JavaScript', percent: 25 });44 });45 it('handles empty input', () => {46 expect(computeLanguages([]).languages).toEqual([]);47 });48});4950describe('languageColor', () => {51 it('returns linguist colors with a grey fallback', () => {52 expect(languageColor('Python')).toBe('#3572A5');53 expect(languageColor('NotALanguage')).toBe('#8b93a3');54 });55});56