1
- const buffer = require ( 'vinyl-buffer' ) ;
2
1
const chai = require ( 'chai' ) ;
3
2
const cleanCSS = require ( '..' ) ;
4
3
const concat = require ( 'gulp-concat' ) ;
5
- const del = require ( 'del' ) ;
6
4
const expect = chai . expect ;
7
5
const File = require ( 'vinyl' ) ;
8
6
const gulp = require ( 'gulp' ) ;
@@ -14,305 +12,307 @@ const vfsFake = require('vinyl-fs-fake');
14
12
chai . should ( ) ;
15
13
chai . use ( require ( 'chai-string' ) ) ;
16
14
17
- describe ( 'gulp-clean-css: init' , function ( ) {
15
+ describe ( 'gulp-clean-css: init' , ( ) => {
18
16
19
- it ( 'should return the gulp-clean-css object: required export' , function ( ) {
17
+ it ( 'should return the gulp-clean-css object: required export' , ( ) => {
20
18
expect ( cleanCSS ) . to . exist ;
21
19
} ) ;
22
20
} ) ;
23
21
24
- describe ( 'gulp-clean-css: base functionality' , function ( ) {
22
+ describe ( 'gulp-clean-css: base functionality' , ( ) => {
25
23
26
- it ( 'should play nicely with other plugins: gulp-sass: before' , function ( done ) {
27
- var i = 0 ;
24
+ it ( 'should play nicely with other plugins: gulp-sass: before' , done => {
25
+
26
+ let i = 0 ;
28
27
29
28
gulp . src ( [ 'test/fixtures/**/*.scss' , '!test/fixtures/empty/**' , '!test/fixtures/sourcemaps-load/**' ] )
30
- . pipe ( gulpSass ( ) )
31
- . pipe ( cleanCSS ( ) )
32
- . pipe ( rename ( {
33
- suffix : '.generated' ,
34
- } ) )
35
- . pipe ( gulp . dest ( 'test/fixtures/' ) )
36
- . on ( 'data' , function ( file ) {
37
- i += 1 ;
38
- } )
39
- . once ( 'end' , function ( ) {
40
- i . should . equal ( 3 ) ;
41
- done ( ) ;
42
- } ) ;
29
+ . pipe ( gulpSass ( ) )
30
+ . pipe ( cleanCSS ( ) )
31
+ . pipe ( rename ( {
32
+ suffix : '.generated' ,
33
+ } ) )
34
+ . pipe ( gulp . dest ( 'test/fixtures/' ) )
35
+ . on ( 'data' , file => {
36
+ i += 1 ;
37
+ } )
38
+ . once ( 'end' , ( ) => {
39
+ i . should . equal ( 3 ) ;
40
+ done ( ) ;
41
+ } ) ;
43
42
} ) ;
44
43
45
- it ( 'should allow the file through' , function ( done ) {
46
- var i = 0 ;
44
+ it ( 'should allow the file through' , done => {
45
+
46
+ let i = 0 ;
47
47
48
48
gulp . src ( 'test/fixtures/test.css' )
49
- . pipe ( cleanCSS ( ) )
50
- . on ( 'data' , function ( file ) {
51
- i += 1 ;
52
- } )
53
- . once ( 'end' , function ( ) {
54
- i . should . equal ( 1 ) ;
55
- done ( ) ;
56
- } ) ;
49
+ . pipe ( cleanCSS ( ) )
50
+ . on ( 'data' , file => {
51
+ i += 1 ;
52
+ } )
53
+ . once ( 'end' , ( ) => {
54
+ i . should . equal ( 1 ) ;
55
+ done ( ) ;
56
+ } ) ;
57
57
} ) ;
58
58
59
- it ( 'should allow the file through:empty file, pipe dest' , function ( done ) {
60
- var i = 0 ;
59
+ it ( 'should allow the file through:empty file, pipe dest' , done => {
60
+
61
+ let i = 0 ;
61
62
62
63
gulp . src ( 'test/fixtures/empty/**/*.scss' )
63
- . pipe ( gulpSass ( ) )
64
- . pipe ( cleanCSS ( ) )
65
- . pipe ( rename ( {
66
- suffix : '.generated' ,
67
- } ) )
68
- . pipe ( gulp . dest ( function ( file ) {
69
- return file . base + '/empty-parsed' ;
70
- } ) )
71
- . on ( 'data' , function ( file ) {
72
- i += 1 ;
73
- } )
74
- . once ( 'end' , function ( ) {
75
- i . should . equal ( 3 ) ;
76
- done ( ) ;
77
- } ) ;
64
+ . pipe ( gulpSass ( ) )
65
+ . pipe ( cleanCSS ( ) )
66
+ . pipe ( rename ( {
67
+ suffix : '.generated' ,
68
+ } ) )
69
+ // .pipe(gulp.dest(file => {
70
+ // return file.base + '/empty-parsed';
71
+ // }))
72
+ . pipe ( gulp . dest ( file => `${ file . base } /empty-parsed` ) )
73
+ . on ( 'data' , file => {
74
+ i += 1 ;
75
+ } )
76
+ . once ( 'end' , ( ) => {
77
+ i . should . equal ( 3 ) ;
78
+ done ( ) ;
79
+ } ) ;
78
80
} ) ;
79
81
80
- it ( 'should produce the expected file' , function ( done ) {
82
+ it ( 'should produce the expected file' , done => {
81
83
82
- var mockFile = new File ( {
84
+ let mockFile = new File ( {
83
85
cwd : '/' ,
84
86
base : '/test/' ,
85
87
path : '/test/expected.test.css' ,
86
88
contents : new Buffer ( 'p{text-align:center;color:green}' )
87
89
} ) ;
88
90
89
91
gulp . src ( 'test/fixtures/test.css' )
90
- . pipe ( cleanCSS ( ) )
91
- . on ( 'data' , function ( file ) {
92
- file . contents . should . exist && expect ( file . contents . toString ( ) ) . to . equal ( mockFile . contents . toString ( ) ) ;
93
- done ( ) ;
94
- } ) ;
92
+ . pipe ( cleanCSS ( ) )
93
+ . on ( 'data' , file => {
94
+ file . contents . should . exist && expect ( file . contents . toString ( ) ) . to . equal ( mockFile . contents . toString ( ) ) ;
95
+ done ( ) ;
96
+ } ) ;
95
97
} ) ;
96
98
97
- it ( 'should minify the css: empty file, no `file.contents`' , function ( done ) {
99
+ it ( 'should minify the css: empty file, no `file.contents`' , done => {
98
100
99
- var i = 0 ;
101
+ let i = 0 ;
100
102
101
- var mockFile = new File ( {
103
+ let mockFile = new File ( {
102
104
cwd : '/' ,
103
105
base : '/test/' ,
104
106
path : '/test/expected.test.css' ,
105
107
contents : undefined
106
108
} ) ;
107
109
108
110
vfsFake . src ( mockFile )
109
- . pipe ( cleanCSS ( ) )
110
- . on ( 'data' , function ( file ) {
111
- i += 1 ;
112
- } )
113
- . once ( 'end' , function ( ) {
114
- i . should . equal ( 1 ) ;
115
- done ( ) ;
116
- } ) ;
111
+ . pipe ( cleanCSS ( ) )
112
+ . on ( 'data' , file => {
113
+ i += 1 ;
114
+ } )
115
+ . once ( 'end' , ( ) => {
116
+ i . should . equal ( 1 ) ;
117
+ done ( ) ;
118
+ } ) ;
117
119
} ) ;
118
120
119
- it ( 'should invoke optional callback with details specified in options: debug' , function ( done ) {
121
+ it ( 'should invoke optional callback with details specified in options: debug' , done => {
120
122
gulp . src ( 'test/fixtures/test.css' )
121
- . pipe ( cleanCSS ( { debug : true } , function ( details ) {
122
- details . stats . should . exist &&
123
- details . stats . originalSize . should . exist &&
124
- details . stats . minifiedSize . should . exist ;
125
- } ) )
126
- . on ( 'data' , function ( file ) {
127
- done ( ) ;
128
- } ) ;
123
+ . pipe ( cleanCSS ( { debug : true } , ( details ) => {
124
+ details . stats . should . exist &&
125
+ details . stats . originalSize . should . exist &&
126
+ details . stats . minifiedSize . should . exist ;
127
+ } ) )
128
+ . on ( 'data' , file => {
129
+ done ( ) ;
130
+ } ) ;
129
131
} ) ;
130
132
131
- it ( 'should invoke optional callback with out options object supplied: return object hash' , function ( done ) {
133
+ it ( 'should invoke optional callback with out options object supplied: return object hash' , done => {
132
134
gulp . src ( 'test/fixtures/test.css' )
133
- . pipe ( cleanCSS ( function ( details ) {
134
- details . stats . should . exist &&
135
- expect ( details ) . to . have . ownProperty ( 'stats' ) &&
136
- expect ( details ) . to . have . ownProperty ( 'errors' ) &&
137
- expect ( details ) . to . have . ownProperty ( 'warnings' ) &&
138
- expect ( details ) . to . not . have . ownProperty ( 'sourceMap' ) ;
139
- } ) )
140
- . on ( 'data' , function ( file ) {
141
- done ( ) ;
142
- } ) ;
135
+ . pipe ( cleanCSS ( details => {
136
+ details . stats . should . exist &&
137
+ expect ( details ) . to . have . ownProperty ( 'stats' ) &&
138
+ expect ( details ) . to . have . ownProperty ( 'errors' ) &&
139
+ expect ( details ) . to . have . ownProperty ( 'warnings' ) &&
140
+ expect ( details ) . to . not . have . ownProperty ( 'sourceMap' ) ;
141
+ } ) )
142
+ . on ( 'data' , ( file ) => {
143
+ done ( ) ;
144
+ } ) ;
143
145
} ) ;
144
146
145
- it ( 'should invoke optional callback without options object supplied: return object hash with sourceMap: true; return correct hash' , function ( done ) {
147
+ it ( 'should invoke optional callback without options object supplied: return object hash with sourceMap: true; return correct hash' , done => {
146
148
gulp . src ( 'test/fixtures/test.css' )
147
- . pipe ( cleanCSS ( { sourceMap : true } , function ( details ) {
148
- details . stats . should . exist &&
149
- expect ( details ) . have . ownProperty ( 'sourceMap' ) ;
150
- } ) )
151
- . on ( 'data' , function ( file ) {
152
- done ( ) ;
153
- } ) ;
149
+ . pipe ( cleanCSS ( { sourceMap : true } , details => {
150
+ details . stats . should . exist &&
151
+ expect ( details ) . have . ownProperty ( 'sourceMap' ) ;
152
+ } ) )
153
+ . on ( 'data' , file => {
154
+ done ( ) ;
155
+ } ) ;
154
156
} ) ;
155
157
156
- it ( 'should invoke optional callback with file details returned' , function ( done ) {
158
+ it ( 'should invoke optional callback with file details returned' , done => {
157
159
158
- var expected = 'test.css'
160
+ let expected = 'test.css' ;
159
161
160
162
gulp . src ( 'test/fixtures/test.css' )
161
- . pipe ( cleanCSS ( function ( details ) {
162
- details . name . should . equal ( expected )
163
- } ) )
164
- . on ( 'data' , function ( file ) {
165
- done ( ) ;
166
- } ) ;
163
+ . pipe ( cleanCSS ( details => {
164
+ details . name . should . equal ( expected )
165
+ } ) )
166
+ . on ( 'data' , file => {
167
+ done ( ) ;
168
+ } ) ;
167
169
} ) ;
168
170
169
- it ( 'should write sourcemaps' , function ( done ) {
171
+ it ( 'should write sourcemaps' , done => {
170
172
171
- var i = 0 ;
173
+ let i = 0 ;
172
174
173
175
gulp . src ( [ 'test/fixtures/sourcemaps/**/*.css' , '!test/fixtures/sourcemaps/**/*.generated.css' ] )
174
- . pipe ( sourcemaps . init ( ) )
175
- . pipe ( concat ( 'sourcemapped.css' ) )
176
- . pipe ( cleanCSS ( ) )
177
- . pipe ( rename ( {
178
- suffix : '.generated' ,
179
- } ) )
180
- . on ( 'data' , function ( file ) {
181
- i += 1 ;
182
- } )
183
- . pipe ( sourcemaps . write ( ) )
184
- . pipe ( gulp . dest ( function ( file ) {
185
- return file . base ;
186
- } ) )
187
- . once ( 'end' , function ( ) {
188
- i . should . equal ( 1 ) ;
189
- done ( ) ;
190
- } ) ;
176
+ . pipe ( sourcemaps . init ( ) )
177
+ . pipe ( concat ( 'sourcemapped.css' ) )
178
+ . pipe ( cleanCSS ( ) )
179
+ . pipe ( rename ( {
180
+ suffix : '.generated' ,
181
+ } ) )
182
+ . on ( 'data' , file => {
183
+ i += 1 ;
184
+ } )
185
+ . pipe ( sourcemaps . write ( ) )
186
+ . pipe ( gulp . dest ( file => file . base ) )
187
+ . once ( 'end' , ( ) => {
188
+ i . should . equal ( 1 ) ;
189
+ done ( ) ;
190
+ } ) ;
191
191
} ) ;
192
192
193
- it ( 'should write sourcemaps, worrectly map output' , function ( done ) {
193
+ it ( 'should write sourcemaps, worrectly map output' , done => {
194
194
195
- var i = 0 ;
195
+ let i = 0 ;
196
196
197
197
gulp . src ( 'test/fixtures/sourcemaps-load/scss/test-sass.scss' )
198
- . pipe ( sourcemaps . init ( ) )
199
- . pipe ( gulpSass ( ) )
200
- . pipe ( sourcemaps . init ( { loadMaps : true } ) )
201
- . pipe ( cleanCSS ( { sourceMapInlineSources : true } ) )
202
- . on ( 'data' , function ( file ) {
203
- i += 1 ;
204
- } )
205
- . pipe ( rename ( {
206
- suffix : '.min'
207
- } ) )
208
- . pipe ( sourcemaps . write ( ) )
209
- . pipe ( gulp . dest ( 'test/fixtures/sourcemaps-load/min' ) )
210
- . once ( 'end' , function ( ) {
211
- i . should . equal ( 1 ) ; // todo inspect mapping here
212
- done ( ) ;
213
- } ) ;
198
+ . pipe ( sourcemaps . init ( ) )
199
+ . pipe ( gulpSass ( ) )
200
+ . pipe ( sourcemaps . init ( { loadMaps : true } ) )
201
+ . pipe ( cleanCSS ( { sourceMapInlineSources : true } ) )
202
+ . on ( 'data' , file => {
203
+ i += 1 ;
204
+ } )
205
+ . pipe ( rename ( {
206
+ suffix : '.min'
207
+ } ) )
208
+ . pipe ( sourcemaps . write ( ) )
209
+ . pipe ( gulp . dest ( 'test/fixtures/sourcemaps-load/min' ) )
210
+ . once ( 'end' , ( ) => {
211
+ i . should . equal ( 1 ) ; // todo inspect mapping here
212
+ done ( ) ;
213
+ } ) ;
214
214
} ) ;
215
215
216
- it ( 'should return a warning for improper syntax' , function ( done ) {
216
+ it ( 'should return a warning for improper syntax' , done => {
217
217
218
- var i = 0 ;
218
+ let i = 0 ;
219
219
220
- var css = new File ( {
220
+ let css = new File ( {
221
221
path : './fixtures/test.css' ,
222
222
contents : new Buffer ( 'body{color:red' )
223
223
} ) ;
224
224
225
225
vfsFake . src ( css )
226
- . pipe ( cleanCSS ( { debug : true } , function ( details ) {
227
- expect ( details . warnings ) . to . exist &&
228
- expect ( details . warnings . length ) . to . equal ( 1 ) &&
229
- expect ( details . warnings [ 0 ] ) . to . equal ( 'Missing \'}\' at fixtures/test.css:1:14.' ) ;
230
- } ) )
231
- . on ( 'data' , function ( file ) {
232
- i += 1 ;
233
- } )
234
- . once ( 'end' , function ( ) {
235
- i . should . equal ( 1 ) ;
236
- done ( ) ;
237
- } ) ;
226
+ . pipe ( cleanCSS ( { debug : true } , details => {
227
+ expect ( details . warnings ) . to . exist &&
228
+ expect ( details . warnings . length ) . to . equal ( 1 ) &&
229
+ expect ( details . warnings [ 0 ] ) . to . equal ( 'Missing \'}\' at fixtures/test.css:1:14.' ) ;
230
+ } ) )
231
+ . on ( 'data' , file => {
232
+ i += 1 ;
233
+ } )
234
+ . once ( 'end' , ( ) => {
235
+ i . should . equal ( 1 ) ;
236
+ done ( ) ;
237
+ } ) ;
238
238
} ) ;
239
239
240
- it ( 'should invoke a plugin error: streaming not supported' , function ( done ) {
240
+ it ( 'should invoke a plugin error: streaming not supported' , done => {
241
241
242
242
gulp . src ( 'test/fixtures/test.css' , { buffer : false } )
243
- . pipe ( cleanCSS ( )
244
- . on ( 'error' , function ( err ) {
245
- expect ( err . message ) . to . equal ( 'Streaming not supported!' )
246
- done ( ) ;
247
- } ) ) ;
243
+ . pipe ( cleanCSS ( )
244
+ . on ( 'error' , err => {
245
+ expect ( err . message ) . to . equal ( 'Streaming not supported!' ) ;
246
+ done ( ) ;
247
+ } ) ) ;
248
248
} ) ;
249
249
250
- it ( 'should return a clean-css error' , function ( done ) {
250
+ it ( 'should return a clean-css error' , done => {
251
251
252
- var css = new File ( {
252
+ let css = new File ( {
253
253
path : '/' ,
254
254
contents : new Buffer ( '@import url(/some/fake/file);' )
255
255
} ) ;
256
256
257
257
vfsFake . src ( css )
258
- . pipe ( cleanCSS ( ) )
259
- . on ( 'error' , function ( err ) {
260
- expect ( err ) . to . exist ;
261
- expect ( err ) . to . equal ( 'Ignoring local @import of "/some/fake/file" as resource is missing.' ) ;
262
- done ( ) ;
263
- } ) ;
258
+ . pipe ( cleanCSS ( ) )
259
+ . on ( 'error' , err => {
260
+ expect ( err ) . to . exist ;
261
+ expect ( err ) . to . equal ( 'Ignoring local @import of "/some/fake/file" as resource is missing.' ) ;
262
+ done ( ) ;
263
+ } ) ;
264
264
} ) ;
265
265
} ) ;
266
266
267
- describe ( 'gulp-clean-css: rebase' , function ( ) {
267
+ describe ( 'gulp-clean-css: rebase' , ( ) => {
268
268
269
- it ( 'should not rebase files by default - do not resolve relative files' , function ( done ) {
269
+ it ( 'should not rebase files by default - do not resolve relative files' , done => {
270
270
271
271
gulp . src ( [ 'test/fixtures/rebasing/subdir/insub.css' ] )
272
- . pipe ( cleanCSS ( { rebase : false } ) )
273
- . on ( 'data' , function ( file ) {
272
+ . pipe ( cleanCSS ( { rebase : false } ) )
273
+ . on ( 'data' , file => {
274
274
275
- let expected = `
275
+ let expected = `
276
276
p.insub_same{background:url(insub.png)}
277
277
p.insub_child{background:url(child/child.png)}
278
278
p.insub_parent{background:url(../parent.png)}
279
279
p.insub_other{background:url(../othersub/inother.png)}
280
280
p.insub_absolute{background:url(/inroot.png)}` ;
281
281
282
- let actual = file . contents . toString ( ) ;
282
+ let actual = file . contents . toString ( ) ;
283
283
284
- expect ( actual ) . to . equalIgnoreSpaces ( expected )
285
- } )
286
- . once ( 'end' , done ) ;
284
+ expect ( actual ) . to . equalIgnoreSpaces ( expected )
285
+ } )
286
+ . once ( 'end' , done ) ;
287
287
} ) ;
288
288
289
- it ( 'should by rebase files with target specified' , function ( done ) {
289
+ it ( 'should by rebase files with target specified' , done => {
290
290
291
291
gulp . src ( [ 'test/fixtures/rebasing/subdir/insub.css' ] )
292
- . pipe ( cleanCSS ( { rebaseTo : 'test' } ) )
293
- . on ( 'data' , function ( file ) {
292
+ . pipe ( cleanCSS ( { rebaseTo : 'test' } ) )
293
+ . on ( 'data' , file => {
294
294
295
- let expected = `
295
+ let expected = `
296
296
p.insub_same{background:url(fixtures/rebasing/subdir/insub.png)}
297
297
p.insub_child{background:url(fixtures/rebasing/subdir/child/child.png)}
298
298
p.insub_parent{background:url(fixtures/rebasing/parent.png)}
299
299
p.insub_other{background:url(fixtures/rebasing/othersub/inother.png)}
300
300
p.insub_absolute{background:url(/inroot.png)}` ;
301
301
302
- let actual = file . contents . toString ( ) ;
302
+ let actual = file . contents . toString ( ) ;
303
303
304
- expect ( actual ) . to . equalIgnoreSpaces ( expected ) ;
305
- } )
306
- . once ( 'end' , done ) ;
304
+ expect ( actual ) . to . equalIgnoreSpaces ( expected ) ;
305
+ } )
306
+ . once ( 'end' , done ) ;
307
307
} ) ;
308
308
309
- it ( 'should rebase to current relative file location - relative imports are resolved like in the browser' , function ( done ) {
309
+ it ( 'should rebase to current relative file location - relative imports are resolved like in the browser' , done => {
310
310
311
311
gulp . src ( [ 'test/fixtures/rebasing/subdir/import.css' ] )
312
- . pipe ( cleanCSS ( ) )
313
- . on ( 'data' , function ( file ) {
312
+ . pipe ( cleanCSS ( ) )
313
+ . on ( 'data' , file => {
314
314
315
- let expected = `
315
+ let expected = `
316
316
p.imported_nested{background:url(../otherdir/nestedsub/nested.png)}
317
317
p.imported_same{background:url(../otherdir/imported.png)}
318
318
p.imported_parent{background:url(../parent.png)}
@@ -325,10 +325,10 @@ describe('gulp-clean-css: rebase', function () {
325
325
p.insub_absolute{background:url(/inroot.png)}
326
326
p.import{background:url(import.png)}` ;
327
327
328
- let actual = file . contents . toString ( ) ;
328
+ let actual = file . contents . toString ( ) ;
329
329
330
- expect ( actual ) . to . equalIgnoreSpaces ( expected )
331
- } )
332
- . once ( 'end' , done ) ;
330
+ expect ( actual ) . to . equalIgnoreSpaces ( expected )
331
+ } )
332
+ . once ( 'end' , done ) ;
333
333
} ) ;
334
334
} ) ;
0 commit comments