mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-08-29 15:49:22 +00:00
Add test that the translation JSON is valid (#4315)
# Description of Changes Adds a vitest to check that the translation JSON files exist and are actually valid JSON.
This commit is contained in:
parent
442b373ff4
commit
5b20f11e20
50
frontend/src/tests/translation.test.ts
Normal file
50
frontend/src/tests/translation.test.ts
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import { describe, test, expect } from 'vitest';
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
const LOCALES_DIR = path.join(__dirname, '../../public/locales');
|
||||||
|
|
||||||
|
// Get all locale directories for parameterized tests
|
||||||
|
const getLocaleDirectories = () => {
|
||||||
|
if (!fs.existsSync(LOCALES_DIR)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return fs.readdirSync(LOCALES_DIR, { withFileTypes: true })
|
||||||
|
.filter(dirent => dirent.isDirectory())
|
||||||
|
.map(dirent => dirent.name);
|
||||||
|
};
|
||||||
|
|
||||||
|
const localeDirectories = getLocaleDirectories();
|
||||||
|
|
||||||
|
describe('Translation JSON Validation', () => {
|
||||||
|
test('should find the locales directory', () => {
|
||||||
|
expect(fs.existsSync(LOCALES_DIR)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should have at least one locale directory', () => {
|
||||||
|
expect(localeDirectories.length).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.each(localeDirectories)('should have valid JSON in %s/translation.json', (localeDir) => {
|
||||||
|
const translationFile = path.join(LOCALES_DIR, localeDir, 'translation.json');
|
||||||
|
|
||||||
|
// Check if file exists
|
||||||
|
expect(fs.existsSync(translationFile)).toBe(true);
|
||||||
|
|
||||||
|
// Read file content
|
||||||
|
const content = fs.readFileSync(translationFile, 'utf8');
|
||||||
|
expect(content.trim()).not.toBe('');
|
||||||
|
|
||||||
|
// Parse JSON - this will throw if invalid JSON
|
||||||
|
let jsonData;
|
||||||
|
expect(() => {
|
||||||
|
jsonData = JSON.parse(content);
|
||||||
|
}).not.toThrow();
|
||||||
|
|
||||||
|
// Ensure it's an object at root level
|
||||||
|
expect(typeof jsonData).toBe('object');
|
||||||
|
expect(jsonData).not.toBeNull();
|
||||||
|
expect(Array.isArray(jsonData)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user