diff --git a/app/javascript/dashboard/routes/dashboard/settings/macros/specs/MacroProperties.spec.js b/app/javascript/dashboard/routes/dashboard/settings/macros/specs/MacroProperties.spec.js index 31218cbba..edd1b53d6 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/macros/specs/MacroProperties.spec.js +++ b/app/javascript/dashboard/routes/dashboard/settings/macros/specs/MacroProperties.spec.js @@ -1,6 +1,9 @@ import { shallowMount } from '@vue/test-utils'; +import { withFullI18n } from 'test-i18n'; import MacroProperties from '../MacroProperties.vue'; +withFullI18n(); + const mountComponent = props => shallowMount(MacroProperties, { props: { diff --git a/vitest.config.ts b/vitest.config.ts index 5533f3998..6656bb159 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,4 +1,5 @@ /// +import path from 'path'; import { defineConfig } from 'vitest/config'; import vue from '@vitejs/plugin-vue'; import { aliases, vueOptions } from './vite.shared'; @@ -6,7 +7,9 @@ import yaml from '@rollup/plugin-yaml'; export default defineConfig({ plugins: [vue(vueOptions), yaml()], - resolve: { alias: aliases }, + resolve: { + alias: { ...aliases, 'test-i18n': path.resolve('./vitest.i18n.js') }, + }, test: { environment: 'jsdom', include: ['app/**/*.{test,spec}.?(c|m)[jt]s?(x)'], diff --git a/vitest.i18n.js b/vitest.i18n.js new file mode 100644 index 000000000..f0ef7d4ca --- /dev/null +++ b/vitest.i18n.js @@ -0,0 +1,21 @@ +import { config } from '@vue/test-utils'; +import { createI18n } from 'vue-i18n'; +import i18nMessages from 'dashboard/i18n'; +import FloatingVue from 'floating-vue'; + +/** + * Replaces the empty i18n instance from the global setup with the real + * messages. Call it at the top of the spec, outside of hooks. + * See vitest.setup.js. + */ +export function withFullI18n(locale = 'en') { + const i18n = createI18n({ + legacy: false, + locale, + messages: i18nMessages, + }); + + config.global.plugins = [i18n, FloatingVue]; + + return i18n; +} diff --git a/vitest.setup.js b/vitest.setup.js index 1bed8ee3e..12516be93 100644 --- a/vitest.setup.js +++ b/vitest.setup.js @@ -1,12 +1,15 @@ import { config } from '@vue/test-utils'; import { createI18n } from 'vue-i18n'; -import i18nMessages from 'dashboard/i18n'; import FloatingVue from 'floating-vue'; +// No messages: loading them here would pull 2537 locale files into every spec. +// Specs asserting on translated copy should use withFullI18n from vitest.i18n. const i18n = createI18n({ legacy: false, locale: 'en', - messages: i18nMessages, + messages: {}, + missingWarn: false, + fallbackWarn: false, }); config.global.plugins = [i18n, FloatingVue];