Skip to content

Commit

Permalink
feat: add locale unit test (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolPlayLin authored Dec 1, 2023
1 parent 3066a4c commit 95a7052
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions __test__/locale.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { describe, it, expect } from 'vitest'
import { resolve } from 'node:path'
import { readdirSync } from 'node:fs'
import en from '../locales/en-US.json'

function getKeys(obj: any, path = '', result: string[] = []) {
for (let key in obj) {
if (typeof obj[key] === 'object') {
getKeys(obj[key], path ? `${path}.${key}` : key, result);
} else {
result.push(path ? `${path}.${key}` : key);
}
}
return result;
}

const localesOtherThanEnglish = readdirSync(resolve(__dirname, '../locales')).filter((file) => {
return file.endsWith('.json') && !file.startsWith('en-US')
})
const defaultKeys = getKeys(en);

describe("locale files should include all keys", () => {
localesOtherThanEnglish.forEach((locale) => {
it(`for ${locale}`, () => {
expect(getKeys(require(`../locales/${locale}`))).toEqual(defaultKeys)
})
})
})

0 comments on commit 95a7052

Please sign in to comment.