-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
843 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { readdirSync } from 'node:fs'; | ||
import { join as joinPath } from 'path'; | ||
|
||
const getDirectories = (source: string) => | ||
readdirSync(source, { withFileTypes: true }) | ||
.filter((dirent) => dirent.isDirectory()) | ||
.map((dirent) => dirent.name); | ||
|
||
export function getLanguages(parent: string) { | ||
const path = joinPath(parent, 'lang'); | ||
return getDirectories(path); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { statSync } from 'fs'; | ||
import { existsSync } from 'node:fs'; | ||
import { describe, expect, it } from 'vitest'; | ||
import type { z } from 'zod'; | ||
|
||
import { FileReader } from '../../../src/file/FileReader'; | ||
|
||
export function testFileRead( | ||
file: string, | ||
path: string, | ||
schema: z.ZodTypeAny, | ||
): boolean { | ||
describe(`${file} - "${path}"`, () => { | ||
it('should exist', () => { | ||
const exists = existsSync(path); | ||
expect(exists).toBeTruthy(); | ||
}); | ||
|
||
it('should be a file', () => { | ||
const stat = statSync(path); | ||
expect(stat.isFile()).toBeTruthy(); | ||
}); | ||
|
||
it('should match the schema and conf format', async () => { | ||
const reader = new FileReader(path, schema); | ||
try { | ||
await reader.read(); | ||
} catch (error) { | ||
expect(error).toBeUndefined(); | ||
} | ||
}); | ||
}); | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { BlacklistMessagesSchema } from '../../../src/blacklist/message/read/BlacklistMessagesSchema'; | ||
import { testMessageFile } from './helpers/testMessageFile'; | ||
|
||
testMessageFile('blacklist', BlacklistMessagesSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { GeneralMessagesSchema } from '../../../src/hermes/message/messages/general/GeneralMessagesSchema'; | ||
import { testMessageFile } from './helpers/testMessageFile'; | ||
|
||
testMessageFile('general', GeneralMessagesSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { OfferMessagesSchema } from '../../../src/offer/message/read/OfferMessagesSchema'; | ||
import { testMessageFile } from './helpers/testMessageFile'; | ||
|
||
testMessageFile('offer', OfferMessagesSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { RequestMessagesSchema } from '../../../src/request/message/read/RequestMessagesSchema'; | ||
import { testMessageFile } from './helpers/testMessageFile'; | ||
|
||
testMessageFile('request', RequestMessagesSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { TagsMessagesSchema } from '../../../src/tag/message/TagsMessagesSchema'; | ||
import { testMessageFile } from './helpers/testMessageFile'; | ||
|
||
testMessageFile('tags', TagsMessagesSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { getLanguages } from '../../helpers/getLanguages'; | ||
|
||
let cache: string[] | undefined; | ||
|
||
export function getMessagesLanguages() { | ||
if (!cache) { | ||
cache = getLanguages('messages'); | ||
} | ||
return cache; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { join as joinPath } from 'path'; | ||
import type { z } from 'zod'; | ||
|
||
import { testFileRead } from '../../helpers/testFileRead'; | ||
import { getMessagesLanguages } from './getMessagesLanguages'; | ||
|
||
const languages = getMessagesLanguages(); | ||
|
||
export function testMessageFile(file: string, schema: z.ZodTypeAny) { | ||
for (const language of languages) { | ||
const path = joinPath('lang', language, `${file}.conf`); | ||
testFileRead(`${file} messages (${language})`, path, schema); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,8 @@ | |
"strict": true | ||
}, | ||
"include": [ | ||
"src" | ||
"src", | ||
"test" | ||
], | ||
"exclude": [ | ||
"dist", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
name: 'Hermes', | ||
passWithNoTests: true, | ||
}, | ||
}); |