From 0de1352b12cccc4ec8597fbfe18ec73aae60aa9f Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Fri, 22 May 2020 03:13:46 +0900 Subject: [PATCH] refactor --- src/errors.ts | 5 ++++- src/warnings.ts | 12 ++++++------ test/diretive.test.ts | 16 ++++++++++++---- test/legacy.test.ts | 17 +++++++++++++---- test/plugin.test.ts | 5 ++++- 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/errors.ts b/src/errors.ts index dfc4eaddb..aa6703ae0 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -25,7 +25,10 @@ export const enum I18nErrorCodes { __EXTEND_POINT__ } -export function createI18nError(code: I18nErrorCodes, ...args: unknown[]): I18nError { +export function createI18nError( + code: I18nErrorCodes, + ...args: unknown[] +): I18nError { return createCompileError( code, null, diff --git a/src/warnings.ts b/src/warnings.ts index 5f9bb51c8..69e18ef84 100644 --- a/src/warnings.ts +++ b/src/warnings.ts @@ -13,12 +13,12 @@ export const enum I18nWarnCodes { export const warnMessages: { [code: number]: string } = { [I18nWarnCodes.FALLBACK_TO_ROOT]: `Fall back to {type} '{key}' with root locale.`, - [I18nWarnCodes.NOT_SUPPORTED_PRESERVE]: `not supportted 'preserve'.`, - [I18nWarnCodes.NOT_SUPPORTED_FORMATTER]: `not supportted 'formatter'.`, - [I18nWarnCodes.NOT_SUPPORTED_PRESERVE_DIRECTIVE]: `not supportted 'preserveDirectiveContent'.`, - [I18nWarnCodes.NOT_SUPPORTED_GET_CHOICE_INDEX]: `not supportted 'getChoiceIndex'.`, - [I18nWarnCodes.COMPONENT_NAME_LEGACY_COMPATIBLE]: `component name legacy compatible: '{name}' -> 'i18n'`, - [I18nWarnCodes.NOT_FOUND_PARENT_COMPOSER]: `not found parent composer. use the global composer` + [I18nWarnCodes.NOT_SUPPORTED_PRESERVE]: `Not supportted 'preserve'.`, + [I18nWarnCodes.NOT_SUPPORTED_FORMATTER]: `Not supportted 'formatter'.`, + [I18nWarnCodes.NOT_SUPPORTED_PRESERVE_DIRECTIVE]: `Not supportted 'preserveDirectiveContent'.`, + [I18nWarnCodes.NOT_SUPPORTED_GET_CHOICE_INDEX]: `Not supportted 'getChoiceIndex'.`, + [I18nWarnCodes.COMPONENT_NAME_LEGACY_COMPATIBLE]: `Component name legacy compatible: '{name}' -> 'i18n'`, + [I18nWarnCodes.NOT_FOUND_PARENT_COMPOSER]: `Not found parent composer. use the global composer.` } export function getWarnMessage( diff --git a/test/diretive.test.ts b/test/diretive.test.ts index cdd7fc883..ada1ab0ef 100644 --- a/test/diretive.test.ts +++ b/test/diretive.test.ts @@ -88,7 +88,9 @@ test('object literal', async () => { const name = ref('kazupon') const t = resolveDirective('t') return () => { - return withDirectives(h('p'), [[t, { path: 'hello', locale: 'ja', args: { name: name.value } }]]) + return withDirectives(h('p'), [ + [t, { path: 'hello', locale: 'ja', args: { name: name.value } }] + ]) } } }) @@ -146,7 +148,9 @@ test('preserve modifier', async () => { const wrapper = await mount(App, i18n) expect(mockWarn).toHaveBeenCalledTimes(1) - expect(mockWarn.mock.calls[0][0]).toEqual(getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_PRESERVE)) + expect(mockWarn.mock.calls[0][0]).toEqual( + getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_PRESERVE) + ) }) test('legacy mode', async () => { @@ -202,7 +206,9 @@ describe('errors', () => { } catch (e) { error = e } - expect(error.message).toEqual(errorMessages[I18nErrorCodes.NOT_FOUND_COMPOSER]) + expect(error.message).toEqual( + errorMessages[I18nErrorCodes.NOT_FOUND_COMPOSER] + ) }) test(errorMessages[I18nErrorCodes.REQUIRED_VALUE], async () => { @@ -231,7 +237,9 @@ describe('errors', () => { } catch (e) { error = e } - expect(error.message).toEqual(format(errorMessages[I18nErrorCodes.REQUIRED_VALUE], 'path')) + expect(error.message).toEqual( + format(errorMessages[I18nErrorCodes.REQUIRED_VALUE], 'path') + ) }) test(errorMessages[I18nErrorCodes.INVALID_VALUE], async () => { diff --git a/test/legacy.test.ts b/test/legacy.test.ts index 0dfeec282..d4d3353b2 100644 --- a/test/legacy.test.ts +++ b/test/legacy.test.ts @@ -9,6 +9,7 @@ import { warn } from '../src/utils' import { createVueI18n } from '../src/legacy' import { errorMessages, I18nErrorCodes } from '../src/errors' +import { getWarnMessage, I18nWarnCodes } from '../src/warnings' test('locale', () => { const i18n = createVueI18n() @@ -55,9 +56,15 @@ test('formatter', () => { } } expect(mockWarn).toHaveBeenCalledTimes(3) - expect(mockWarn.mock.calls[0][0]).toEqual(`not supportted 'formatter'.`) - expect(mockWarn.mock.calls[1][0]).toEqual(`not supportted 'formatter'.`) - expect(mockWarn.mock.calls[2][0]).toEqual(`not supportted 'formatter'.`) + expect(mockWarn.mock.calls[0][0]).toEqual( + getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_FORMATTER) + ) + expect(mockWarn.mock.calls[1][0]).toEqual( + getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_FORMATTER) + ) + expect(mockWarn.mock.calls[2][0]).toEqual( + getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_FORMATTER) + ) }) test('missing', () => { @@ -452,7 +459,9 @@ test('getChoiceIndex', () => { const i18n = createVueI18n({}) i18n.getChoiceIndex(1, 2) - expect(mockWarn.mock.calls[0][0]).toEqual(`not supportted 'getChoiceIndex'.`) + expect(mockWarn.mock.calls[0][0]).toEqual( + getWarnMessage(I18nWarnCodes.NOT_SUPPORTED_GET_CHOICE_INDEX) + ) }) test('warnHtmlInMessage', () => { diff --git a/test/plugin.test.ts b/test/plugin.test.ts index 8da64eb83..24990bbf1 100644 --- a/test/plugin.test.ts +++ b/test/plugin.test.ts @@ -13,6 +13,7 @@ import { warn } from '../src/utils' import { createApp } from 'vue' import { I18n, I18nInternal } from '../src/i18n' import { apply } from '../src/plugin' +import { getWarnMessage, I18nWarnCodes } from '../src/warnings' describe('useI18nComponentName option', () => { test('default', () => { @@ -36,7 +37,9 @@ describe('useI18nComponentName option', () => { apply(app, i18n, { useI18nComponentName: true }) expect(mockWarn).toHaveBeenCalled() expect(mockWarn.mock.calls[0][0]).toEqual( - `component name legacy compatible: 'i18n-t' -> 'i18n'` + getWarnMessage(I18nWarnCodes.COMPONENT_NAME_LEGACY_COMPATIBLE, { + name: 'i18n-t' + }) ) }) })