Skip to content

Commit

Permalink
fix: add tests for forwardedHost change, deprecate setting instead of…
Browse files Browse the repository at this point in the history
… removing
  • Loading branch information
rchl committed Mar 15, 2020
1 parent 2a17c99 commit 3f4d135
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/index.js
Expand Up @@ -78,6 +78,11 @@ module.exports = function (userOptions) {
console.warn('[' + options.MODULE_NAME + '] The `differentDomains` option and `no_prefix` strategy are not compatible. Change strategy or disable `differentDomains` option.')
}

if ('forwardedHost' in options) {
// eslint-disable-next-line no-console
console.warn('[' + options.MODULE_NAME + '] The `forwardedHost` option is deprecated. You can safely remove it. See: https://github.com/nuxt-community/nuxt-i18n/pull/630.')
}

// Plugins
for (const file of requiredPlugins) {
this.addPlugin({
Expand Down
28 changes: 25 additions & 3 deletions test/module.test.js
Expand Up @@ -812,7 +812,7 @@ describe('differentDomains enabled', () => {
await nuxt.close()
})

test('matches domain\'s locale (en)', async () => {
test('host matches locale\'s domain (en)', async () => {
const requestOptions = {
headers: {
Host: 'en.nuxt-app.localhost'
Expand All @@ -824,7 +824,7 @@ describe('differentDomains enabled', () => {
await expect(dom.querySelector('head meta[property="og-locale"]')).toBe(null)
})

test('matches domain\'s locale (fr)', async () => {
test('host matches locale\'s domain (fr)', async () => {
const requestOptions = {
headers: {
Host: 'fr.nuxt-app.localhost'
Expand All @@ -833,7 +833,29 @@ describe('differentDomains enabled', () => {
const html = await get('/', requestOptions)
const dom = getDom(html)
await expect(dom.querySelector('body').textContent).toContain('page: Accueil')
await expect(dom.querySelector('head meta[property="og-locale"]')).toBe(null)
})

test('x-forwarded-host does not match locale\'s domain', async () => {
const requestOptions = {
headers: {
'X-Forwarded-Host': 'xx.nuxt-app.localhost'
}
}
const html = await get('/', requestOptions)
const dom = getDom(html)
// Falls back to english.
await expect(dom.querySelector('body').textContent).toContain('page: Homepage')
})

test('x-forwarded-host does match locale\'s domain (fr)', async () => {
const requestOptions = {
headers: {
'X-Forwarded-Host': 'fr.nuxt-app.localhost'
}
}
const html = await get('/', requestOptions)
const dom = getDom(html)
await expect(dom.querySelector('body').textContent).toContain('page: Accueil')
})
})

Expand Down
1 change: 1 addition & 0 deletions types/nuxt-i18n.d.ts
Expand Up @@ -46,6 +46,7 @@ declare namespace NuxtVueI18n {
defaultLocale?: null | Locale
locales?: Array<Locale | LocaleObject>
differentDomains?: boolean
forwardedHost?: boolean
onLanguageSwitched?: (oldLocale: string, newLocale: string) => void
}

Expand Down

0 comments on commit 3f4d135

Please sign in to comment.