@@ -60,24 +60,30 @@ test('require option', async () => {
60
60
} )
61
61
62
62
test ( '--provider: not found' , async ( ) => {
63
+ // run
63
64
const imp = await import ( '../../src/commands/import' )
64
65
const cmd = yargs . command ( imp )
65
66
await new Promise ( ( resolve , reject ) => {
66
67
cmd . parse ( `import --provider=./404-provider.js` , ( err , argv , output ) => {
67
68
err ? reject ( err ) : resolve ( output )
68
69
} )
69
70
} )
71
+
72
+ // verify
70
73
expect ( spyLog ) . toHaveBeenCalledWith ( 'Not found ./404-provider.js provider' )
71
74
} )
72
75
73
76
test ( 'not specified --target and --targetPaths' , async ( ) => {
77
+ // run
74
78
const imp = await import ( '../../src/commands/import' )
75
79
const cmd = yargs . command ( imp )
76
80
await new Promise ( ( resolve , reject ) => {
77
81
cmd . parse ( `import --provider=l10n-service-provider` , ( err , argv , output ) => {
78
82
err ? reject ( err ) : resolve ( output )
79
83
} )
80
84
} )
85
+
86
+ // verify
81
87
expect ( spyLog ) . toHaveBeenCalledWith ( 'You need to specify either --target or --target-paths' )
82
88
} )
83
89
@@ -95,9 +101,11 @@ test('--target option', async () => {
95
101
} )
96
102
} )
97
103
104
+ // verify
98
105
expect ( mockImport ) . toHaveBeenCalledWith ( {
99
106
messages : [ {
100
107
locale : 'en' ,
108
+ format : 'json' ,
101
109
data : fs . readFileSync ( './test/fixtures/locales/en.json' )
102
110
} ] ,
103
111
dryRun : false ,
@@ -119,9 +127,11 @@ test('--locale option', async () => {
119
127
} )
120
128
} )
121
129
130
+ // verify
122
131
expect ( mockImport ) . toHaveBeenCalledWith ( {
123
132
messages : [ {
124
133
locale : 'ja' ,
134
+ format : 'json' ,
125
135
data : fs . readFileSync ( './test/fixtures/locales/lang.json' )
126
136
} ] ,
127
137
dryRun : false ,
@@ -145,12 +155,14 @@ test('--conf option', async () => {
145
155
} )
146
156
} )
147
157
158
+ // verify
148
159
expect ( L10nServiceProvider ) . toHaveBeenCalledWith ( {
149
160
provider : { token : 'xxx' }
150
161
} )
151
162
expect ( mockImport ) . toHaveBeenCalledWith ( {
152
163
messages : [ {
153
164
locale : 'en' ,
165
+ format : 'json' ,
154
166
data : fs . readFileSync ( './test/fixtures/locales/en.json' )
155
167
} ] ,
156
168
dryRun : false ,
@@ -170,6 +182,7 @@ test('--conf option omit', async () => {
170
182
} )
171
183
} )
172
184
185
+ // verify
173
186
expect ( L10nOmitServiceProvider ) . toHaveBeenCalledWith ( {
174
187
provider : { token : 'yyy' }
175
188
} )
@@ -193,12 +206,15 @@ test('--target-paths option', async () => {
193
206
expect ( mockImport ) . toHaveBeenCalledWith ( {
194
207
messages : [ {
195
208
locale : 'en' ,
209
+ format : 'json' ,
196
210
data : fs . readFileSync ( './test/fixtures/locales/en.json' )
197
211
} , {
198
212
locale : 'ja' ,
213
+ format : 'json' ,
199
214
data : fs . readFileSync ( './test/fixtures/locales/ja.json' )
200
215
} , {
201
216
locale : 'lang' ,
217
+ format : 'json' ,
202
218
data : fs . readFileSync ( './test/fixtures/locales/lang.json' )
203
219
} ] ,
204
220
dryRun : false ,
@@ -220,6 +236,7 @@ test('not specified --filename-match', async () => {
220
236
} )
221
237
} )
222
238
239
+ // verify
223
240
expect ( spyError ) . toHaveBeenCalledWith ( 'import fail:' , 'You need to specify together --filename-match' )
224
241
} )
225
242
@@ -237,12 +254,41 @@ test('--dry-run option', async () => {
237
254
} )
238
255
} )
239
256
257
+ // verify
240
258
expect ( mockImport ) . toHaveBeenCalledWith ( {
241
259
messages : [ {
242
260
locale : 'ja' ,
261
+ format : 'json' ,
243
262
data : fs . readFileSync ( './test/fixtures/locales/lang.json' )
244
263
} ] ,
245
264
dryRun : true ,
246
265
normalize : undefined
247
266
} )
248
267
} )
268
+
269
+ test ( '--format option' , async ( ) => {
270
+ // setup mocks
271
+ mockImport . mockImplementation ( ( { resource } ) => Promise . resolve ( ) )
272
+
273
+ // run
274
+ const imp = await import ( '../../src/commands/import' )
275
+ const cmd = yargs . command ( imp )
276
+ await new Promise ( ( resolve , reject ) => {
277
+ cmd . parse ( `import --provider=@scope/l10n-service-provider \
278
+ --target=./test/fixtures/locales/ja \
279
+ --format=json` , ( err , argv , output ) => {
280
+ err ? reject ( err ) : resolve ( output )
281
+ } )
282
+ } )
283
+
284
+ // verify
285
+ expect ( mockImport ) . toHaveBeenCalledWith ( {
286
+ messages : [ {
287
+ locale : 'ja' ,
288
+ format : 'json' ,
289
+ data : fs . readFileSync ( './test/fixtures/locales/ja' )
290
+ } ] ,
291
+ dryRun : false ,
292
+ normalize : undefined
293
+ } )
294
+ } )
0 commit comments