/
gulp.test.js
195 lines (175 loc) · 5.39 KB
/
gulp.test.js
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import { assert } from 'chai'
import { pEvent } from 'p-event'
import { fileURLToPath } from 'url'
import fs from 'fs-extra'
import gulp from 'gulp'
import path from 'path'
import sinon from 'sinon'
import './gulpfile.js'
import PluralRulesMock from '../Intl.PluralRules.mock.js'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
describe('gulp plugin', function () {
// test execution time depends on I/O
this.timeout(0)
beforeEach(async () => {
await fs.emptyDir(path.resolve(__dirname, './locales'))
sinon.replace(Intl, 'PluralRules', PluralRulesMock)
})
afterEach(async () => {
await fs.emptyDir(path.resolve(__dirname, './locales'))
sinon.restore()
})
it('works as a gulp plugin', async () => {
const gulpStream = gulp.task('i18next')()
await pEvent(gulpStream, 'end')
const enReact = await fs.readJson(
path.resolve(__dirname, './locales/en/react.json')
)
try {
await fs.readJson(path.resolve(__dirname, './locales/en/react_old.json'))
} catch (error) {
assert.strictEqual(error.code, 'ENOENT')
}
const enNamespace = await fs.readJson(
path.resolve(__dirname, './locales/en/test-namespace.json')
)
try {
await fs.readJson(
path.resolve(__dirname, './locales/en/test-namespace_old.json')
)
} catch (error) {
assert.strictEqual(error.code, 'ENOENT')
}
const enKeyPrefix = await fs.readJson(
path.resolve(__dirname, './locales/en/key-prefix.json')
)
try {
await fs.readJson(
path.resolve(__dirname, './locales/en/key-prefix_old.json')
)
} catch (error) {
assert.strictEqual(error.code, 'ENOENT')
}
const enTranslation = await fs.readJson(
path.resolve(__dirname, './locales/en/translation.json')
)
try {
await fs.readJson(
path.resolve(__dirname, './locales/en/translation_old.json')
)
} catch (error) {
assert.strictEqual(error.code, 'ENOENT')
}
const frReact = await fs.readJson(
path.resolve(__dirname, './locales/fr/react.json')
)
try {
await fs.readJson(path.resolve(__dirname, './locales/fr/react_old.json'))
} catch (error) {
assert.strictEqual(error.code, 'ENOENT')
}
const frNamespace = await fs.readJson(
path.resolve(__dirname, './locales/fr/test-namespace.json')
)
try {
await fs.readJson(path.resolve(__dirname, './locales/fr/react_old.json'))
} catch (error) {
assert.strictEqual(error.code, 'ENOENT')
}
const frTranslation = await fs.readJson(
path.resolve(__dirname, './locales/fr/translation.json')
)
try {
await fs.readJson(path.resolve(__dirname, './locales/fr/react_old.json'))
} catch (error) {
assert.strictEqual(error.code, 'ENOENT')
}
assert.deepEqual(enReact, {
bar: '',
"don't split {{on}}": "don't split {{on}}",
fifth_one: '',
fifth_other: '',
first: '',
foo: '',
fourth: '',
'override-default': 'default override',
second: '',
third: {
first_one:
'Hello <1>{{name}}</1>, you have {{count}} unread message. <5>Go to messages</5>.',
first_other:
'Hello <1>{{name}}</1>, you have {{count}} unread message. <5>Go to messages</5>.',
second: " <1>Hello,</1> this shouldn't be trimmed.",
third: "<0>Hello,</0>this should be trimmed.<2> and this shoudln't</2>",
},
'This should be part of the value and the key':
'This should be part of the value and the key',
})
assert.deepEqual(enNamespace, {
'test-1': '',
'test-2': '',
})
assert.deepEqual(enKeyPrefix, {
'test-prefix': {
foo: '',
bar: '',
},
})
assert.deepEqual(enTranslation, {
fifth: 'bar',
fifth_male: '',
first: '',
fourth: '',
fourth_male: 'defaultValue',
second: 'defaultValue',
second_male: 'defaultValue',
selfClosing: '',
seventh: 'defaultValue',
sixth: '',
third: '{{var}} defaultValue',
third_female: 'defaultValue',
})
assert.deepEqual(frReact, {
bar: '',
"don't split {{on}}": "don't split {{on}}",
fifth_one: '',
fifth_many: '',
fifth_other: '',
first: '',
foo: '',
fourth: '',
'override-default': 'default override',
second: '',
third: {
first_one:
'Hello <1>{{name}}</1>, you have {{count}} unread message. <5>Go to messages</5>.',
first_many:
'Hello <1>{{name}}</1>, you have {{count}} unread message. <5>Go to messages</5>.',
first_other:
'Hello <1>{{name}}</1>, you have {{count}} unread message. <5>Go to messages</5>.',
second: " <1>Hello,</1> this shouldn't be trimmed.",
third: "<0>Hello,</0>this should be trimmed.<2> and this shoudln't</2>",
},
'This should be part of the value and the key':
'This should be part of the value and the key',
})
assert.deepEqual(frNamespace, {
'test-1': '',
'test-2': '',
})
assert.deepEqual(frTranslation, {
fifth: 'bar',
fifth_male: '',
first: '',
fourth: '',
fourth_male: 'defaultValue',
second: 'defaultValue',
second_male: 'defaultValue',
selfClosing: '',
seventh: 'defaultValue',
sixth: '',
third: '{{var}} defaultValue',
third_female: 'defaultValue',
})
})
})