@@ -17,7 +17,7 @@ chai.use(require('chai-string'));
17
17
describe ( 'gulp-clean-css: init' , function ( ) {
18
18
19
19
it ( 'should return the gulp-clean-css object: required export' , function ( ) {
20
- expect ( cleanCSS ) . to . be . function ;
20
+ expect ( cleanCSS ) . to . exist ;
21
21
} ) ;
22
22
} ) ;
23
23
@@ -27,54 +27,54 @@ describe('gulp-clean-css: base functionality', function () {
27
27
var i = 0 ;
28
28
29
29
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
- } ) ;
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
+ } ) ;
43
43
} ) ;
44
44
45
45
it ( 'should allow the file through' , function ( done ) {
46
46
var 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' , function ( file ) {
51
+ i += 1 ;
52
+ } )
53
+ . once ( 'end' , function ( ) {
54
+ i . should . equal ( 1 ) ;
55
+ done ( ) ;
56
+ } ) ;
57
57
} ) ;
58
58
59
59
it ( 'should allow the file through:empty file, pipe dest' , function ( done ) {
60
60
var i = 0 ;
61
61
62
62
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
- } ) ;
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
+ } ) ;
78
78
} ) ;
79
79
80
80
it ( 'should produce the expected file' , function ( done ) {
@@ -87,11 +87,11 @@ describe('gulp-clean-css: base functionality', function () {
87
87
} ) ;
88
88
89
89
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
- } ) ;
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
+ } ) ;
95
95
} ) ;
96
96
97
97
it ( 'should minify the css: empty file, no `file.contents`' , function ( done ) {
@@ -106,111 +106,111 @@ describe('gulp-clean-css: base functionality', function () {
106
106
} ) ;
107
107
108
108
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
- } ) ;
109
+ . pipe ( cleanCSS ( ) )
110
+ . on ( 'data' , function ( file ) {
111
+ i += 1 ;
112
+ } )
113
+ . once ( 'end' , function ( ) {
114
+ i . should . equal ( 1 ) ;
115
+ done ( ) ;
116
+ } ) ;
117
117
} ) ;
118
118
119
119
it ( 'should invoke optional callback with details specified in options: debug' , function ( done ) {
120
120
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
- } ) ;
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
+ } ) ;
129
129
} ) ;
130
130
131
131
it ( 'should invoke optional callback with out options object supplied: return object hash' , function ( done ) {
132
132
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
- } ) ;
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
+ } ) ;
143
143
} ) ;
144
144
145
145
it ( 'should invoke optional callback without options object supplied: return object hash with sourceMap: true; return correct hash' , function ( done ) {
146
146
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
- } ) ;
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
+ } ) ;
154
154
} ) ;
155
155
156
156
it ( 'should invoke optional callback with file details returned' , function ( done ) {
157
157
158
158
var expected = 'test.css'
159
159
160
160
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
- } ) ;
161
+ . pipe ( cleanCSS ( function ( details ) {
162
+ details . name . should . equal ( expected )
163
+ } ) )
164
+ . on ( 'data' , function ( file ) {
165
+ done ( ) ;
166
+ } ) ;
167
167
} ) ;
168
168
169
169
it ( 'should write sourcemaps' , function ( done ) {
170
170
171
171
var i = 0 ;
172
172
173
173
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
- } ) ;
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
+ } ) ;
191
191
} ) ;
192
192
193
193
it ( 'should write sourcemaps, worrectly map output' , function ( done ) {
194
194
195
195
var 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' , 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
+ } ) ;
214
214
} ) ;
215
215
216
216
it ( 'should return a warning for improper syntax' , function ( done ) {
@@ -223,28 +223,28 @@ describe('gulp-clean-css: base functionality', function () {
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 } , 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
+ } ) ;
238
238
} ) ;
239
239
240
240
it ( 'should invoke a plugin error: streaming not supported' , function ( 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' , function ( err ) {
245
+ expect ( err . message ) . to . equal ( 'Streaming not supported!' )
246
+ done ( ) ;
247
+ } ) ) ;
248
248
} ) ;
249
249
250
250
it ( 'should return a clean-css error' , function ( done ) {
@@ -255,12 +255,12 @@ describe('gulp-clean-css: base functionality', function () {
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' , 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
+ } ) ;
264
264
} ) ;
265
265
} ) ;
266
266
@@ -269,50 +269,50 @@ describe('gulp-clean-css: rebase', function () {
269
269
it ( 'should not rebase files by default - do not resolve relative files' , function ( 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' , function ( 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
289
it ( 'should by rebase files with target specified' , function ( 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' , function ( 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
309
it ( 'should rebase to current relative file location - relative imports are resolved like in the browser' , function ( 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' , function ( 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