mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 21:11:30 +08:00 
			
		
		
		
	feat(test): ensure backend translations are valid JSON
This commit is contained in:
		
							parent
							
								
									c255af67c9
								
							
						
					
					
						commit
						f6b6b2e740
					
				| @ -3,17 +3,24 @@ import * as i18n from "./i18n.js"; | |||||||
| import path from "path"; | import path from "path"; | ||||||
| import fs from "fs"; | import fs from "fs"; | ||||||
| 
 | 
 | ||||||
|  | function checkTranslations(translationDir: string, translationFileName: string) { | ||||||
|  |     const locales = i18n.getLocales(); | ||||||
|  | 
 | ||||||
|  |     for (const locale of locales) { | ||||||
|  |         const translationPath = path.join(translationDir, locale.id, translationFileName); | ||||||
|  |         const translationFile = fs.readFileSync(translationPath, { encoding: "utf-8" }); | ||||||
|  |         expect(() => { | ||||||
|  |             JSON.parse(translationFile); | ||||||
|  |         }, `JSON error while parsing locale '${locale.id}' at "${translationPath}"`).not.toThrow(); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| describe("i18n", () => { | describe("i18n", () => { | ||||||
|     it("frontend translations are valid JSON", () => { |     it("frontend translations are valid JSON", () => { | ||||||
|         const translationDir = "src/public/translations"; |         checkTranslations("src/public/translations", "translation.json"); | ||||||
|         const locales = i18n.getLocales(); |     }); | ||||||
| 
 | 
 | ||||||
|         for (const locale of locales) { |     it("backend translations are valid JSON", () => { | ||||||
|             const translationPath = path.join(translationDir, locale.id, "translation.json"); |         checkTranslations("translations", "server.json"); | ||||||
|             const translationFile = fs.readFileSync(translationPath, { encoding: "utf-8" }); |  | ||||||
|             expect(() => { |  | ||||||
|                 JSON.parse(translationFile); |  | ||||||
|             }, `JSON error while parsing locale '${locale.id}' at "${translationPath}"`).not.toThrow(); |  | ||||||
|         } |  | ||||||
|     }); |     }); | ||||||
| }); | }); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Elian Doran
						Elian Doran