From 09e883ffb50a28316bcb6487db91cc10be57890f Mon Sep 17 00:00:00 2001 From: Christian Kaisermann Date: Thu, 23 Jan 2020 10:21:29 -0300 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20bump=20package=20json?= =?UTF-8?q?=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 8 +- package.json | 2 +- test/runtime/stores/format.test.ts | 112 ------------------------- test/runtime/stores/formatters.test.ts | 5 +- 4 files changed, 5 insertions(+), 122 deletions(-) delete mode 100644 test/runtime/stores/format.test.ts diff --git a/.gitignore b/.gitignore index f71570e..8092f29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,5 @@ node_modules *.log -dist/ -coverage/ -<<<<<<< HEAD +/coverage/ +/dist/ /types/ -======= -types/ ->>>>>>> feat: 🎸 add runtime typings diff --git a/package.json b/package.json index 39ebf99..3df6a28 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte-i18n", - "version": "2.2.4", + "version": "3.0.0-alpha.1", "main": "dist/runtime.cjs.js", "module": "dist/runtime.esm.js", "types": "types/runtime/index.d.ts", diff --git a/test/runtime/stores/format.test.ts b/test/runtime/stores/format.test.ts deleted file mode 100644 index b6de057..0000000 --- a/test/runtime/stores/format.test.ts +++ /dev/null @@ -1,112 +0,0 @@ -<<<<<<< HEAD:test/runtime/stores/format.test.ts -import { Formatter } from '../../../src/runtime/types' -import { $format } from '../../../src/runtime/stores/format' -import { init } from '../../../src/runtime/configs' -import { addMessages } from '../../../src/runtime/stores/dictionary' -import { $locale } from '../../../src/runtime/stores/locale' -======= -import { get } from 'svelte/store' - -import { - $format, - $formatTime, - $formatDate, - $formatNumber, -} from '../../../src/client/stores/formatters' -import { init } from '../../../src/client/configs' -import { addMessages } from '../../../src/client/stores/dictionary' -import { $locale } from '../../../src/client/stores/locale' -import { MessageFormatter } from '../../../src/client/types' -import { - TimeFormatter, - DateFormatter, - NumberFormatter, -} from '../../../src/client/types/index' ->>>>>>> feat: 🎸 make date,time and number formatters tree-shakeable:test/client/stores/formatters.test.ts - -let formatMessage: MessageFormatter -let formatTime: TimeFormatter -let formatDate: DateFormatter -let formatNumber: NumberFormatter -$locale.subscribe(() => { - formatMessage = get($format) - formatTime = get($formatTime) - formatDate = get($formatDate) - formatNumber = get($formatNumber) -}) - -addMessages('en', require('../../fixtures/en.json')) -addMessages('en-GB', require('../../fixtures/en-GB.json')) -addMessages('pt', require('../../fixtures/pt.json')) -addMessages('pt-BR', require('../../fixtures/pt-BR.json')) -addMessages('pt-PT', require('../../fixtures/pt-PT.json')) - -beforeEach(() => { - init({ fallbackLocale: 'en' }) -}) - -test('formats a message by its id and the current locale', () => { - expect(formatMessage({ id: 'form.field_1_name' })).toBe('Name') -}) - -test('formats a message by its id and the a passed locale', () => { - expect(formatMessage({ id: 'form.field_1_name', locale: 'pt' })).toBe('Nome') -}) - -test('formats a message with interpolated values', () => { - expect(formatMessage({ id: 'photos', values: { n: 0 } })).toBe( - 'You have no photos.' - ) - expect(formatMessage({ id: 'photos', values: { n: 1 } })).toBe( - 'You have one photo.' - ) - expect(formatMessage({ id: 'photos', values: { n: 21 } })).toBe( - 'You have 21 photos.' - ) -}) - -test('accepts a message id as first argument', () => { - expect(formatMessage('form.field_1_name')).toBe('Name') -}) - -test('accepts a message id as first argument and formatting options as second', () => { - expect(formatMessage('form.field_1_name', { locale: 'pt' })).toBe('Nome') -}) - -test('throws if no locale is set', () => { - $locale.set(null) - expect(() => formatMessage('form.field_1_name')).toThrow( - '[svelte-i18n] Cannot format a message without first setting the initial locale.' - ) -}) - -test('uses a missing message default value', () => { - expect(formatMessage('missing', { default: 'Missing Default' })).toBe( - 'Missing Default' - ) -}) - -test('warn on missing messages', () => { - const warn = global.console.warn - global.console.warn = jest.fn() - - formatMessage('missing') - - expect(console.warn).toBeCalledWith( - `[svelte-i18n] The message "missing" was not found in "en".` - ) - - global.console.warn = warn -}) - -describe('format utilities', () => { - test('time', () => { - expect(formatTime(new Date(2019, 0, 1, 20, 37))).toBe('8:37 PM') - }) - test('date', () => { - expect(formatDate(new Date(2019, 0, 1, 20, 37))).toBe('1/1/19') - }) - test('number', () => { - expect(formatNumber(123123123)).toBe('123,123,123') - }) -}) diff --git a/test/runtime/stores/formatters.test.ts b/test/runtime/stores/formatters.test.ts index 4b3da0b..cff89eb 100644 --- a/test/runtime/stores/formatters.test.ts +++ b/test/runtime/stores/formatters.test.ts @@ -1,4 +1,3 @@ - import { get } from 'svelte/store' import { @@ -10,13 +9,13 @@ import { import { init } from '../../../src/runtime/configs' import { addMessages } from '../../../src/runtime/stores/dictionary' import { $locale } from '../../../src/runtime/stores/locale' -import { MessageFormatter , +import { + MessageFormatter, TimeFormatter, DateFormatter, NumberFormatter, } from '../../../src/runtime/types' - let formatMessage: MessageFormatter let formatTime: TimeFormatter let formatDate: DateFormatter