GitNexus/gitnexus/test/unit/parser-loader.test.ts
Gergő Magyar bf09eab95b
feat: configure prettier with pre-commit hook (#563)
* feat: configure prettier with pre-commit hook integration

Add prettier, lint-staged, and prettier-plugin-tailwindcss at the repo
root with husky pre-commit hook integration. Moves husky from
gitnexus/ to root package.json for reliable hook installation.

- Root package.json with prepare/format/format:check scripts
- .prettierrc with endOfLine:lf and tailwindStylesheet for TW v4
- .prettierignore excluding fixtures, vendor, generated, *.d.ts, *.md
- .gitattributes enforcing LF line endings for Windows consistency
- Pre-commit hook uses direct node_modules/.bin/ paths (no npx)

* style: apply prettier formatting to entire codebase

One-time bulk format. No logic changes.
Use .git-blame-ignore-revs to skip this commit in git blame.

* chore: add .git-blame-ignore-revs for prettier format commit

* perf: pre-commit hook runs only tests related to staged files

Use vitest --related to scope test execution to tests that import
the changed files, instead of running the full suite on every commit.

* perf: remove vitest from pre-commit hook, keep in CI only

Pre-commit now runs lint-staged + tsc only. Tests run in CI
(ci-tests.yml) where they belong — keeps commits fast.

* ci: add prettier format check to quality workflow

PRs will now fail if code isn't formatted with prettier.
2026-03-28 14:58:04 +00:00

95 lines
3.3 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { loadParser, loadLanguage } from '../../src/core/tree-sitter/parser-loader.js';
import { SupportedLanguages } from '../../src/config/supported-languages.js';
describe('parser-loader', () => {
describe('loadParser', () => {
it('returns a Parser instance', async () => {
const parser = await loadParser();
expect(parser).toBeDefined();
expect(typeof parser.parse).toBe('function');
});
it('returns the same singleton instance', async () => {
const parser1 = await loadParser();
const parser2 = await loadParser();
expect(parser1).toBe(parser2);
});
});
describe('loadLanguage', () => {
it('loads TypeScript language', async () => {
await expect(loadLanguage(SupportedLanguages.TypeScript)).resolves.not.toThrow();
});
it('loads JavaScript language', async () => {
await expect(loadLanguage(SupportedLanguages.JavaScript)).resolves.not.toThrow();
});
it('loads Python language', async () => {
await expect(loadLanguage(SupportedLanguages.Python)).resolves.not.toThrow();
});
it('loads Java language', async () => {
await expect(loadLanguage(SupportedLanguages.Java)).resolves.not.toThrow();
});
it('loads C language', async () => {
await expect(loadLanguage(SupportedLanguages.C)).resolves.not.toThrow();
});
it('loads C++ language', async () => {
await expect(loadLanguage(SupportedLanguages.CPlusPlus)).resolves.not.toThrow();
});
it('loads C# language', async () => {
await expect(loadLanguage(SupportedLanguages.CSharp)).resolves.not.toThrow();
});
it('loads Go language', async () => {
await expect(loadLanguage(SupportedLanguages.Go)).resolves.not.toThrow();
});
it('loads Rust language', async () => {
await expect(loadLanguage(SupportedLanguages.Rust)).resolves.not.toThrow();
});
it('loads PHP language', async () => {
await expect(loadLanguage(SupportedLanguages.PHP)).resolves.not.toThrow();
});
it('loads TSX grammar for .tsx files', async () => {
// TSX uses a different grammar (TypeScript.tsx vs TypeScript.typescript)
await expect(
loadLanguage(SupportedLanguages.TypeScript, 'Component.tsx'),
).resolves.not.toThrow();
});
it('loads TS grammar for .ts files', async () => {
await expect(loadLanguage(SupportedLanguages.TypeScript, 'utils.ts')).resolves.not.toThrow();
});
it('loads Ruby language', async () => {
await expect(loadLanguage(SupportedLanguages.Ruby)).resolves.not.toThrow();
});
it('throws for unsupported language', async () => {
await expect(loadLanguage('erlang' as SupportedLanguages)).rejects.toThrow(
'Unsupported language',
);
});
});
describe('Swift optional dependency', () => {
it('handles Swift loading gracefully', async () => {
// Swift is optional — it either loads successfully or throws an error about unsupported language
try {
await loadLanguage(SupportedLanguages.Swift);
// If it succeeds, tree-sitter-swift is installed
} catch (e: any) {
// If it fails, it should be because tree-sitter-swift is not installed
expect(e.message).toContain('Unsupported language');
}
});
});
});