forked from vuejs/create-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocale.spec.ts
28 lines (25 loc) · 828 Bytes
/
locale.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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 locales = readdirSync(resolve(__dirname, '../locales')).filter((file) => {
return file.endsWith('.json')
})
const defaultKeys = getKeys(en);
describe("should include all keys", () => {
locales.forEach((locale) => {
it.runIf(!locale.startsWith("en-US"))(`for ${locale}`, () => {
expect(getKeys(require(`../locales/${locale}`))).toEqual(defaultKeys)
})
})
})