-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
custom-block.test.ts
105 lines (95 loc) · 3.58 KB
/
custom-block.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { bundleAndRun } from './utils'
import { createMessageContext } from '@intlify/core-base'
test('basic', async () => {
const { module } = await bundleAndRun('basic.vue')
const i18n = module.__i18n.pop()
expect(i18n.locale).toEqual('')
expect(i18n.resource.en.hello(createMessageContext())).toEqual('hello world!')
})
test('yaml', async () => {
const { module } = await bundleAndRun('yaml.vue')
expect(module.__i18n).toMatchSnapshot()
let i18n = module.__i18n.pop()
expect(i18n.locale).toEqual('ja')
expect(i18n.resource.hello(createMessageContext())).toEqual(
'こんにちは、世界!'
)
i18n = module.__i18n.pop()
expect(i18n.locale).toEqual('en')
expect(i18n.resource.hello(createMessageContext())).toEqual('hello world!')
})
test('json5', async () => {
const { module } = await bundleAndRun('json5.vue')
expect(module.__i18n).toMatchSnapshot()
const i18n = module.__i18n.pop()
expect(i18n.locale).toEqual('')
expect(i18n.resource.en.hello(createMessageContext())).toEqual('hello world!')
})
test('import', async () => {
const { module } = await bundleAndRun('import.vue')
expect(module.__i18n).toMatchSnapshot()
const i18n = module.__i18n.pop()
expect(i18n.locale).toEqual('')
expect(i18n.resource.en.hello(createMessageContext())).toEqual('hello world!')
})
test('multiple', async () => {
const { module } = await bundleAndRun('multiple.vue')
expect(module.__i18n).toMatchSnapshot()
expect(module.__i18n.length).toEqual(2)
let i18n = module.__i18n.pop()
expect(i18n.locale).toEqual('')
expect(i18n.resource.ja.hello(createMessageContext())).toEqual(
'こんにちは、世界!'
)
i18n = module.__i18n.pop()
expect(i18n.locale).toEqual('')
expect(i18n.resource.en.hello(createMessageContext())).toEqual('hello world!')
})
test('locale attr', async () => {
const { module } = await bundleAndRun('locale.vue')
expect(module.__i18n).toMatchSnapshot()
const i18n = module.__i18n.pop()
expect(i18n.locale).toEqual('ja')
expect(i18n.resource.hello(createMessageContext())).toEqual(
'こんにちは、世界!'
)
})
test('locale attr and basic', async () => {
const { module } = await bundleAndRun('locale-mix.vue')
expect(module.__i18n).toMatchSnapshot()
let i18n = module.__i18n.pop()
expect(i18n.locale).toEqual('ja')
expect(i18n.resource.hello(createMessageContext())).toEqual(
'こんにちは、世界!'
)
i18n = module.__i18n.pop()
expect(i18n.locale).toEqual('')
expect(i18n.resource.en.hello(createMessageContext())).toEqual('hello world!')
})
test('locale attr and import', async () => {
const { module } = await bundleAndRun('locale-import.vue')
expect(module.__i18n).toMatchSnapshot()
const i18n = module.__i18n.pop()
expect(i18n.locale).toEqual('en')
expect(i18n.resource.hello(createMessageContext())).toEqual('hello world!')
})
test('special characters', async () => {
const { module } = await bundleAndRun('special-char.vue')
expect(module.__i18n).toMatchSnapshot()
const i18n = module.__i18n.pop()
expect(i18n.locale).toEqual('')
expect(i18n.resource.en.hello(createMessageContext())).toEqual(
'hello\ngreat\t"world"'
)
})
test('global', async () => {
const { module } = await bundleAndRun('global-mix.vue')
expect(module.__i18n).toMatchSnapshot()
expect(module.__i18nGlobal).toMatchSnapshot()
const l = module.__i18n.pop()
expect(l.locale).toEqual('ja')
expect(l.resource.hello(createMessageContext())).toEqual('hello local!')
const g = module.__i18nGlobal.pop()
expect(g.locale).toEqual('')
expect(g.resource.en.hello(createMessageContext())).toEqual('hello global!')
})