feat: make translation test fail if hardcoded strings are found

This commit is contained in:
Botzy 2025-05-28 17:16:08 +03:00
parent d27f92fb01
commit e704abcb03

View file

@ -88,22 +88,20 @@ function walk(dir, report) {
} }
}); });
} }
const report = [];
describe('i18n hardcoded string scan', () => { walk(directoryToScan, report);
it('should print hardcoded strings with suggested keys', () => {
const report = [];
walk(directoryToScan, report);
if (report.length === 0) { if (report.length !== 0) {
console.log('✅ No hardcoded strings found.'); describe.each(report)('Missing translation key', (entry) => {
} else { it(`should not have "${entry.string}" in ${entry.file} at line ${entry.line}`, () => {
console.log('🚨 Hardcoded strings found:'); expect(entry.string).toBeFalsy();
report.forEach((row) => { });
console.log(`File: ${row.file}, Line: ${row.line}, String: "${row.string}", Suggested Key: ${row.key}`);
});
}
// Optional: expect no hardcoded strings if you want the test to fail in that case
// expect(report.length).toBe(0);
}); });
}); } else {
describe('Missing translation key', () => {
it('No hardcoded strings found', () => {
expect(true).toBe(true); // or just skip
});
});
}