forked from vuejs/create-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocale.spec.ts
44 lines (39 loc) · 1.26 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { describe, it, expect } from 'vitest'
import { resolve } from 'node:path'
import { readdirSync } from 'node:fs'
import { Language } from '../utils/getLanguage'
import { includeAllKeys, excludeKeys } from './utils'
const locales = readdirSync(resolve(__dirname, '../locales')).filter((file) => {
return file.includes('.json')
})
describe('should match name regex', () => {
/**
*
* both can match normal locale or reusable locale
*
* @example normal locale: en-US
* @example reusable locale: zh-Hant
*/
const regex = /^[a-zA-Z]{2}(-[a-zA-Z]{2})*.json$|^[a-zA-Z]{2}(-[a-zA-z]{4})*.json$/
locales.forEach((locale) => {
it(`for ${locale}`, () => {
expect(locale).toMatch(regex)
})
})
})
describe('should include full keys', () => {
const structure = require('../schema/locale.json') as Language
locales.forEach((locale) => {
it(`for ${locale}`, () => {
expect(includeAllKeys(require(`../locales/${locale}`), structure)).toBeTruthy()
})
})
})
describe("should not include extra keys", () => {
const structure = require('../schema/locale.json') as Language
locales.forEach((locale) => {
it(`for ${locale}`, () => {
expect(excludeKeys(require(`../locales/${locale}`), structure)).toBeTruthy()
})
})
})