Skip to content

Commit 5208bc4

Browse files
committed
test: Add missing tests cases.
1 parent 79235e0 commit 5208bc4

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

src/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ export function loadLanguageAsync(lang: string): Promise<string | void> {
5858
const data: LanguageInterface = { lang, messages }
5959
loaded.push(data)
6060
return setLanguage(data)
61-
})
62-
.catch((err) => {
63-
throw new TypeError(`Cannot load lang: ${lang} file: ${err.message}`)
64-
})
61+
});
6562
}
6663

6764
/**

src/loader.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@ import { Engine } from 'php-parser'
55
export const hasPhpTranslations = (folderPath: string): boolean => {
66
folderPath = folderPath.replace(/[\\/]$/, '') + path.sep
77

8-
const folders = fs
9-
.readdirSync(folderPath)
10-
.filter((file) => fs.statSync(folderPath + path.sep + file).isDirectory())
11-
.sort()
8+
try {
9+
const folders = fs
10+
.readdirSync(folderPath)
11+
.filter((file) => fs.statSync(folderPath + path.sep + file).isDirectory())
12+
.sort()
1213

13-
for (const folder of folders) {
14-
const lang = {}
14+
for (const folder of folders) {
15+
const lang = {}
1516

16-
const files = fs.readdirSync(folderPath + path.sep + folder).filter((file) => /\.php$/.test(file))
17+
const files = fs.readdirSync(folderPath + path.sep + folder).filter((file) => /\.php$/.test(file))
1718

18-
if (files.length > 0) {
19-
return true
19+
if (files.length > 0) {
20+
return true
21+
}
2022
}
23+
} catch (e) {
24+
console.log(e.message)
2125
}
2226

2327
return false

test/fixtures/lang/en/auth.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
'level1' => [
88
'level2' => 'baren'
99
]
10-
]
10+
],
11+
'arr' => ['foo', 'bar'],
1112
];

test/loader.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ it('transform nested .php lang files to .json', () => {
3434
expect(langEn['foo.level1.level2']).toBe('baren');
3535
});
3636

37-
it('checks if there is .php translations', () => {
38-
const hasTranslations = hasPhpTranslations(__dirname + '/fixtures/lang/');
37+
it('transforms simple index array to .json', () => {
38+
const lang = parse(fs.readFileSync(__dirname + '/fixtures/lang/en/auth.php').toString());
39+
expect(lang['arr.0']).toBe('foo');
40+
expect(lang['arr.1']).toBe('bar');
41+
});
3942

40-
expect(hasTranslations).toBe(true);
43+
it('checks if there is .php translations', () => {
44+
expect(hasPhpTranslations(__dirname + '/fixtures/lang/')).toBe(true);
45+
expect(hasPhpTranslations(__dirname + '/fixtures/wronglangfolder/')).toBe(false);
4146
});

test/translate.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ it('translates with "trans" helper', async () => {
2020
it('returns the same message if there is no resolve method provided', async () => {
2121
const wrapper = mount({ template: `<h1>{{ $t('Welcome!') }}</h1>` }, {
2222
global: {
23-
plugins: [[i18nVue, {
24-
resolve: () => new Promise((resolve) => resolve({ default: {} }))
25-
}]]
23+
plugins: [i18nVue]
2624
}
2725
});
2826

0 commit comments

Comments
 (0)