-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make
parsePages
compatible with typescript decorators
- Loading branch information
Showing
10 changed files
with
360 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Configuration as NuxtConfiguration } from '@nuxt/types' | ||
import { NuxtVueI18n } from '../../../types/vue'; | ||
|
||
const nuxtI18nOptions: NuxtVueI18n.Options.AllOptionsInterface { | ||
locales: [ | ||
{ code: 'en', iso: 'en-US', name: 'English' }, | ||
{ code: 'pl', iso: 'pl-PL', name: 'Polish' } | ||
], | ||
defaultLocale: 'en', | ||
parsePages: true | ||
} | ||
|
||
const config: NuxtConfiguration = { | ||
buildModules: ['@nuxt/typescript-build'], | ||
modules: ['nuxt-i18n', nuxtI18nOptions], | ||
}; | ||
|
||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<template> | ||
<div> | ||
Home | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { Component, Vue } from 'vue-property-decorator' | ||
@Component({ | ||
nuxtI18n: { | ||
paths: { | ||
pl: '/polish' | ||
} | ||
}, | ||
head() { | ||
return { | ||
title: 'Home' | ||
} | ||
} | ||
}) | ||
export default class Home extends Vue { | ||
async mounted() { | ||
await (this as any).$message.info('This is a normal message') | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<template> | ||
<div> | ||
Home | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import Vue from 'vue'; | ||
function fail() {} | ||
export default Vue.extend({ | ||
nuxtI18n: a, | ||
head() { | ||
return { | ||
title: 'invalid options' | ||
} | ||
} | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import path from 'path' | ||
|
||
describe('parsePages', () => { | ||
test('parses in-component options', async () => { | ||
const { extractComponentOptions } = await import('../src/helpers/components') | ||
const options = extractComponentOptions(path.join(__dirname, './fixture/typescript/pages/index.vue')) | ||
expect(options).toHaveProperty('paths') | ||
expect(options.paths).toHaveProperty('pl') | ||
expect(options.paths.pl).toBe('/polish') | ||
}) | ||
|
||
test('triggers warning with invalid in-component options', async () => { | ||
const { extractComponentOptions } = await import('../src/helpers/components') | ||
|
||
const spy = jest.spyOn(console, 'warn').mockImplementation(() => {}) | ||
const options = extractComponentOptions(path.join(__dirname, './fixture/typescript/pages/invalidOptions.vue')) | ||
expect(spy.mock.calls[0][0]).toContain('Error parsing') | ||
spy.mockRestore() | ||
|
||
expect(Object.keys(options).length).toBe(0) | ||
}) | ||
}) |
Oops, something went wrong.