Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: load i18n in tests without typescript error #1167

Merged
merged 2 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr_ci_frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ jobs:
- name: Run Vitest - Component Testing
if: always()
working-directory: ./frontend
run: sudo yarn test
run: sudo yarn test --silent
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,10 @@ We use [Vitest](https://vitest.dev/) for component and unit testing. You can ru

```bash
# Within ./frontend:
yarn test
yarn test --silent
```
> [!NOTE]
> The `--silent` flag is to suppress a lot of warnings from existing issues between Nuxt and Vitest. If you need to see the warnings omit the `--silent` flag.

Please see the [frontend testing guide](FRONTEND_TESTING.md) for information on how to write component tests.

Expand Down
24 changes: 11 additions & 13 deletions frontend/test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import { useNuxtApp } from "#app";
import { config } from "@vue/test-utils";
import { createPinia, defineStore, setActivePinia } from "pinia";
import { createI18n } from "vue-i18n";
import en from "~/i18n/en-US.json" assert { type: "json" };

import type { UseColorModeFn } from "~/test/vitest-globals";

// Set up Pinia.
Expand All @@ -19,20 +21,16 @@ const useColorModeFn: UseColorModeFn = () => ({
globalThis.useColorModeMock = vi.fn(useColorModeFn);

// Set up I18n.
beforeAll(() => {
// https://github.com/nuxt/test-utils/issues/566
const nuxtApp = useNuxtApp();

config.global.plugins.push({
async install(app, ...options) {
// @ts-expect-error Typescript cannot detect Nuxt plugins.
const i18n = nuxtApp.vueApp.__VUE_I18N__;

await i18n.install(app, ...options);
},
});
// https://github.com/nuxt-modules/i18n/issues/2637#issuecomment-2233566361
const i18n = createI18n({
legacy: false,
locale: "en",
fallbackLocale: "en",
messages: Object.assign({ en }),
});

config.global.plugins.push(i18n);

afterEach(() => {
// Clean up Pinia.
setActivePinia(createPinia());
Expand Down
Loading