From e704abcb03fa2f4505327d4324472e0394f8c4a1 Mon Sep 17 00:00:00 2001 From: Botzy Date: Wed, 28 May 2025 17:16:08 +0300 Subject: [PATCH] feat: make translation test fail if hardcoded strings are found --- tests/i18nScan.test.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/tests/i18nScan.test.js b/tests/i18nScan.test.js index 03d3156c8..5f2964a9a 100644 --- a/tests/i18nScan.test.js +++ b/tests/i18nScan.test.js @@ -88,22 +88,20 @@ function walk(dir, report) { } }); } +const report = []; -describe('i18n hardcoded string scan', () => { - it('should print hardcoded strings with suggested keys', () => { - const report = []; - walk(directoryToScan, report); +walk(directoryToScan, report); - if (report.length === 0) { - console.log('✅ No hardcoded strings found.'); - } else { - console.log('🚨 Hardcoded strings found:'); - 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); +if (report.length !== 0) { + describe.each(report)('Missing translation key', (entry) => { + it(`should not have "${entry.string}" in ${entry.file} at line ${entry.line}`, () => { + expect(entry.string).toBeFalsy(); + }); }); -}); +} else { + describe('Missing translation key', () => { + it('No hardcoded strings found', () => { + expect(true).toBe(true); // or just skip + }); + }); +}