Skip to content

Commit

Permalink
test: refactor and merge similar tests (#2886)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede committed Mar 28, 2024
1 parent b09f118 commit e234134
Show file tree
Hide file tree
Showing 24 changed files with 100 additions and 281 deletions.
10 changes: 10 additions & 0 deletions specs/basic_usage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,4 +624,14 @@ describe('basic usage', async () => {
expect(await getText(page, '#install-module-locale')).toEqual('Installer module locale works!')
expect(await getText(page, '#install-module-vue-i18n')).toEqual('Installer module vue-i18n works!')
})

describe('experimental.autoImportTranslationFunctions', async () => {
test('can use `$t` in `<template>`', async () => {
const { consoleLogs } = await renderPage('/experimental/auto-import-translation-functions')

const logStrings = consoleLogs.map(x => x.text)
expect(logStrings).toContain('[autoImportTranslationFunctions][default]: Welcome')
expect(logStrings).toContain('[autoImportTranslationFunctions][fr]: Bienvenue')
})
})
})
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { test, expect, describe } from 'vitest'
import { fileURLToPath } from 'node:url'
import { setup, $fetch, undiciRequest } from './utils'
import { getDom } from './helper'
import { setup, $fetch, undiciRequest } from '../utils'
import { getDom } from '../helper'

await setup({
rootDir: fileURLToPath(new URL(`./fixtures/different_domains`, import.meta.url)),
rootDir: fileURLToPath(new URL(`../fixtures/different_domains`, import.meta.url)),
// overrides
nuxtConfig: {
extends: [fileURLToPath(new URL(`./fixtures/layers/layer-domain`, import.meta.url))],
extends: [fileURLToPath(new URL(`../fixtures/layers/layer-domain`, import.meta.url))],
runtimeConfig: {
public: {
i18n: {
Expand All @@ -20,6 +20,7 @@ await setup({
}
},
i18n: {
baseUrl: 'http://localhost:3000',
locales: [
{
code: 'en',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { test, expect, describe } from 'vitest'
import { fileURLToPath } from 'node:url'
import { setup, $fetch, undiciRequest } from './utils'
import { getDom } from './helper'
import { setup, $fetch, undiciRequest } from '../utils'
import { getDom } from '../helper'

await setup({
rootDir: fileURLToPath(new URL(`./fixtures/different_domains`, import.meta.url)),
rootDir: fileURLToPath(new URL(`../fixtures/different_domains`, import.meta.url)),
// overrides
nuxtConfig: {
i18n: {
baseUrl: 'http://localhost:3000',
locales: [
{
code: 'en',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { test, expect, describe } from 'vitest'
import { fileURLToPath } from 'node:url'
import { setup, $fetch, undiciRequest } from './utils'
import { getDom } from './helper'
import { setup, $fetch, undiciRequest } from '../utils'
import { getDom } from '../helper'

await setup({
rootDir: fileURLToPath(new URL(`./fixtures/different_domains`, import.meta.url)),
rootDir: fileURLToPath(new URL(`../fixtures/different_domains`, import.meta.url)),
// overrides
nuxtConfig: {
i18n: {
baseUrl: 'http://localhost:3000',
locales: [
{
code: 'en',
Expand Down
53 changes: 53 additions & 0 deletions specs/different_domains/no_ssr.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { test, expect } from 'vitest'
import { fileURLToPath } from 'node:url'
import { setup, url, createPage } from '../utils'
import { getText } from '../helper'

await setup({
rootDir: fileURLToPath(new URL(`../fixtures/different_domains`, import.meta.url)),
nuxtConfig: {
i18n: {
defaultLocale: 'fr',
differentDomains: true,
locales: [
{
code: 'en',
domain: 'en.nuxt-app.localhost'
},
{
code: 'fr',
domain: 'fr.nuxt-app.localhost'
},
{
code: 'nl',
domain: 'localhost'
}
],
strategy: 'no_prefix'
},
ssr: false
}
})

test('(#2313) detection locale from domain', async () => {
async function assertDifferentDomain(locale: string, browserLocale = 'en') {
const page = await createPage(url('/'), {
extraHTTPHeaders: {
'X-Forwarded-Host': `${locale}.nuxt-app.localhost`
},
locale: browserLocale
})

expect(await getText(page, '#lang-switcher-current-locale code')).toEqual(locale)
await page.close()
}

await assertDifferentDomain('en')
await assertDifferentDomain('fr', 'fr')
})

test('(#2334) should not redirect loop, when use no_prefix and ssr: false', async () => {
const page = await createPage(url('/'), { locale: 'fr' })

expect(await getText(page, '#lang-switcher-current-locale code')).toEqual('fr')
})
6 changes: 3 additions & 3 deletions specs/exclude_locales.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { setup } from './utils'
import { getText, renderPage } from './helper'

await setup({
rootDir: fileURLToPath(new URL(`./fixtures/locale_codes`, import.meta.url)),
rootDir: fileURLToPath(new URL(`./fixtures/basic`, import.meta.url)),
browser: true,
// overrides
nuxtConfig: {
Expand All @@ -19,8 +19,8 @@ await setup({
test('leave only English locale', async () => {
const { page } = await renderPage('/')

const locales = await page.locator('li')
const locales = await page.locator('#configured-locales-list li')

expect(await locales.count()).toEqual(1)
expect(await getText(page, 'li')).toMatch('en')
expect(await getText(page, '#configured-locales-list li')).toMatch('en')
})
37 changes: 0 additions & 37 deletions specs/experimental/auto_import_translation_functions.spec.ts

This file was deleted.

9 changes: 8 additions & 1 deletion specs/fixtures/basic/components/BasicUsage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { navigateTo } from '#imports'
import { useLocalePath, useSwitchLocalePath, useLocaleRoute, useI18n } from '#i18n'
const { locale } = useI18n()
const { locale, locales } = useI18n()
const localePath = useLocalePath()
const switchLocalePath = useSwitchLocalePath()
const localeRoute = useLocaleRoute()
Expand Down Expand Up @@ -35,6 +35,13 @@ function onClick() {
</form>
</div>
</section>
<section id="configured-locales-list">
<ul>
<li v-for="locale in locales" :key="locale.code">
{{ locale.code }}
</li>
</ul>
</section>
<section id="locale-path-usages">
<h3>localePath</h3>
<ul>
Expand Down
5 changes: 4 additions & 1 deletion specs/fixtures/basic_usage/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export default defineNuxtConfig({
i18n: {
vueI18n: './config/i18n.config.ts',
locales: ['en', 'fr'],
defaultLocale: 'en'
defaultLocale: 'en',
experimental: {
autoImportTranslationFunctions: true
}
// debug: true,
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script setup lang="ts">
console.log(`[autoImportTranslationFunctions][default]: ${$t('welcome')}`)
console.log(`[autoImportTranslationFunctions][fr]: ${$t('welcome', 1, { locale: 'fr' })}`)
</script>

<template>
<div>See console logs if experimental feature has logged without error</div>
</template>
5 changes: 0 additions & 5 deletions specs/fixtures/basic_usage/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ const switchLocalePath = useSwitchLocalePath()
const localeRoute = useLocaleRoute()
const appConfig = useAppConfig()
if (useNuxtApp().$config.public.i18n.experimental.autoImportTranslationFunctions) {
console.log(`[autoImportTranslationFunctions][default]: ${$t('welcome')}`)
console.log(`[autoImportTranslationFunctions][fr]: ${$t('welcome', 1, { locale: 'fr' })}`)
}
const category = ref({
title: 'Kirby',
slug: 'nintendo'
Expand Down
4 changes: 1 addition & 3 deletions specs/fixtures/different_domains/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default defineNuxtConfig({

i18n: {
lazy: false,
baseUrl: 'http://localhost:3000',
locales: [
{
code: 'en',
Expand All @@ -27,7 +26,6 @@ export default defineNuxtConfig({
domain: 'fr.nuxt-app.localhost'
}
],
defaultLocale: 'ja',
detectBrowserLanguage: false
defaultLocale: 'ja'
}
})
12 changes: 0 additions & 12 deletions specs/fixtures/locale_codes/app.vue

This file was deleted.

4 changes: 0 additions & 4 deletions specs/fixtures/locale_codes/i18n.config.ts

This file was deleted.

9 changes: 0 additions & 9 deletions specs/fixtures/locale_codes/layers/i18n-layer/i18n.config.ts

This file was deleted.

26 changes: 0 additions & 26 deletions specs/fixtures/locale_codes/layers/i18n-layer/nuxt.config.ts

This file was deleted.

33 changes: 0 additions & 33 deletions specs/fixtures/locale_codes/modules/ExtendI18n.ts

This file was deleted.

35 changes: 0 additions & 35 deletions specs/fixtures/locale_codes/nuxt.config.ts

This file was deleted.

0 comments on commit e234134

Please sign in to comment.