Skip to content

Commit

Permalink
test: remove logs and add baseUrl config (#3342)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede authored Feb 3, 2025
1 parent fd90056 commit b5f48dd
Show file tree
Hide file tree
Showing 21 changed files with 25 additions and 62 deletions.
8 changes: 4 additions & 4 deletions specs/basic_usage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('basic usage', async () => {
runtimeConfig: {
public: {
i18n: {
baseUrl: '',
baseUrl: 'http://localhost:3000',
skipSettingLocaleOnNavigate: undefined,
detectBrowserLanguage: undefined
}
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('basic usage', async () => {
)

expect(await getText(page, '#locale-head')).toMatchInlineSnapshot(
`"{ "htmlAttrs": { "lang": "en" }, "link": [ { "hid": "i18n-alt-en", "rel": "alternate", "href": "/nuxt-context-extension", "hreflang": "en" }, { "hid": "i18n-alt-fr", "rel": "alternate", "href": "/fr/nuxt-context-extension", "hreflang": "fr" }, { "hid": "i18n-alt-ja", "rel": "alternate", "href": "/ja/nuxt-context-extension", "hreflang": "ja" }, { "hid": "i18n-alt-ja-JP", "rel": "alternate", "href": "/ja/nuxt-context-extension", "hreflang": "ja-JP" }, { "hid": "i18n-alt-nl", "rel": "alternate", "href": "/nl/nuxt-context-extension", "hreflang": "nl" }, { "hid": "i18n-alt-nl-NL", "rel": "alternate", "href": "/nl/nuxt-context-extension", "hreflang": "nl-NL" }, { "hid": "i18n-alt-kr", "rel": "alternate", "href": "/kr/nuxt-context-extension", "hreflang": "kr" }, { "hid": "i18n-alt-kr-KO", "rel": "alternate", "href": "/kr/nuxt-context-extension", "hreflang": "kr-KO" }, { "hid": "i18n-xd", "rel": "alternate", "href": "/nuxt-context-extension", "hreflang": "x-default" }, { "hid": "i18n-can", "rel": "canonical", "href": "/nuxt-context-extension" } ], "meta": [ { "hid": "i18n-og-url", "property": "og:url", "content": "/nuxt-context-extension" }, { "hid": "i18n-og", "property": "og:locale", "content": "en" }, { "hid": "i18n-og-alt-fr", "property": "og:locale:alternate", "content": "fr" }, { "hid": "i18n-og-alt-ja-JP", "property": "og:locale:alternate", "content": "ja_JP" }, { "hid": "i18n-og-alt-nl-NL", "property": "og:locale:alternate", "content": "nl_NL" }, { "hid": "i18n-og-alt-kr-KO", "property": "og:locale:alternate", "content": "kr_KO" } ] }"`
`"{ "htmlAttrs": { "lang": "en" }, "link": [ { "hid": "i18n-alt-en", "rel": "alternate", "href": "http://localhost:3000/nuxt-context-extension", "hreflang": "en" }, { "hid": "i18n-alt-fr", "rel": "alternate", "href": "http://localhost:3000/fr/nuxt-context-extension", "hreflang": "fr" }, { "hid": "i18n-alt-ja", "rel": "alternate", "href": "http://localhost:3000/ja/nuxt-context-extension", "hreflang": "ja" }, { "hid": "i18n-alt-ja-JP", "rel": "alternate", "href": "http://localhost:3000/ja/nuxt-context-extension", "hreflang": "ja-JP" }, { "hid": "i18n-alt-nl", "rel": "alternate", "href": "http://localhost:3000/nl/nuxt-context-extension", "hreflang": "nl" }, { "hid": "i18n-alt-nl-NL", "rel": "alternate", "href": "http://localhost:3000/nl/nuxt-context-extension", "hreflang": "nl-NL" }, { "hid": "i18n-alt-kr", "rel": "alternate", "href": "http://localhost:3000/kr/nuxt-context-extension", "hreflang": "kr" }, { "hid": "i18n-alt-kr-KO", "rel": "alternate", "href": "http://localhost:3000/kr/nuxt-context-extension", "hreflang": "kr-KO" }, { "hid": "i18n-xd", "rel": "alternate", "href": "http://localhost:3000/nuxt-context-extension", "hreflang": "x-default" }, { "hid": "i18n-can", "rel": "canonical", "href": "http://localhost:3000/nuxt-context-extension" } ], "meta": [ { "hid": "i18n-og-url", "property": "og:url", "content": "http://localhost:3000/nuxt-context-extension" }, { "hid": "i18n-og", "property": "og:locale", "content": "en" }, { "hid": "i18n-og-alt-fr", "property": "og:locale:alternate", "content": "fr" }, { "hid": "i18n-og-alt-ja-JP", "property": "og:locale:alternate", "content": "ja_JP" }, { "hid": "i18n-og-alt-nl-NL", "property": "og:locale:alternate", "content": "nl_NL" }, { "hid": "i18n-og-alt-kr-KO", "property": "og:locale:alternate", "content": "kr_KO" } ] }"`
)
})

Expand Down Expand Up @@ -463,11 +463,11 @@ describe('basic usage', async () => {
// head tags - alt links are updated server side
const product1Html = await $fetch('/products/big-chair')
const product1Dom = getDom(product1Html)
expect(product1Dom.querySelector('#i18n-alt-nl').href).toEqual('/nl/products/grote-stoel')
expect(product1Dom.querySelector('#i18n-alt-nl').href).toEqual('http://localhost:3000/nl/products/grote-stoel')

const product2Html = await $fetch('/nl/products/rode-mok')
const product2dom = getDom(product2Html)
expect(product2dom.querySelector('#i18n-alt-en').href).toEqual('/products/red-mug')
expect(product2dom.querySelector('#i18n-alt-en').href).toEqual('http://localhost:3000/products/red-mug')
})

describe('language switching', async () => {
Expand Down
8 changes: 4 additions & 4 deletions specs/basic_usage_compat_4.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('basic usage - compatibilityVersion: 4', async () => {
runtimeConfig: {
public: {
i18n: {
baseUrl: '',
baseUrl: 'http://localhost:3000',
skipSettingLocaleOnNavigate: undefined,
detectBrowserLanguage: undefined
}
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('basic usage - compatibilityVersion: 4', async () => {
)

expect(await getText(page, '#locale-head')).toMatchInlineSnapshot(
`"{ "htmlAttrs": { "lang": "en" }, "link": [ { "hid": "i18n-alt-en", "rel": "alternate", "href": "/nuxt-context-extension", "hreflang": "en" }, { "hid": "i18n-alt-ja", "rel": "alternate", "href": "/ja/nuxt-context-extension", "hreflang": "ja" }, { "hid": "i18n-alt-ja-JP", "rel": "alternate", "href": "/ja/nuxt-context-extension", "hreflang": "ja-JP" }, { "hid": "i18n-alt-fr", "rel": "alternate", "href": "/fr/nuxt-context-extension", "hreflang": "fr" }, { "hid": "i18n-alt-fr-FR", "rel": "alternate", "href": "/fr/nuxt-context-extension", "hreflang": "fr-FR" }, { "hid": "i18n-alt-nl", "rel": "alternate", "href": "/nl/nuxt-context-extension", "hreflang": "nl" }, { "hid": "i18n-alt-nl-NL", "rel": "alternate", "href": "/nl/nuxt-context-extension", "hreflang": "nl-NL" }, { "hid": "i18n-alt-kr", "rel": "alternate", "href": "/kr/nuxt-context-extension", "hreflang": "kr" }, { "hid": "i18n-alt-kr-KO", "rel": "alternate", "href": "/kr/nuxt-context-extension", "hreflang": "kr-KO" }, { "hid": "i18n-xd", "rel": "alternate", "href": "/nuxt-context-extension", "hreflang": "x-default" }, { "hid": "i18n-can", "rel": "canonical", "href": "/nuxt-context-extension" } ], "meta": [ { "hid": "i18n-og-url", "property": "og:url", "content": "/nuxt-context-extension" }, { "hid": "i18n-og", "property": "og:locale", "content": "en" }, { "hid": "i18n-og-alt-ja-JP", "property": "og:locale:alternate", "content": "ja_JP" }, { "hid": "i18n-og-alt-fr-FR", "property": "og:locale:alternate", "content": "fr_FR" }, { "hid": "i18n-og-alt-nl-NL", "property": "og:locale:alternate", "content": "nl_NL" }, { "hid": "i18n-og-alt-kr-KO", "property": "og:locale:alternate", "content": "kr_KO" } ] }"`
`"{ "htmlAttrs": { "lang": "en" }, "link": [ { "hid": "i18n-alt-en", "rel": "alternate", "href": "http://localhost:3000/nuxt-context-extension", "hreflang": "en" }, { "hid": "i18n-alt-ja", "rel": "alternate", "href": "http://localhost:3000/ja/nuxt-context-extension", "hreflang": "ja" }, { "hid": "i18n-alt-ja-JP", "rel": "alternate", "href": "http://localhost:3000/ja/nuxt-context-extension", "hreflang": "ja-JP" }, { "hid": "i18n-alt-fr", "rel": "alternate", "href": "http://localhost:3000/fr/nuxt-context-extension", "hreflang": "fr" }, { "hid": "i18n-alt-fr-FR", "rel": "alternate", "href": "http://localhost:3000/fr/nuxt-context-extension", "hreflang": "fr-FR" }, { "hid": "i18n-alt-nl", "rel": "alternate", "href": "http://localhost:3000/nl/nuxt-context-extension", "hreflang": "nl" }, { "hid": "i18n-alt-nl-NL", "rel": "alternate", "href": "http://localhost:3000/nl/nuxt-context-extension", "hreflang": "nl-NL" }, { "hid": "i18n-alt-kr", "rel": "alternate", "href": "http://localhost:3000/kr/nuxt-context-extension", "hreflang": "kr" }, { "hid": "i18n-alt-kr-KO", "rel": "alternate", "href": "http://localhost:3000/kr/nuxt-context-extension", "hreflang": "kr-KO" }, { "hid": "i18n-xd", "rel": "alternate", "href": "http://localhost:3000/nuxt-context-extension", "hreflang": "x-default" }, { "hid": "i18n-can", "rel": "canonical", "href": "http://localhost:3000/nuxt-context-extension" } ], "meta": [ { "hid": "i18n-og-url", "property": "og:url", "content": "http://localhost:3000/nuxt-context-extension" }, { "hid": "i18n-og", "property": "og:locale", "content": "en" }, { "hid": "i18n-og-alt-ja-JP", "property": "og:locale:alternate", "content": "ja_JP" }, { "hid": "i18n-og-alt-fr-FR", "property": "og:locale:alternate", "content": "fr_FR" }, { "hid": "i18n-og-alt-nl-NL", "property": "og:locale:alternate", "content": "nl_NL" }, { "hid": "i18n-og-alt-kr-KO", "property": "og:locale:alternate", "content": "kr_KO" } ] }"`
)
})

Expand Down Expand Up @@ -463,11 +463,11 @@ describe('basic usage - compatibilityVersion: 4', async () => {
// head tags - alt links are updated server side
const product1Html = await $fetch('/products/big-chair')
const product1Dom = getDom(product1Html)
expect(product1Dom.querySelector('#i18n-alt-nl').href).toEqual('/nl/products/grote-stoel')
expect(product1Dom.querySelector('#i18n-alt-nl').href).toEqual('http://localhost:3000/nl/products/grote-stoel')

const product2Html = await $fetch('/nl/products/rode-mok')
const product2dom = getDom(product2Html)
expect(product2dom.querySelector('#i18n-alt-en').href).toEqual('/products/red-mug')
expect(product2dom.querySelector('#i18n-alt-en').href).toEqual('http://localhost:3000/products/red-mug')
})

describe('language switching', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect } from 'vitest'
import { test, expect, describe, beforeEach } from 'vitest'
import { fileURLToPath } from 'node:url'
import { setup, url } from '../utils'
import { getText, renderPage, startServerWithRuntimeConfig } from '../helper'
Expand Down
3 changes: 1 addition & 2 deletions specs/custom_route_paths/component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ test('can not access to disable route path', async () => {
expect(await page.locator('#link-ignore-disable').getAttribute('href')).toBe(null)

// disable direct url access
let res: Response | (Error & { status: () => number }) | null = null
let res: Awaited<ReturnType<typeof page.goto>> | (Error & { status: () => number }) | null = null
try {
// attempting to goto /fr/disable instead of /fr/ignore-routes/disable since
// that route has a catch all that would succeed
Expand All @@ -84,7 +84,6 @@ test('can not access to disable route path', async () => {
res = error as Error & { status: () => number }
}

console.log(res)
// 404
expect(res!.status()).toBe(404) // eslint-disable-line @typescript-eslint/no-non-null-assertion
})
4 changes: 2 additions & 2 deletions specs/custom_route_paths/module_configration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ test('can not access to pick route path', async () => {
expect(await page.locator('#link-history').getAttribute('href')).toBe(null)

// disable direct url access
let res: Response | (Error & { status: () => number }) | null = null
let res: Awaited<ReturnType<typeof page.goto>> | (Error & { status: () => number }) | null = null
try {
res = await page.goto(url('/fr/history'))
} catch (error: unknown) {
Expand All @@ -98,7 +98,7 @@ test('can not access to disable route path', async () => {
expect(await page.locator('#link-category').getAttribute('href')).toBe(null)

// disable direct url access
let res: Response | (Error & { status: () => number }) | null = null
let res: Awaited<ReturnType<typeof page.goto>> | (Error & { status: () => number }) | null = null
try {
res = await page.goto(url('/fr/category/test'))
} catch (error: unknown) {
Expand Down
2 changes: 1 addition & 1 deletion specs/experimental/scan_page_meta.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect } from 'vitest'
import { test, expect, describe } from 'vitest'
import { fileURLToPath } from 'node:url'
import { setup, url } from '../utils'
import { getText, renderPage } from '../helper'
Expand Down
2 changes: 1 addition & 1 deletion specs/experimental/switch_locale_path_link_ssr.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect } from 'vitest'
import { test, expect, describe } from 'vitest'
import { fileURLToPath } from 'node:url'
import { $fetch, setup } from '../utils'
import { getDom, gotoPath, renderPage, waitForURL } from '../helper'
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/basic_usage/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default defineNuxtConfig({
plugins: [`../plugins/i18nHooks.ts`],
i18n: {
restructureDir: false,
baseUrl: 'http://localhost:3000',
vueI18n: './config/i18n.config.ts',
locales: ['en', 'fr'],
defaultLocale: 'en',
Expand Down
1 change: 0 additions & 1 deletion specs/fixtures/basic_usage_compat_4/localeDetector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Detect based on query, cookie, header
export default defineI18nLocaleDetector((event, { defaultLocale }) => {
console.log('hello')
const query = tryQueryLocale(event, { lang: '' })
if (query) {
return query.toString()
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/basic_usage_compat_4/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default defineNuxtConfig({
plugins: [`../plugins/i18nHooks.ts`],
i18n: {
restructureDir: false,
baseUrl: 'http://localhost:3000',
vueI18n: './config/i18n.config.ts',
defaultLocale: 'en',
experimental: {
Expand Down
2 changes: 0 additions & 2 deletions specs/fixtures/issues/2590/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ useHead(() => ({
htmlAttrs: head.value.htmlAttrs
}))
console.log(head.value.htmlAttrs)
const availableLocales = computed(() => {
return (locales.value as LocaleObject[])
.filter(item => {
Expand Down
1 change: 1 addition & 0 deletions specs/fixtures/routing/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export default defineNuxtConfig({
modules: ['@nuxtjs/i18n'],

i18n: {
baseUrl: 'http://localhost:3000',
restructureDir: false,
locales: ['en', 'ja'],
detectBrowserLanguage: false
Expand Down
7 changes: 1 addition & 6 deletions specs/lazy_load/basic_lazy_load.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ describe('basic lazy loading', async () => {
test('dynamic locale files are not cached', async () => {
const { page } = await renderPage('/nl')

page.on('domcontentloaded', () => {
console.log('domcontentload triggered!')
})

// capture dynamicTime - simulates changing api response
const dynamicTime = await getText(page, '#dynamic-time')

Expand All @@ -45,7 +41,6 @@ describe('basic lazy loading', async () => {

// only default locales are fetched (en)
await page.goto(home)
console.log(setFromRequests())
expect(setFromRequests().filter(locale => locale.includes('fr') || locale.includes('nl'))).toHaveLength(0)

// wait for request after navigation
Expand Down Expand Up @@ -107,7 +102,7 @@ describe('basic lazy loading', async () => {
expect(await page.getAttribute('html', 'lang')).toEqual('fr-FR')
})

test('mutiple lazy loading', async () => {
test('multiple lazy loading', async () => {
const { page } = await renderPage('/en-GB')

// `en` base rendering
Expand Down
7 changes: 1 addition & 6 deletions specs/lazy_load/restructure.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ describe('basic lazy loading (restructure)', async () => {
test('dynamic locale files are not cached', async () => {
const { page } = await renderPage('/nl')

page.on('domcontentloaded', () => {
console.log('domcontentload triggered!')
})

// capture dynamicTime - simulates changing api response
const dynamicTime = await getText(page, '#dynamic-time')

Expand All @@ -45,7 +41,6 @@ describe('basic lazy loading (restructure)', async () => {

// only default locales are fetched (en)
await page.goto(home)
console.log(setFromRequests())
expect(setFromRequests().filter(locale => locale.includes('fr') || locale.includes('nl'))).toHaveLength(0)

// wait for request after navigation
Expand Down Expand Up @@ -107,7 +102,7 @@ describe('basic lazy loading (restructure)', async () => {
expect(await page.getAttribute('html', 'lang')).toEqual('fr-FR')
})

test('mutiple lazy loading', async () => {
test('multiple lazy loading', async () => {
const { page } = await renderPage('/en-GB')

// `en` base rendering
Expand Down
11 changes: 1 addition & 10 deletions specs/routing/composition.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,7 @@ await setup({
nuxtConfig: {
i18n: {
customRoutes: 'config',
pages: {
// 'categories/[id]': {
// en: 'categories/english',
// ja: 'categories/japanese'
// }
// '[...pathMatch]': {
// en: { pathMatch: 'not-found-english' },
// ja: { pathMatch: 'not-found-japanese' }
// }
}
pages: {}
}
}
})
Expand Down
11 changes: 1 addition & 10 deletions specs/routing/legacy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,7 @@ await setup({
i18n: {
vueI18n: 'i18n-legacy.config.ts',
customRoutes: 'config',
pages: {
// 'categories/[id]': {
// en: 'categories/english',
// ja: 'categories/japanese'
// }
// '[...pathMatch]': {
// en: { pathMatch: 'not-found-english' },
// ja: { pathMatch: 'not-found-japanese' }
// }
}
pages: {}
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion specs/routing_strategies/no_prefix.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, test, expect } from 'vitest'
import { describe, test, expect, beforeAll } from 'vitest'
import { fileURLToPath } from 'node:url'
import { setup, url } from '../utils'
import {
Expand Down
2 changes: 1 addition & 1 deletion specs/routing_strategies/prefix.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, test, expect } from 'vitest'
import { describe, test, expect, beforeEach } from 'vitest'
import { fileURLToPath } from 'node:url'
import { setup, url, fetch } from '../utils'
import { getText, getData, renderPage, waitForURL, startServerWithRuntimeConfig, gotoPath } from '../helper'
Expand Down
2 changes: 1 addition & 1 deletion specs/routing_strategies/root_redirect.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect } from 'vitest'
import { test, expect, describe } from 'vitest'
import { fileURLToPath } from 'node:url'
import { setup, url, fetch } from '../utils'
import { startServerWithRuntimeConfig } from '../helper'
Expand Down
1 change: 0 additions & 1 deletion specs/seo/baseUrl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ await setup({
// @ts-ignore
const headers = useRequestHeaders(['x-override-base-url'])
const xOverrideBaseUrl = headers['x-override-base-url']
console.log('xOverrideBaseUrl', xOverrideBaseUrl)
if (Array.isArray(xOverrideBaseUrl)) {
return xOverrideBaseUrl[0]
}
Expand Down
9 changes: 1 addition & 8 deletions specs/ssg/basic_lazy_load.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ describe('basic lazy loading', async () => {
test('dynamic locale files are not cached', async () => {
const { page } = await renderPage('/nl')

page.on('domcontentloaded', () => {
console.log('domcontentload triggered!')
})

// capture dynamicTime - simulates changing api response
const dynamicTime = await getText(page, '#dynamic-time')

Expand All @@ -46,7 +42,6 @@ describe('basic lazy loading', async () => {

// only default locales are fetched (en)
await page.goto(home)
console.log(setFromRequests())
expect(setFromRequests().filter(locale => locale.includes('fr') || locale.includes('nl'))).toHaveLength(0)

// wait for request after navigation
Expand Down Expand Up @@ -90,8 +85,6 @@ describe('basic lazy loading', async () => {
test('can access to prefix locale: /fr', async () => {
const { page } = await renderPage('/fr')

console.log(page.url())

// `fr` rendering
expect(await getText(page, '#home-header')).toEqual('Accueil')
expect(await getText(page, 'title')).toEqual('Accueil')
Expand All @@ -110,7 +103,7 @@ describe('basic lazy loading', async () => {
expect(await page.getAttribute('html', 'lang')).toEqual('fr-FR')
})

test('mutiple lazy loading', async () => {
test('multiple lazy loading', async () => {
const { page } = await renderPage('/en-GB')

// `en` base rendering
Expand Down

0 comments on commit b5f48dd

Please sign in to comment.