Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
xiCO2k committed May 6, 2024
1 parent 3f3962e commit 05ac140
Show file tree
Hide file tree
Showing 7 changed files with 4,293 additions and 5,749 deletions.
17 changes: 0 additions & 17 deletions jest.config.js

This file was deleted.

9,970 changes: 4,256 additions & 5,714 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,26 @@
"devDependencies": {
"@babel/cli": "^7.23.4",
"@babel/core": "^7.23.7",
"@babel/preset-env": "^7.23.7",
"@types/jest": "^27.5.2",
"@babel/preset-env": "^7.23.8",
"@types/jest": "^29.5.11",
"@vitejs/plugin-vue": "^5.0.2",
"@vue/babel-plugin-jsx": "^1.1.5",
"@vue/test-utils": "^2.4.3",
"babel-jest": "^27.5.1",
"babel-jest": "^29.7.0",
"babel-plugin-transform-vite-meta-env": "^1.0.3",
"jest": "^27.5.1",
"laravel-mix": "^6.0.49",
"prettier": "^2.8.8",
"prettier": "^3.1.1",
"rimraf": "^5.0.5",
"source-map": "^0.7.4",
"ts-jest": "^27.1.5",
"ts-loader": "^9.5.1",
"tsc-multi": "^1.1.0",
"typescript": "^4.9.5",
"vite": "^4.5.1"
"typescript": "^5.3.3",
"vite": "^5.0.11",
"vite-tsconfig-paths": "^4.2.3",
"vitest": "^1.1.3"
},
"dependencies": {
"php-parser": "3.1.3",
"php-parser": "3.1.5",
"vue": "^3.2.45"
},
"lint-staged": {
Expand Down
6 changes: 3 additions & 3 deletions test/class.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ it('allows resetting all data', async () => {
})

it('calls onLoad when loaded', async () => {
const onLoadFunction = jest.fn()
const onLoadFunction = vi.fn()

const i18n = new I18n({
lang: 'pt',
Expand All @@ -86,7 +86,7 @@ it('calls onLoad when loaded', async () => {
})

it('can override missing translations with fallback language translations', async () => {
const onLoadFunction = jest.fn()
const onLoadFunction = vi.fn()
const i18n = new I18n({
fallbackLang: 'en',
fallbackMissingTranslations: true,
Expand All @@ -101,4 +101,4 @@ it('can override missing translations with fallback language translations', asyn
expect(i18n.trans('Welcome!')).toBe('Bem-vindo!')

expect(i18n.trans('English only.')).toBe('English only.')
})
})
17 changes: 11 additions & 6 deletions test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mount } from '@vue/test-utils'
import {mount} from "@vue/test-utils";
import { i18nVue } from '../src'
import { generateFiles, parseAll } from '../src/loader'

Expand All @@ -9,7 +9,10 @@ global.mountPlugin = async (template = '<div />', lang = 'pt', fallbackLang = 'p
lang,
fallbackLang,
fallbackMissingTranslations,
resolve: lang => import(`./fixtures/lang/${lang}.json`),
resolve: async lang => {
const langs = import.meta.glob('./fixtures/lang/*.json');
return await langs[`./fixtures/lang/${lang}.json`]();
},
}]]
}
});
Expand All @@ -25,7 +28,10 @@ global.mountPluginWithRequire = async (template = '<div />', lang = 'pt', fallba
plugins: [[i18nVue, {
lang,
fallbackLang,
resolve: (lang) => require(`./fixtures/lang/${lang}.json`),
resolve: (lang) => {
const langs = import.meta.glob('./fixtures/lang/*.json', { eager: true });
return langs[`./fixtures/lang/${lang}.json`].default;
},
}]]
}
});
Expand All @@ -37,9 +43,8 @@ global.mountPluginWithRequire = async (template = '<div />', lang = 'pt', fallba

global.mixLoader = () => {
const langPath = __dirname + '/fixtures/lang/';

generateFiles(langPath, parseAll(langPath));

process.env = Object.assign(process.env, {
LARAVEL_VUE_I18N_HAS_PHP: 'true',
});
process.env.LARAVEL_VUE_I18N_HAS_PHP = true;
}
1 change: 1 addition & 0 deletions test/translate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ it('translates a possible nested item, and if not exists check on the root level
});

it('translates a nested file item while using "/" and "." at the same time as a delimiter', async () => {
global.mixLoader();
await global.mountPlugin()

expect(trans('nested/cars/car.is_electric')).toBe('É elétrico?');
Expand Down
12 changes: 12 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import viteTsconfigPaths from 'vite-tsconfig-paths';

export default defineConfig({
plugins: [vue(), viteTsconfigPaths()],
test: {
globals: true,
environment: 'jsdom',
setupFiles: './test/setup.ts',
},
});

0 comments on commit 05ac140

Please sign in to comment.