MCPcopy Create free account
hub / github.com/FSGModding/FSG_Mod_Assistant / testFile

Function testFile

test/fix-locale-files.js:61–99  ·  view source on GitHub ↗
(file)

Source from the content-addressed store, hash-verified

59}
60
61async function testFile(file) {
62 let thisFile = {}
63
64 try {
65 thisFile = JSON.parse(fs.readFileSync(path.join(testPath, `${file}.json`)))
66 const thisFileKeys = new Set(Object.keys(thisFile))
67 const extraKeys = new Set([...thisFileKeys].filter((x) => !baseLocaleKeys.has(x)))
68 const missingKeys = new Set([...baseLocaleKeys].filter((x) => !thisFileKeys.has(x)))
69
70 if ( extraKeys.size !== 0 ) {
71 test.warn(`${file} :: Extra keys removed : ${[...extraKeys].join(', ')}`)
72 for ( const thisKey of extraKeys ) { delete thisFile[thisKey] }
73 }
74 if ( missingKeys.size !== 0 ) {
75 test.warn(`${file} :: Missing keys added : ${[...missingKeys].join(', ')}`)
76 const stringsToTranslate = [...missingKeys].map((x) => baseLocaleData[x])
77
78 await translator.translateText(
79 stringsToTranslate,
80 'en',
81 fileMap[file]
82 ).then((results) => {
83 for ( const [idx, thisKey] of [...missingKeys].entries() ) {
84 thisFile[thisKey] = results[idx].text
85 }
86 test.step(`${file} :: Got Translated Data`)
87 }).catch((err) => {
88 for ( const thisKey of missingKeys ) {
89 thisFile[thisKey] = baseLocaleData[thisKey]
90 }
91 test.error(`${file} :: Translation failed, added english : ${err}`)
92 })
93 }
94 } catch (err) {
95 test.error(`Could not process ${file} :: ${err}`)
96 }
97
98 return thisFile
99}
100
101function fileWriter(data, file) {
102 test.step(`${file} :: Writing Clean File`)

Callers 1

checkFilesFunction · 0.85

Calls 6

keysMethod · 0.80
hasMethod · 0.80
stepMethod · 0.80
parseMethod · 0.45
warnMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected