1
1
'use strict'
2
2
3
3
const mocks = require ( 'mocks' )
4
- const di = require ( 'di' )
5
4
const path = require ( 'path' )
6
5
7
- const events = require ( '../../lib/events' )
8
-
9
6
describe ( 'preprocessor' , ( ) => {
10
7
let m
11
8
let mockFs
12
- let emitterSetting
13
9
// mimic first few bytes of a pdf file
14
10
const binarydata = Buffer . from ( [ 0x25 , 0x50 , 0x44 , 0x66 , 0x46 , 0x00 ] )
15
11
12
+ // Each test will define a spy; the fakeInstatiatePlugin will return it.
13
+ let fakePreprocessor
14
+
15
+ const simpleFakeInstantiatePlugin = ( ) => { return fakePreprocessor }
16
+
16
17
beforeEach ( ( ) => {
17
18
mockFs = mocks . fs . create ( {
18
19
some : {
@@ -32,22 +33,16 @@ describe('preprocessor', () => {
32
33
'graceful-fs' : mockFs ,
33
34
minimatch : require ( 'minimatch' )
34
35
}
35
- emitterSetting = { emitter : [ 'value' , new events . EventEmitter ( ) ] }
36
36
m = mocks . loadFile ( path . join ( __dirname , '/../../lib/preprocessor.js' ) , mocks_ )
37
37
} )
38
38
39
39
it ( 'should preprocess matching file' , async ( ) => {
40
- const fakePreprocessor = sinon . spy ( ( content , file , done ) => {
40
+ fakePreprocessor = sinon . spy ( ( content , file , done ) => {
41
41
file . path = file . path + '-preprocessed'
42
42
done ( null , 'new-content' )
43
43
} )
44
44
45
- const injector = new di . Injector ( [ {
46
- 'preprocessor:fake' : [
47
- 'factory' , function ( ) { return fakePreprocessor }
48
- ]
49
- } , emitterSetting ] )
50
- const pp = m . createPriorityPreprocessor ( { '**/*.js' : [ 'fake' ] } , { } , null , injector )
45
+ const pp = m . createPriorityPreprocessor ( { '**/*.js' : [ 'fake' ] } , { } , null , simpleFakeInstantiatePlugin )
51
46
52
47
const file = { originalPath : '/some/a.js' , path : 'path' }
53
48
@@ -58,15 +53,12 @@ describe('preprocessor', () => {
58
53
} )
59
54
60
55
it ( 'should match directories starting with a dot' , async ( ) => {
61
- const fakePreprocessor = sinon . spy ( ( content , file , done ) => {
56
+ fakePreprocessor = sinon . spy ( ( content , file , done ) => {
62
57
file . path = file . path + '-preprocessed'
63
58
done ( null , 'new-content' )
64
59
} )
65
60
66
- const injector = new di . Injector ( [ {
67
- 'preprocessor:fake' : [ 'factory' , function ( ) { return fakePreprocessor } ]
68
- } , emitterSetting ] )
69
- const pp = m . createPriorityPreprocessor ( { '**/*.js' : [ 'fake' ] } , { } , null , injector )
61
+ const pp = m . createPriorityPreprocessor ( { '**/*.js' : [ 'fake' ] } , { } , null , simpleFakeInstantiatePlugin )
70
62
71
63
const file = { originalPath : '/some/.dir/a.js' , path : 'path' }
72
64
@@ -77,15 +69,12 @@ describe('preprocessor', () => {
77
69
} )
78
70
79
71
it ( 'should get content if preprocessor is an async function or return Promise with content' , async ( ) => {
80
- const fakePreprocessor = sinon . spy ( async ( content , file , done ) => {
72
+ fakePreprocessor = sinon . spy ( async ( content , file , done ) => {
81
73
file . path = file . path + '-preprocessed'
82
74
return 'new-content'
83
75
} )
84
76
85
- const injector = new di . Injector ( [ {
86
- 'preprocessor:fake' : [ 'factory' , function ( ) { return fakePreprocessor } ]
87
- } , emitterSetting ] )
88
- const pp = m . createPriorityPreprocessor ( { '**/*.js' : [ 'fake' ] } , { } , null , injector )
77
+ const pp = m . createPriorityPreprocessor ( { '**/*.js' : [ 'fake' ] } , { } , null , simpleFakeInstantiatePlugin )
89
78
90
79
const file = { originalPath : '/some/.dir/a.js' , path : 'path' }
91
80
@@ -96,15 +85,12 @@ describe('preprocessor', () => {
96
85
} )
97
86
98
87
it ( 'should get content if preprocessor is an async function still calling done()' , async ( ) => {
99
- const fakePreprocessor = sinon . spy ( async ( content , file , done ) => {
88
+ fakePreprocessor = sinon . spy ( async ( content , file , done ) => {
100
89
file . path = file . path + '-preprocessed'
101
90
done ( null , 'new-content' )
102
91
} )
103
92
104
- const injector = new di . Injector ( [ {
105
- 'preprocessor:fake' : [ 'factory' , function ( ) { return fakePreprocessor } ]
106
- } , emitterSetting ] )
107
- const pp = m . createPriorityPreprocessor ( { '**/*.js' : [ 'fake' ] } , { } , null , injector )
93
+ const pp = m . createPriorityPreprocessor ( { '**/*.js' : [ 'fake' ] } , { } , null , simpleFakeInstantiatePlugin )
108
94
109
95
const file = { originalPath : '/some/.dir/a.js' , path : 'path' }
110
96
@@ -115,16 +101,13 @@ describe('preprocessor', () => {
115
101
} )
116
102
117
103
it ( 'should check patterns after creation when invoked' , async ( ) => {
118
- const fakePreprocessor = sinon . spy ( ( content , file , done ) => {
104
+ fakePreprocessor = sinon . spy ( ( content , file , done ) => {
119
105
file . path = file . path + '-preprocessed'
120
106
done ( null , 'new-content' )
121
107
} )
122
108
123
- const injector = new di . Injector ( [ {
124
- 'preprocessor:fake' : [ 'factory' , function ( ) { return fakePreprocessor } ]
125
- } , emitterSetting ] )
126
109
const config = { '**/*.txt' : [ 'fake' ] }
127
- const pp = m . createPriorityPreprocessor ( config , { } , null , injector )
110
+ const pp = m . createPriorityPreprocessor ( config , { } , null , simpleFakeInstantiatePlugin )
128
111
129
112
const file = { originalPath : '/some/a.js' , path : 'path' }
130
113
@@ -137,14 +120,11 @@ describe('preprocessor', () => {
137
120
} )
138
121
139
122
it ( 'should ignore not matching file' , async ( ) => {
140
- const fakePreprocessor = sinon . spy ( ( content , file , done ) => {
123
+ fakePreprocessor = sinon . spy ( ( content , file , done ) => {
141
124
done ( null , '' )
142
125
} )
143
126
144
- const injector = new di . Injector ( [ {
145
- 'preprocessor:fake' : [ 'factory' , function ( ) { return fakePreprocessor } ]
146
- } , emitterSetting ] )
147
- const pp = m . createPriorityPreprocessor ( { '**/*.js' : [ 'fake' ] } , { } , null , injector )
127
+ const pp = m . createPriorityPreprocessor ( { '**/*.js' : [ 'fake' ] } , { } , null , simpleFakeInstantiatePlugin )
148
128
149
129
const file = { originalPath : '/some/a.txt' , path : 'path' }
150
130
@@ -153,34 +133,33 @@ describe('preprocessor', () => {
153
133
} )
154
134
155
135
it ( 'should apply all preprocessors' , async ( ) => {
156
- const fakePreprocessor1 = sinon . spy ( ( content , file , done ) => {
157
- file . path = file . path + '-p1'
158
- done ( null , content + '-c1' )
159
- } )
160
-
161
- const fakePreprocessor2 = sinon . spy ( ( content , file , done ) => {
162
- file . path = file . path + '-p2'
163
- done ( content + '-c2' )
164
- } )
165
-
166
- const injector = new di . Injector ( [ {
167
- 'preprocessor:fake1' : [ 'factory' , function ( ) { return fakePreprocessor1 } ] ,
168
- 'preprocessor:fake2' : [ 'factory' , function ( ) { return fakePreprocessor2 } ]
169
- } , emitterSetting ] )
136
+ const fakes = {
137
+ fake1 : sinon . spy ( ( content , file , done ) => {
138
+ file . path = file . path + '-p1'
139
+ done ( null , content + '-c1' )
140
+ } ) ,
141
+ fake2 : sinon . spy ( ( content , file , done ) => {
142
+ file . path = file . path + '-p2'
143
+ done ( content + '-c2' )
144
+ } )
145
+ }
146
+ function fakeInstatiatePlugin ( kind , name ) {
147
+ return fakes [ name ]
148
+ }
170
149
171
- const pp = m . createPriorityPreprocessor ( { '**/*.js' : [ 'fake1' , 'fake2' ] } , { } , null , injector )
150
+ const pp = m . createPriorityPreprocessor ( { '**/*.js' : [ 'fake1' , 'fake2' ] } , { } , null , fakeInstatiatePlugin )
172
151
173
152
const file = { originalPath : '/some/a.js' , path : 'path' }
174
153
175
154
await pp ( file )
176
- expect ( fakePreprocessor1 ) . to . have . been . calledOnce
177
- expect ( fakePreprocessor2 ) . to . have . been . calledOnce
155
+ expect ( fakes . fake1 ) . to . have . been . calledOnce
156
+ expect ( fakes . fake2 ) . to . have . been . calledOnce
178
157
expect ( file . path ) . to . equal ( 'path-p1-p2' )
179
158
expect ( file . content ) . to . equal ( 'content-c1-c2' )
180
159
} )
181
160
182
161
it ( 'should compute SHA' , async ( ) => {
183
- const pp = m . createPriorityPreprocessor ( { } , { } , null , new di . Injector ( [ emitterSetting ] ) )
162
+ const pp = m . createPriorityPreprocessor ( { } , { } , null , simpleFakeInstantiatePlugin )
184
163
const file = { originalPath : '/some/a.js' , path : 'path' }
185
164
186
165
await pp ( file )
@@ -198,15 +177,11 @@ describe('preprocessor', () => {
198
177
} )
199
178
200
179
it ( 'should compute SHA from content returned by a processor' , async ( ) => {
201
- const fakePreprocessor = sinon . spy ( ( content , file , done ) => {
180
+ fakePreprocessor = sinon . spy ( ( content , file , done ) => {
202
181
done ( null , content + '-processed' )
203
182
} )
204
183
205
- const injector = new di . Injector ( [ {
206
- 'preprocessor:fake' : [ 'factory' , function ( ) { return fakePreprocessor } ]
207
- } , emitterSetting ] )
208
-
209
- const pp = m . createPriorityPreprocessor ( { '**/a.js' : [ 'fake' ] } , { } , null , injector )
184
+ const pp = m . createPriorityPreprocessor ( { '**/a.js' : [ 'fake' ] } , { } , null , simpleFakeInstantiatePlugin )
210
185
211
186
const fileProcess = { originalPath : '/some/a.js' , path : 'path' }
212
187
const fileSkip = { originalPath : '/some/b.js' , path : 'path' }
@@ -221,15 +196,11 @@ describe('preprocessor', () => {
221
196
} )
222
197
223
198
it ( 'should return error if any preprocessor fails' , ( ) => {
224
- const failingPreprocessor = sinon . spy ( ( content , file , done ) => {
199
+ fakePreprocessor = sinon . spy ( ( content , file , done ) => {
225
200
done ( new Error ( 'Some error' ) , null )
226
201
} )
227
202
228
- const injector = new di . Injector ( [ {
229
- 'preprocessor:failing' : [ 'factory' , function ( ) { return failingPreprocessor } ]
230
- } , emitterSetting ] )
231
-
232
- const pp = m . createPriorityPreprocessor ( { '**/*.js' : [ 'failing' ] } , { } , null , injector )
203
+ const pp = m . createPriorityPreprocessor ( { '**/*.js' : [ 'failing' ] } , { } , null , simpleFakeInstantiatePlugin )
233
204
234
205
const file = { originalPath : '/some/a.js' , path : 'path' }
235
206
@@ -241,20 +212,20 @@ describe('preprocessor', () => {
241
212
} )
242
213
243
214
it ( 'should stop preprocessing after an error' , async ( ) => {
244
- const failingPreprocessor = sinon . spy ( ( content , file , done ) => {
245
- done ( new Error ( 'Some error' ) , null )
246
- } )
247
-
248
- const fakePreprocessor = sinon . spy ( ( content , file , done ) => {
249
- done ( null , content )
250
- } )
215
+ const fakes = {
216
+ failing : sinon . spy ( ( content , file , done ) => {
217
+ done ( new Error ( 'Some error' ) , null )
218
+ } ) ,
219
+ fake : sinon . spy ( ( content , file , done ) => {
220
+ done ( null , content )
221
+ } )
222
+ }
251
223
252
- const injector = new di . Injector ( [ {
253
- 'preprocessor:failing' : [ 'factory' , function ( ) { return failingPreprocessor } ] ,
254
- 'preprocessor:fake' : [ 'factory' , function ( ) { return fakePreprocessor } ]
255
- } , emitterSetting ] )
224
+ function fakeInstantiatePlugin ( kind , name ) {
225
+ return fakes [ name ]
226
+ }
256
227
257
- const pp = m . createPriorityPreprocessor ( { '**/*.js' : [ 'failing' , 'fake' ] } , { } , null , injector )
228
+ const pp = m . createPriorityPreprocessor ( { '**/*.js' : [ 'failing' , 'fake' ] } , { } , null , fakeInstantiatePlugin )
258
229
259
230
const file = { originalPath : '/some/a.js' , path : 'path' }
260
231
@@ -263,7 +234,7 @@ describe('preprocessor', () => {
263
234
} , ( err ) => {
264
235
expect ( err . message ) . to . equal ( 'Some error' )
265
236
} )
266
- expect ( fakePreprocessor ) . not . to . have . been . called
237
+ expect ( fakes . fake ) . not . to . have . been . called
267
238
} )
268
239
269
240
describe ( 'when fs.readFile fails' , ( ) => {
@@ -274,15 +245,11 @@ describe('preprocessor', () => {
274
245
} )
275
246
276
247
it ( 'should retry up to 3 times' , async ( ) => {
277
- const fakePreprocessor = sinon . spy ( ( content , file , done ) => {
248
+ fakePreprocessor = sinon . spy ( ( content , file , done ) => {
278
249
done ( null , content )
279
250
} )
280
251
281
- const injector = new di . Injector ( [ {
282
- 'preprocessor:fake' : [ 'factory' , function ( ) { return fakePreprocessor } ]
283
- } , emitterSetting ] )
284
-
285
- const pp = m . createPriorityPreprocessor ( { '**/*.js' : [ 'fake' ] } , { } , null , injector )
252
+ const pp = m . createPriorityPreprocessor ( { '**/*.js' : [ 'fake' ] } , { } , null , simpleFakeInstantiatePlugin )
286
253
287
254
await pp ( file ) . then ( ( ) => {
288
255
throw new Error ( 'Should be rejected' )
@@ -295,9 +262,7 @@ describe('preprocessor', () => {
295
262
} )
296
263
297
264
it ( 'should throw after 3 retries' , async ( ) => {
298
- const injector = new di . Injector ( [ { } , emitterSetting ] )
299
-
300
- const pp = m . createPriorityPreprocessor ( { '**/*.js' : [ ] } , { } , null , injector )
265
+ const pp = m . createPriorityPreprocessor ( { '**/*.js' : [ ] } , { } , null , simpleFakeInstantiatePlugin )
301
266
302
267
await pp ( file ) . then ( ( ) => {
303
268
throw new Error ( 'Should be rejected' )
@@ -309,15 +274,11 @@ describe('preprocessor', () => {
309
274
} )
310
275
311
276
it ( 'should not preprocess binary files by default' , async ( ) => {
312
- const fakePreprocessor = sinon . spy ( ( content , file , done ) => {
277
+ fakePreprocessor = sinon . spy ( ( content , file , done ) => {
313
278
done ( null , content )
314
279
} )
315
280
316
- const injector = new di . Injector ( [ {
317
- 'preprocessor:fake' : [ 'factory' , function ( ) { return fakePreprocessor } ]
318
- } , emitterSetting ] )
319
-
320
- const pp = m . createPriorityPreprocessor ( { '**/*' : [ 'fake' ] } , { } , null , injector )
281
+ const pp = m . createPriorityPreprocessor ( { '**/*' : [ 'fake' ] } , { } , null , simpleFakeInstantiatePlugin )
321
282
322
283
const file = { originalPath : '/some/photo.png' , path : 'path' }
323
284
@@ -327,15 +288,11 @@ describe('preprocessor', () => {
327
288
} )
328
289
329
290
it ( 'should not preprocess files configured to be binary' , async ( ) => {
330
- const fakePreprocessor = sinon . spy ( ( content , file , done ) => {
291
+ fakePreprocessor = sinon . spy ( ( content , file , done ) => {
331
292
done ( null , content )
332
293
} )
333
294
334
- const injector = new di . Injector ( [ {
335
- 'preprocessor:fake' : [ 'factory' , function ( ) { return fakePreprocessor } ]
336
- } , emitterSetting ] )
337
-
338
- const pp = m . createPriorityPreprocessor ( { '**/*' : [ 'fake' ] } , { } , null , injector )
295
+ const pp = m . createPriorityPreprocessor ( { '**/*' : [ 'fake' ] } , { } , null , simpleFakeInstantiatePlugin )
339
296
340
297
const file = { originalPath : '/some/proto.pb' , path : 'path' , isBinary : true }
341
298
@@ -345,15 +302,11 @@ describe('preprocessor', () => {
345
302
} )
346
303
347
304
it ( 'should preprocess files configured not to be binary' , async ( ) => {
348
- const fakePreprocessor = sinon . spy ( ( content , file , done ) => {
305
+ fakePreprocessor = sinon . spy ( ( content , file , done ) => {
349
306
done ( null , content )
350
307
} )
351
308
352
- const injector = new di . Injector ( [ {
353
- 'preprocessor:fake' : [ 'factory' , function ( ) { return fakePreprocessor } ]
354
- } , emitterSetting ] )
355
-
356
- const pp = m . createPriorityPreprocessor ( { '**/*' : [ 'fake' ] } , { } , null , injector )
309
+ const pp = m . createPriorityPreprocessor ( { '**/*' : [ 'fake' ] } , { } , null , simpleFakeInstantiatePlugin )
357
310
358
311
// Explicit false for isBinary
359
312
const file = { originalPath : '/some/proto.pb' , path : 'path' , isBinary : false }
@@ -364,16 +317,12 @@ describe('preprocessor', () => {
364
317
} )
365
318
366
319
it ( 'should preprocess binary files if handleBinaryFiles=true' , async ( ) => {
367
- const fakePreprocessor = sinon . spy ( ( content , file , done ) => {
320
+ fakePreprocessor = sinon . spy ( ( content , file , done ) => {
368
321
done ( null , content )
369
322
} )
370
323
fakePreprocessor . handleBinaryFiles = true
371
324
372
- const injector = new di . Injector ( [ {
373
- 'preprocessor:fake' : [ 'factory' , function ( ) { return fakePreprocessor } ]
374
- } , emitterSetting ] )
375
-
376
- const pp = m . createPriorityPreprocessor ( { '**/*' : [ 'fake' ] } , { } , null , injector )
325
+ const pp = m . createPriorityPreprocessor ( { '**/*' : [ 'fake' ] } , { } , null , simpleFakeInstantiatePlugin )
377
326
378
327
const file = { originalPath : '/some/photo.png' , path : 'path' }
379
328
@@ -383,15 +332,11 @@ describe('preprocessor', () => {
383
332
} )
384
333
385
334
it ( 'should not preprocess binary files with capital letters in extension' , async ( ) => {
386
- const fakePreprocessor = sinon . spy ( ( content , file , done ) => {
335
+ fakePreprocessor = sinon . spy ( ( content , file , done ) => {
387
336
done ( null , content )
388
337
} )
389
338
390
- const injector = new di . Injector ( [ {
391
- 'preprocessor:fake' : [ 'factory' , function ( ) { fakePreprocessor } ]
392
- } , emitterSetting ] )
393
-
394
- const pp = m . createPriorityPreprocessor ( { '**/*' : [ 'fake' ] } , { } , null , injector )
339
+ const pp = m . createPriorityPreprocessor ( { '**/*' : [ 'fake' ] } , { } , null , simpleFakeInstantiatePlugin )
395
340
396
341
const file = { originalPath : '/some/CAM_PHOTO.JPG' , path : 'path' }
397
342
@@ -402,88 +347,84 @@ describe('preprocessor', () => {
402
347
403
348
it ( 'should merge lists of preprocessors using default priority' , async ( ) => {
404
349
const callOrder = [ ]
405
- const fakePreprocessorA = sinon . spy ( ( content , file , done ) => {
406
- callOrder . push ( 'a' )
407
- done ( null , content )
408
- } )
409
- const fakePreprocessorB = sinon . spy ( ( content , file , done ) => {
410
- callOrder . push ( 'b' )
411
- done ( null , content )
412
- } )
413
- const fakePreprocessorC = sinon . spy ( ( content , file , done ) => {
414
- callOrder . push ( 'c' )
415
- done ( null , content )
416
- } )
417
- const fakePreprocessorD = sinon . spy ( ( content , file , done ) => {
418
- callOrder . push ( 'd' )
419
- done ( null , content )
420
- } )
421
-
422
- const injector = new di . Injector ( [ {
423
- 'preprocessor:fakeA' : [ 'factory' , function ( ) { return fakePreprocessorA } ] ,
424
- 'preprocessor:fakeB' : [ 'factory' , function ( ) { return fakePreprocessorB } ] ,
425
- 'preprocessor:fakeC' : [ 'factory' , function ( ) { return fakePreprocessorC } ] ,
426
- 'preprocessor:fakeD' : [ 'factory' , function ( ) { return fakePreprocessorD } ]
427
- } , emitterSetting ] )
350
+ const fakes = {
351
+ fakeA : sinon . spy ( ( content , file , done ) => {
352
+ callOrder . push ( 'a' )
353
+ done ( null , content )
354
+ } ) ,
355
+ fakeB : sinon . spy ( ( content , file , done ) => {
356
+ callOrder . push ( 'b' )
357
+ done ( null , content )
358
+ } ) ,
359
+ fakeC : sinon . spy ( ( content , file , done ) => {
360
+ callOrder . push ( 'c' )
361
+ done ( null , content )
362
+ } ) ,
363
+ fakeD : sinon . spy ( ( content , file , done ) => {
364
+ callOrder . push ( 'd' )
365
+ done ( null , content )
366
+ } )
367
+ }
368
+ function fakeInstantiatePlugin ( kind , name ) {
369
+ return fakes [ name ]
370
+ }
428
371
429
372
const pp = m . createPriorityPreprocessor ( {
430
373
'/*/a.js' : [ 'fakeA' , 'fakeB' ] ,
431
374
'/some/*' : [ 'fakeB' , 'fakeC' ] ,
432
375
'/some/a.js' : [ 'fakeD' ]
433
- } , { } , null , injector )
376
+ } , { } , null , fakeInstantiatePlugin )
434
377
435
378
const file = { originalPath : '/some/a.js' , path : 'path' }
436
379
437
380
await pp ( file )
438
- expect ( fakePreprocessorA ) . to . have . been . called
439
- expect ( fakePreprocessorB ) . to . have . been . called
440
- expect ( fakePreprocessorC ) . to . have . been . called
441
- expect ( fakePreprocessorD ) . to . have . been . called
381
+ expect ( fakes . fakeA ) . to . have . been . called
382
+ expect ( fakes . fakeB ) . to . have . been . called
383
+ expect ( fakes . fakeC ) . to . have . been . called
384
+ expect ( fakes . fakeD ) . to . have . been . called
442
385
443
386
expect ( callOrder ) . to . eql ( [ 'a' , 'b' , 'c' , 'd' ] )
444
387
} )
445
388
446
389
it ( 'should merge lists of preprocessors obeying priority' , async ( ) => {
447
390
const callOrder = [ ]
448
- const fakePreprocessorA = sinon . spy ( ( content , file , done ) => {
449
- callOrder . push ( 'a' )
450
- done ( null , content )
451
- } )
452
- const fakePreprocessorB = sinon . spy ( ( content , file , done ) => {
453
- callOrder . push ( 'b' )
454
- done ( null , content )
455
- } )
456
- const fakePreprocessorC = sinon . spy ( ( content , file , done ) => {
457
- callOrder . push ( 'c' )
458
- done ( null , content )
459
- } )
460
- const fakePreprocessorD = sinon . spy ( ( content , file , done ) => {
461
- callOrder . push ( 'd' )
462
- done ( null , content )
463
- } )
464
-
465
- const injector = new di . Injector ( [ {
466
- 'preprocessor:fakeA' : [ 'factory' , function ( ) { return fakePreprocessorA } ] ,
467
- 'preprocessor:fakeB' : [ 'factory' , function ( ) { return fakePreprocessorB } ] ,
468
- 'preprocessor:fakeC' : [ 'factory' , function ( ) { return fakePreprocessorC } ] ,
469
- 'preprocessor:fakeD' : [ 'factory' , function ( ) { return fakePreprocessorD } ]
470
- } , emitterSetting ] )
391
+ const fakes = {
392
+ fakeA : sinon . spy ( ( content , file , done ) => {
393
+ callOrder . push ( 'a' )
394
+ done ( null , content )
395
+ } ) ,
396
+ fakeB : sinon . spy ( ( content , file , done ) => {
397
+ callOrder . push ( 'b' )
398
+ done ( null , content )
399
+ } ) ,
400
+ fakeC : sinon . spy ( ( content , file , done ) => {
401
+ callOrder . push ( 'c' )
402
+ done ( null , content )
403
+ } ) ,
404
+ fakeD : sinon . spy ( ( content , file , done ) => {
405
+ callOrder . push ( 'd' )
406
+ done ( null , content )
407
+ } )
408
+ }
409
+ function fakeInstantiatePlugin ( kind , name ) {
410
+ return fakes [ name ]
411
+ }
471
412
472
413
const priority = { fakeA : - 1 , fakeB : 1 , fakeD : 100 }
473
414
474
415
const pp = m . createPriorityPreprocessor ( {
475
416
'/*/a.js' : [ 'fakeA' , 'fakeB' ] ,
476
417
'/some/*' : [ 'fakeB' , 'fakeC' ] ,
477
418
'/some/a.js' : [ 'fakeD' ]
478
- } , priority , null , injector )
419
+ } , priority , null , fakeInstantiatePlugin )
479
420
480
421
const file = { originalPath : '/some/a.js' , path : 'path' }
481
422
482
423
await pp ( file )
483
- expect ( fakePreprocessorA ) . to . have . been . called
484
- expect ( fakePreprocessorB ) . to . have . been . called
485
- expect ( fakePreprocessorC ) . to . have . been . called
486
- expect ( fakePreprocessorD ) . to . have . been . called
424
+ expect ( fakes . fakeA ) . to . have . been . called
425
+ expect ( fakes . fakeB ) . to . have . been . called
426
+ expect ( fakes . fakeC ) . to . have . been . called
427
+ expect ( fakes . fakeD ) . to . have . been . called
487
428
488
429
expect ( callOrder ) . to . eql ( [ 'd' , 'b' , 'c' , 'a' ] )
489
430
} )
0 commit comments