Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a2f2e90

Browse files
add locale validate
1 parent f074859 commit a2f2e90

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

‎__test__/locale.spec.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,32 @@ import { readdirSync } from 'node:fs'
44
import { Language } from '../utils/getLanguage'
55
import { includeAllKeys, excludeKeys } from './utils'
66

7-
const locales = readdirSync(resolve(__dirname, '../locales'))
7+
const locales = readdirSync(resolve(__dirname, '../locales')).filter((file) => {
8+
return file.includes('.json') // exclude unnecessary files
9+
})
10+
11+
describe('should match name regex', () => {
12+
locales.forEach((locale) => {
13+
it(`for ${locale}`, () => {
14+
expect(locale).toMatch(/^[a-zA-Z]{2}(-[a-zA-Z]{2})*.json$/)
15+
})
16+
})
17+
})
818

919
describe('should include full keys', () => {
10-
const structure: Language = require('../schema/locale.json')
11-
locales.forEach((locale) => {
12-
it(`for ${locale}`, () => {
13-
expect(includeAllKeys(require(`../locales/${locale}`), structure)).toBeTruthy()
14-
})
20+
const structure: Language = require('../schema/locale.json')
21+
locales.forEach((locale) => {
22+
it(`for ${locale}`, () => {
23+
expect(includeAllKeys(require(`../locales/${locale}`), structure)).toBeTruthy()
1524
})
25+
})
1626
})
1727

18-
describe("shouldn't include unnecessary keys", () => {
19-
const structure: Language = require('../schema/locale.json')
20-
locales.forEach((locale) => {
21-
it(`for ${locale}`, () => {
22-
expect(excludeKeys(require(`../locales/${locale}`), structure)).toBeTruthy()
23-
})
28+
describe("should not include unnecessary keys", () => {
29+
const structure: Language = require('../schema/locale.json')
30+
locales.forEach((locale) => {
31+
it(`for ${locale}`, () => {
32+
expect(excludeKeys(require(`../locales/${locale}`), structure)).toBeTruthy()
2433
})
25-
})
34+
})
35+
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /