@@ -25,6 +25,22 @@ var createVinyl = function createVinyl(filename, contents) {
25
25
} ) ;
26
26
} ;
27
27
28
+ var normaliseEOL = function ( str ) {
29
+ if ( typeof ( str ) === 'object' ) {
30
+ str = str . toString ( 'utf8' ) ;
31
+ }
32
+
33
+ return str . replace ( / \r \n / g, '\n' ) ;
34
+ }
35
+
36
+ describe ( 'test helpers' , function ( ) {
37
+ it ( 'should normalise EOL' , function ( done ) {
38
+ should . equal ( normaliseEOL ( 'foo\r\nbar' ) , 'foo\nbar' ) ;
39
+ should . equal ( normaliseEOL ( 'foo\nbar' ) , 'foo\nbar' ) ;
40
+ done ( ) ;
41
+ } ) ;
42
+ } ) ;
43
+
28
44
describe ( 'gulp-sass -- async compile' , function ( ) {
29
45
it ( 'should pass file when it isNull()' , function ( done ) {
30
46
var stream = sass ( ) ;
@@ -66,8 +82,8 @@ describe('gulp-sass -- async compile', function() {
66
82
should . exist ( cssFile . relative ) ;
67
83
should . exist ( cssFile . contents ) ;
68
84
should . equal ( path . basename ( cssFile . path ) , 'empty.css' ) ;
69
- String ( cssFile . contents ) . should . equal (
70
- fs . readFileSync ( path . join ( __dirname , 'expected/ empty.css' ) , 'utf8' )
85
+ String ( normaliseEOL ( cssFile . contents ) ) . should . equal (
86
+ normaliseEOL ( fs . readFileSync ( path . join ( __dirname , 'expected' , ' empty.css') , 'utf8' ) )
71
87
) ;
72
88
done ( ) ;
73
89
} ) ;
@@ -82,8 +98,8 @@ describe('gulp-sass -- async compile', function() {
82
98
should . exist ( cssFile . path ) ;
83
99
should . exist ( cssFile . relative ) ;
84
100
should . exist ( cssFile . contents ) ;
85
- String ( cssFile . contents ) . should . equal (
86
- fs . readFileSync ( path . join ( __dirname , 'expected/ mixins.css' ) , 'utf8' )
101
+ String ( normaliseEOL ( cssFile . contents ) ) . should . equal (
102
+ normaliseEOL ( fs . readFileSync ( path . join ( __dirname , 'expected' , ' mixins.css') , 'utf8' ) )
87
103
) ;
88
104
done ( ) ;
89
105
} ) ;
@@ -97,18 +113,18 @@ describe('gulp-sass -- async compile', function() {
97
113
] ;
98
114
var stream = sass ( ) ;
99
115
var mustSee = files . length ;
100
- var expectedPath = 'expected/ mixins.css' ;
116
+ var expectedPath = path . join ( 'expected' , ' mixins.css') ;
101
117
102
118
stream . on ( 'data' , function ( cssFile ) {
103
119
should . exist ( cssFile ) ;
104
120
should . exist ( cssFile . path ) ;
105
121
should . exist ( cssFile . relative ) ;
106
122
should . exist ( cssFile . contents ) ;
107
123
if ( cssFile . path . indexOf ( 'variables' ) !== - 1 ) {
108
- expectedPath = 'expected/ variables.css' ;
124
+ expectedPath = path . join ( 'expected' , ' variables.css') ;
109
125
}
110
- String ( cssFile . contents ) . should . equal (
111
- fs . readFileSync ( path . join ( __dirname , expectedPath ) , 'utf8' )
126
+ String ( normaliseEOL ( cssFile . contents ) ) . should . equal (
127
+ normaliseEOL ( fs . readFileSync ( path . join ( __dirname , expectedPath ) , 'utf8' ) )
112
128
) ;
113
129
mustSee -- ;
114
130
if ( mustSee <= 0 ) {
@@ -129,8 +145,8 @@ describe('gulp-sass -- async compile', function() {
129
145
should . exist ( cssFile . path ) ;
130
146
should . exist ( cssFile . relative ) ;
131
147
should . exist ( cssFile . contents ) ;
132
- String ( cssFile . contents ) . should . equal (
133
- fs . readFileSync ( path . join ( __dirname , 'expected/ inheritance.css' ) , 'utf8' )
148
+ String ( normaliseEOL ( cssFile . contents ) ) . should . equal (
149
+ normaliseEOL ( fs . readFileSync ( path . join ( __dirname , 'expected' , ' inheritance.css') , 'utf8' ) )
134
150
) ;
135
151
done ( ) ;
136
152
} ) ;
@@ -145,11 +161,11 @@ describe('gulp-sass -- async compile', function() {
145
161
// Error must include message body
146
162
err . message . indexOf ( 'property "font" must be followed by a \':\'' ) . should . not . equal ( - 1 ) ;
147
163
// Error must include file error occurs in
148
- err . message . indexOf ( 'test/ scss/ error.scss' ) . should . not . equal ( - 1 ) ;
164
+ err . message . indexOf ( 'test' , ' scss' , ' error.scss') . should . not . equal ( - 1 ) ;
149
165
// Error must include line and column error occurs on
150
166
err . message . indexOf ( 'on line 2' ) . should . not . equal ( - 1 ) ;
151
167
// Error must include relativePath property
152
- err . relativePath . should . equal ( 'test/ scss/ error.scss' ) ;
168
+ err . relativePath . should . equal ( path . join ( 'test' , ' scss' , ' error.scss') ) ;
153
169
done ( ) ;
154
170
} ) ;
155
171
stream . write ( errorFile ) ;
@@ -180,11 +196,11 @@ describe('gulp-sass -- async compile', function() {
180
196
stream . on ( 'data' , function ( cssFile ) {
181
197
should . exist ( cssFile ) ;
182
198
should . exist ( cssFile . path ) ;
183
- cssFile . path . split ( '/' ) . pop ( ) . should . equal ( 'mixin--changed.css' ) ;
199
+ cssFile . path . split ( path . sep ) . pop ( ) . should . equal ( 'mixin--changed.css' ) ;
184
200
should . exist ( cssFile . relative ) ;
185
201
should . exist ( cssFile . contents ) ;
186
- String ( cssFile . contents ) . should . equal (
187
- fs . readFileSync ( path . join ( __dirname , 'expected/ mixins.css' ) , 'utf8' )
202
+ String ( normaliseEOL ( cssFile . contents ) ) . should . equal (
203
+ normaliseEOL ( fs . readFileSync ( path . join ( __dirname , 'expected' , ' mixins.css') , 'utf8' ) )
188
204
) ;
189
205
done ( ) ;
190
206
} ) ;
@@ -204,8 +220,8 @@ describe('gulp-sass -- async compile', function() {
204
220
should . exist ( cssFile . path ) ;
205
221
should . exist ( cssFile . relative ) ;
206
222
should . exist ( cssFile . contents ) ;
207
- String ( cssFile . contents ) . should . equal ( '/* Added Dynamically */\n' +
208
- fs . readFileSync ( path . join ( __dirname , 'expected/ mixins.css' ) , 'utf8' )
223
+ String ( normaliseEOL ( cssFile . contents ) ) . should . equal ( '/* Added Dynamically */\n' +
224
+ normaliseEOL ( fs . readFileSync ( path . join ( __dirname , 'expected' , ' mixins.css') , 'utf8' ) )
209
225
) ;
210
226
done ( ) ;
211
227
} ) ;
@@ -250,8 +266,8 @@ describe('gulp-sass -- async compile', function() {
250
266
should . exist ( cssFile . path ) ;
251
267
should . exist ( cssFile . relative ) ;
252
268
should . exist ( cssFile . contents ) ;
253
- String ( cssFile . contents ) . should . equal (
254
- fs . readFileSync ( path . join ( __dirname , 'expected/ indent.css' ) , 'utf8' )
269
+ String ( normaliseEOL ( cssFile . contents ) ) . should . equal (
270
+ normaliseEOL ( fs . readFileSync ( path . join ( __dirname , 'expected' , ' indent.css') , 'utf8' ) )
255
271
) ;
256
272
done ( ) ;
257
273
} ) ;
@@ -265,18 +281,18 @@ describe('gulp-sass -- async compile', function() {
265
281
] ;
266
282
var stream = sass ( ) ;
267
283
var mustSee = files . length ;
268
- var expectedPath = 'expected/ mixins.css' ;
284
+ var expectedPath = path . join ( 'expected' , ' mixins.css') ;
269
285
270
286
stream . on ( 'data' , function ( cssFile ) {
271
287
should . exist ( cssFile ) ;
272
288
should . exist ( cssFile . path ) ;
273
289
should . exist ( cssFile . relative ) ;
274
290
should . exist ( cssFile . contents ) ;
275
291
if ( cssFile . path . indexOf ( 'indent' ) !== - 1 ) {
276
- expectedPath = 'expected/ indent.css' ;
292
+ expectedPath = path . join ( 'expected' , ' indent.css') ;
277
293
}
278
- String ( cssFile . contents ) . should . equal (
279
- fs . readFileSync ( path . join ( __dirname , expectedPath ) , 'utf8' )
294
+ String ( normaliseEOL ( cssFile . contents ) ) . should . equal (
295
+ normaliseEOL ( fs . readFileSync ( path . join ( __dirname , expectedPath ) , 'utf8' ) )
280
296
) ;
281
297
mustSee -- ;
282
298
if ( mustSee <= 0 ) {
@@ -292,7 +308,7 @@ describe('gulp-sass -- async compile', function() {
292
308
293
309
describe ( 'gulp-sass -- sync compile' , function ( ) {
294
310
beforeEach ( function ( done ) {
295
- rimraf ( path . join ( __dirname , '/ results/ ' ) , done ) ;
311
+ rimraf ( path . join ( __dirname , 'results' ) , done ) ;
296
312
} ) ;
297
313
298
314
it ( 'should pass file when it isNull()' , function ( done ) {
@@ -334,8 +350,8 @@ describe('gulp-sass -- sync compile', function() {
334
350
should . exist ( cssFile . path ) ;
335
351
should . exist ( cssFile . relative ) ;
336
352
should . exist ( cssFile . contents ) ;
337
- String ( cssFile . contents ) . should . equal (
338
- fs . readFileSync ( path . join ( __dirname , 'expected/ mixins.css' ) , 'utf8' )
353
+ String ( normaliseEOL ( cssFile . contents ) ) . should . equal (
354
+ normaliseEOL ( fs . readFileSync ( path . join ( __dirname , 'expected' , ' mixins.css') , 'utf8' ) )
339
355
) ;
340
356
done ( ) ;
341
357
} ) ;
@@ -349,18 +365,18 @@ describe('gulp-sass -- sync compile', function() {
349
365
] ;
350
366
var stream = sass . sync ( ) ;
351
367
var mustSee = files . length ;
352
- var expectedPath = 'expected/ mixins.css' ;
368
+ var expectedPath = path . join ( 'expected' , ' mixins.css') ;
353
369
354
370
stream . on ( 'data' , function ( cssFile ) {
355
371
should . exist ( cssFile ) ;
356
372
should . exist ( cssFile . path ) ;
357
373
should . exist ( cssFile . relative ) ;
358
374
should . exist ( cssFile . contents ) ;
359
375
if ( cssFile . path . indexOf ( 'variables' ) !== - 1 ) {
360
- expectedPath = 'expected/ variables.css' ;
376
+ expectedPath = path . join ( 'expected' , ' variables.css') ;
361
377
}
362
- String ( cssFile . contents ) . should . equal (
363
- fs . readFileSync ( path . join ( __dirname , expectedPath ) , 'utf8' )
378
+ String ( normaliseEOL ( cssFile . contents ) ) . should . equal (
379
+ normaliseEOL ( fs . readFileSync ( path . join ( __dirname , expectedPath ) , 'utf8' ) )
364
380
) ;
365
381
mustSee -- ;
366
382
if ( mustSee <= 0 ) {
@@ -381,8 +397,8 @@ describe('gulp-sass -- sync compile', function() {
381
397
should . exist ( cssFile . path ) ;
382
398
should . exist ( cssFile . relative ) ;
383
399
should . exist ( cssFile . contents ) ;
384
- String ( cssFile . contents ) . should . equal (
385
- fs . readFileSync ( path . join ( __dirname , 'expected/ inheritance.css' ) , 'utf8' )
400
+ String ( normaliseEOL ( cssFile . contents ) ) . should . equal (
401
+ normaliseEOL ( fs . readFileSync ( path . join ( __dirname , 'expected' , ' inheritance.css') , 'utf8' ) )
386
402
) ;
387
403
done ( ) ;
388
404
} ) ;
@@ -395,7 +411,7 @@ describe('gulp-sass -- sync compile', function() {
395
411
396
412
stream . on ( 'error' , function ( err ) {
397
413
err . message . indexOf ( 'property "font" must be followed by a \':\'' ) . should . not . equal ( - 1 ) ;
398
- err . relativePath . should . equal ( 'test/ scss/ error.scss' ) ;
414
+ err . relativePath . should . equal ( path . join ( 'test' , ' scss' , ' error.scss') ) ;
399
415
done ( ) ;
400
416
} ) ;
401
417
stream . write ( errorFile ) ;
@@ -444,7 +460,7 @@ describe('gulp-sass -- sync compile', function() {
444
460
'inheritance.scss' ,
445
461
] ;
446
462
447
- gulp . src ( path . join ( __dirname , '/ scss/ inheritance.scss' ) )
463
+ gulp . src ( path . join ( __dirname , 'scss' , ' inheritance.scss') )
448
464
. pipe ( sourcemaps . init ( ) )
449
465
. pipe ( sass . sync ( ) )
450
466
. pipe ( tap ( function ( file ) {
@@ -453,7 +469,7 @@ describe('gulp-sass -- sync compile', function() {
453
469
} ) )
454
470
. pipe ( postcss ( [ autoprefixer ( ) ] ) )
455
471
. pipe ( sourcemaps . write ( ) )
456
- . pipe ( gulp . dest ( path . join ( __dirname , '/ results/ ' ) ) )
472
+ . pipe ( gulp . dest ( path . join ( __dirname , 'results' ) ) )
457
473
. pipe ( tap ( function ( file ) {
458
474
should . exist ( file . sourceMap ) ;
459
475
file . sourceMap . sources . should . eql ( expectedSourcesAfter ) ;
@@ -463,19 +479,22 @@ describe('gulp-sass -- sync compile', function() {
463
479
464
480
it ( 'should work with gulp-sourcemaps and a globbed source' , function ( done ) {
465
481
var files , filesContent , actualContent , expectedContent , globPath ;
466
- files = globule . find ( path . join ( __dirname , '/scss/globbed/**/*.scss' ) ) ;
482
+ globPath = path . join ( __dirname , 'scss' , 'globbed' ) ;
483
+ files = globule . find ( path . join ( __dirname , 'scss' , 'globbed' , '**' , '*.scss' ) ) ;
467
484
filesContent = { } ;
485
+
468
486
files . forEach ( function ( file ) {
469
- globPath = file . replace ( path . join ( __dirname , '/scss/globbed/' ) , '' ) ;
470
- filesContent [ globPath ] = fs . readFileSync ( file , 'utf8' ) ;
487
+ var source = path . normalize ( path . relative ( globPath , file ) ) ;
488
+ filesContent [ source ] = fs . readFileSync ( file , 'utf8' ) ;
471
489
} ) ;
472
- gulp . src ( path . join ( __dirname , '/scss/globbed/**/*.scss' ) )
490
+
491
+ gulp . src ( path . join ( __dirname , 'scss' , 'globbed' , '**' , '*.scss' ) )
473
492
. pipe ( sourcemaps . init ( ) )
474
493
. pipe ( sass . sync ( ) )
475
494
. pipe ( tap ( function ( file ) {
476
495
should . exist ( file . sourceMap ) ;
477
- actualContent = file . sourceMap . sourcesContent [ 0 ] ;
478
- expectedContent = filesContent [ file . sourceMap . sources [ 0 ] ] ;
496
+ actualContent = normaliseEOL ( file . sourceMap . sourcesContent [ 0 ] ) ;
497
+ expectedContent = normaliseEOL ( filesContent [ path . normalize ( file . sourceMap . sources [ 0 ] ) ] ) ;
479
498
actualContent . should . eql ( expectedContent ) ;
480
499
} ) )
481
500
. on ( 'end' , done ) ;
@@ -494,7 +513,7 @@ describe('gulp-sass -- sync compile', function() {
494
513
'scss/inheritance.scss'
495
514
] ;
496
515
497
- gulp . src ( path . join ( __dirname , '/ scss/ inheritance.scss' ) , { 'base' : 'test' } )
516
+ gulp . src ( path . join ( __dirname , 'scss' , ' inheritance.scss') , { 'base' : 'test' } )
498
517
. pipe ( sourcemaps . init ( ) )
499
518
. pipe ( sass . sync ( ) )
500
519
. pipe ( tap ( function ( file ) {
@@ -510,12 +529,12 @@ describe('gulp-sass -- sync compile', function() {
510
529
} ) ;
511
530
512
531
it ( 'should work with empty files' , function ( done ) {
513
- gulp . src ( path . join ( __dirname , '/ scss/ empty.scss' ) )
532
+ gulp . src ( path . join ( __dirname , 'scss' , ' empty.scss') )
514
533
. pipe ( sass . sync ( ) )
515
- . pipe ( gulp . dest ( path . join ( __dirname , '/ results/ ' ) ) )
534
+ . pipe ( gulp . dest ( path . join ( __dirname , 'results' ) ) )
516
535
. pipe ( tap ( function ( ) {
517
536
try {
518
- fs . statSync ( path . join ( __dirname , '/ results/ empty.css' ) ) ;
537
+ fs . statSync ( path . join ( __dirname , 'results' , ' empty.css') ) ;
519
538
}
520
539
catch ( e ) {
521
540
should . fail ( false , true , 'Empty file was produced' ) ;
0 commit comments