1
+ 'use strict' ;
2
+
3
+ /* global test, expect */
4
+
1
5
const Reader = require ( '../' ) ;
2
6
const SinkFs = require ( 'asset-pipe-sink-fs' ) ;
3
7
const path = require ( 'path' ) ;
4
8
const { sort, dedupe, compareByOrder } = require ( '../lib/util' ) ;
5
9
const { Readable, PassThrough } = require ( 'stream' ) ;
6
10
7
- function createSlowStream ( sink , filePath , timeout = 1000 ) {
11
+ function createSlowStream ( sink , filePath , timeout = 1000 ) {
8
12
const myStream = new PassThrough ( ) ;
9
13
10
14
process . nextTick ( ( ) => myStream . emit ( 'file found' , filePath ) ) ;
@@ -19,7 +23,7 @@ function createSlowStream(sink, filePath, timeout = 1000) {
19
23
test ( 'new Reader(stream) single feedStream' , done => {
20
24
expect . assertions ( 1 ) ;
21
25
const sink = new SinkFs ( {
22
- path : path . join ( __dirname , './test-assets' )
26
+ path : path . join ( __dirname , './test-assets' ) ,
23
27
} ) ;
24
28
const feedStream = sink . reader ( 'a.json' ) ;
25
29
@@ -38,7 +42,7 @@ test('new Reader(stream) single feedStream', done => {
38
42
test ( 'new Reader([stream1, stream2]) mulitple feedStreams merged' , done => {
39
43
expect . assertions ( 4 ) ;
40
44
const sink = new SinkFs ( {
41
- path : path . join ( __dirname , './test-assets' )
45
+ path : path . join ( __dirname , './test-assets' ) ,
42
46
} ) ;
43
47
const feedStream1 = sink . reader ( 'a.json' ) ;
44
48
const feedStream2 = sink . reader ( 'b.json' ) ;
@@ -61,15 +65,15 @@ test('new Reader([stream1, stream2]) mulitple feedStreams merged', done => {
61
65
test ( 'Dedupe of identical hashes occurs' , done => {
62
66
expect . assertions ( 1 ) ;
63
67
const sink = new SinkFs ( {
64
- path : path . join ( __dirname , './test-assets' )
68
+ path : path . join ( __dirname , './test-assets' ) ,
65
69
} ) ;
66
70
const feedStream1 = sink . reader ( 'a.json' ) ;
67
71
const feedStream2 = sink . reader ( 'd.json' ) ;
68
72
69
73
const reader = new Reader ( [ feedStream1 , feedStream2 ] ) ;
70
74
71
75
reader . on ( 'pipeline ready' , ( ) => {
72
- let bundle = [ ] ;
76
+ const bundle = [ ] ;
73
77
reader . on ( 'data' , data => bundle . push ( data . toString ( ) ) ) ;
74
78
reader . on ( 'end' , ( ) => {
75
79
expect ( bundle . length ) . toBe ( 1 ) ;
@@ -81,7 +85,7 @@ test('Dedupe of identical hashes occurs', done => {
81
85
test ( 'Event: file found' , done => {
82
86
expect . assertions ( 1 ) ;
83
87
const sink = new SinkFs ( {
84
- path : path . join ( __dirname , './test-assets' )
88
+ path : path . join ( __dirname , './test-assets' ) ,
85
89
} ) ;
86
90
const feedStream = sink . reader ( 'a.json' ) ;
87
91
const reader = new Reader ( feedStream ) ;
@@ -97,7 +101,7 @@ test('Event: file found', done => {
97
101
test ( 'Event: file not found single stream' , done => {
98
102
expect . assertions ( 1 ) ;
99
103
const sink = new SinkFs ( {
100
- path : path . join ( __dirname , './test-assets' )
104
+ path : path . join ( __dirname , './test-assets' ) ,
101
105
} ) ;
102
106
const feedStream = sink . reader ( 'does-not-exist.json' ) ;
103
107
const reader = new Reader ( feedStream ) ;
@@ -114,7 +118,7 @@ test('Event: file not found single stream', done => {
114
118
test ( 'Event: file not found multiple streams' , done => {
115
119
expect . assertions ( 2 ) ;
116
120
const sink = new SinkFs ( {
117
- path : path . join ( __dirname , './test-assets' )
121
+ path : path . join ( __dirname , './test-assets' ) ,
118
122
} ) ;
119
123
const feedStream1 = sink . reader ( 'a.json' ) ;
120
124
const feedStream2 = sink . reader ( 'does-not-exist.json' ) ;
@@ -135,7 +139,7 @@ test('Event: file not found multiple streams', done => {
135
139
test ( 'Event: parse error' , done => {
136
140
expect . assertions ( 1 ) ;
137
141
const sink = new SinkFs ( {
138
- path : path . join ( __dirname , './test-assets' )
142
+ path : path . join ( __dirname , './test-assets' ) ,
139
143
} ) ;
140
144
const feedStream = sink . reader ( 'invalid-json.json' ) ;
141
145
const reader = new Reader ( feedStream ) ;
@@ -180,14 +184,14 @@ test('SortAndDedupe() rows without id value dropped', done => {
180
184
const values = [ { id : 'asd' } , { x : '' } , { id : 'sdf' } ] ;
181
185
const stream = new Readable ( {
182
186
objectMode : true ,
183
- read ( ) {
187
+ read ( ) {
184
188
if ( values . length === 0 ) {
185
189
this . push ( null ) ;
186
190
return ;
187
191
}
188
192
const value = values . shift ( ) ;
189
193
this . push ( value ) ;
190
- }
194
+ } ,
191
195
} ) ;
192
196
const buffer = [ ] ;
193
197
stream
@@ -202,27 +206,20 @@ test('SortAndDedupe() rows without id value dropped', done => {
202
206
test ( 'new Reader([s1,s2,s3,s4]) ensure dedupe and correct css concat order' , done => {
203
207
expect . assertions ( 3 ) ;
204
208
const sink = new SinkFs ( {
205
- path : path . join ( __dirname , './test-assets' )
209
+ path : path . join ( __dirname , './test-assets' ) ,
206
210
} ) ;
207
211
const feedStream1 = sink . reader ( 'a.json' ) ;
208
212
const feedStream2 = sink . reader ( 'b.json' ) ;
209
213
const feedStream3 = sink . reader ( 'c.json' ) ;
210
214
const feedStream4 = sink . reader ( 'd.json' ) ;
211
215
212
- const reader = new Reader ( [
213
- feedStream1 ,
214
- feedStream2 ,
215
- feedStream3 ,
216
- feedStream4
217
- ] ) ;
216
+ const reader = new Reader ( [ feedStream1 , feedStream2 , feedStream3 , feedStream4 ] ) ;
218
217
219
218
reader . on ( 'pipeline ready' , ( ) => {
220
- let bundle = [ ] ;
219
+ const bundle = [ ] ;
221
220
reader . on ( 'data' , data => bundle . push ( data . toString ( ) ) ) ;
222
221
reader . on ( 'end' , ( ) => {
223
- expect ( bundle [ 0 ] ) . toBe (
224
- '/* my-module-3/main.css */\n\n/* my-module-3/dep.css */\n\n/* dep/main.css */\n'
225
- ) ;
222
+ expect ( bundle [ 0 ] ) . toBe ( '/* my-module-3/main.css */\n\n/* my-module-3/dep.css */\n\n/* dep/main.css */\n' ) ;
226
223
expect ( bundle [ 1 ] ) . toBe ( '/* my-module-2/main.css */\n' ) ;
227
224
expect ( bundle [ 2 ] ) . toBe ( '/* my-module-1/main.css */\n' ) ;
228
225
done ( ) ;
@@ -233,28 +230,21 @@ test('new Reader([s1,s2,s3,s4]) ensure dedupe and correct css concat order', don
233
230
test ( 'new Reader([s1,s2,s3,s4]) operates correctly under slow speed conditions' , done => {
234
231
expect . assertions ( 3 ) ;
235
232
const sink = new SinkFs ( {
236
- path : path . join ( __dirname , './test-assets' )
233
+ path : path . join ( __dirname , './test-assets' ) ,
237
234
} ) ;
238
235
239
236
const feedStream1 = createSlowStream ( sink , 'a.json' , 800 ) ;
240
237
const feedStream2 = sink . reader ( 'b.json' ) ;
241
238
const feedStream3 = createSlowStream ( sink , 'c.json' , 500 ) ;
242
239
const feedStream4 = createSlowStream ( sink , 'd.json' , 100 ) ;
243
240
244
- const reader = new Reader ( [
245
- feedStream1 ,
246
- feedStream2 ,
247
- feedStream3 ,
248
- feedStream4
249
- ] ) ;
241
+ const reader = new Reader ( [ feedStream1 , feedStream2 , feedStream3 , feedStream4 ] ) ;
250
242
251
243
reader . on ( 'pipeline ready' , ( ) => {
252
- let bundle = [ ] ;
244
+ const bundle = [ ] ;
253
245
reader . on ( 'data' , data => bundle . push ( data . toString ( ) ) ) ;
254
246
reader . on ( 'end' , ( ) => {
255
- expect ( bundle [ 0 ] ) . toBe (
256
- '/* my-module-3/main.css */\n\n/* my-module-3/dep.css */\n\n/* dep/main.css */\n'
257
- ) ;
247
+ expect ( bundle [ 0 ] ) . toBe ( '/* my-module-3/main.css */\n\n/* my-module-3/dep.css */\n\n/* dep/main.css */\n' ) ;
258
248
expect ( bundle [ 1 ] ) . toBe ( '/* my-module-2/main.css */\n' ) ;
259
249
expect ( bundle [ 2 ] ) . toBe ( '/* my-module-1/main.css */\n' ) ;
260
250
done ( ) ;
@@ -269,21 +259,16 @@ test('compareByOrder(a, b) a and b are the same', () => {
269
259
270
260
test ( 'sort() transform operating on stream items without order property' , done => {
271
261
expect . assertions ( 1 ) ;
272
- const items = [
273
- { order : 1 } ,
274
- { order : null } ,
275
- { order : undefined } ,
276
- { noOrder : 'hi' }
277
- ] ;
262
+ const items = [ { order : 1 } , { order : null } , { order : undefined } , { noOrder : 'hi' } ] ;
278
263
const stream = new Readable ( {
279
264
objectMode : true ,
280
- read ( ) {
265
+ read ( ) {
281
266
if ( ! items . length ) {
282
267
this . push ( null ) ;
283
268
return ;
284
269
}
285
270
this . push ( items . shift ( ) ) ;
286
- }
271
+ } ,
287
272
} ) ;
288
273
289
274
const buffer = [ ] ;
0 commit comments