@@ -5,8 +5,11 @@ var assert = require('assert'),
5
5
glob = require ( 'glob' ) ,
6
6
rimraf = require ( 'rimraf' ) ,
7
7
stream = require ( 'stream' ) ,
8
+ once = require ( 'lodash.once' ) ,
8
9
spawn = require ( 'cross-spawn' ) ,
9
10
cli = path . join ( __dirname , '..' , 'bin' , 'node-sass' ) ,
11
+ touch = require ( 'touch' ) ,
12
+ tmpDir = require ( 'unique-temp-dir' ) ,
10
13
fixture = path . join . bind ( null , __dirname , 'fixtures' ) ;
11
14
12
15
describe ( 'cli' , function ( ) {
@@ -226,165 +229,182 @@ describe('cli', function() {
226
229
} , 100 ) ;
227
230
} ) ;
228
231
229
- it . skip ( 'should emit `warn` on file change when using --watch option' , function ( done ) {
230
- var src = fixture ( 'simple/tmp.scss' ) ;
231
-
232
- fs . writeFileSync ( src , '' ) ;
232
+ it ( 'should emit `warn` on file change when using --watch option' , function ( done ) {
233
+ var src = fixture ( 'watching-dir-01/index.scss' ) ;
233
234
234
235
var bin = spawn ( cli , [ '--watch' , src ] ) ;
235
236
236
237
bin . stderr . setEncoding ( 'utf8' ) ;
237
238
bin . stderr . once ( 'data' , function ( data ) {
238
239
assert . strictEqual ( data . trim ( ) , '=> changed: ' + src ) ;
239
- fs . unlinkSync ( src ) ;
240
240
bin . kill ( ) ;
241
+ } ) ;
242
+ bin . on ( 'error' , function ( err ) {
243
+ assert . fail ( err ) ;
241
244
done ( ) ;
242
245
} ) ;
246
+ bin . on ( 'exit' , done ) ;
243
247
244
248
setTimeout ( function ( ) {
245
- fs . appendFileSync ( src , 'body {}' ) ;
249
+ touch . sync ( src ) ;
246
250
} , 500 ) ;
247
- } ) ;
251
+ } ) . timeout ( 5000 ) ;
248
252
249
- it . skip ( 'should emit nothing on file change when using --watch and --quiet options' , function ( done ) {
250
- var src = fixture ( 'simple/tmp.scss' ) ;
251
- var didEmit = false ;
252
- fs . writeFileSync ( src , '' ) ;
253
+ it ( 'should emit nothing on file change when using --watch and --quiet options' , function ( done ) {
254
+ var src = fixture ( 'watching-dir-01/index.scss' ) ;
253
255
254
256
var bin = spawn ( cli , [ '--watch' , '--quiet' , src ] ) ;
255
257
256
258
bin . stderr . setEncoding ( 'utf8' ) ;
257
259
bin . stderr . once ( 'data' , function ( ) {
258
- didEmit = true ;
260
+ assert . fail ( 'should not emit console output with --quiet flag' ) ;
261
+ } ) ;
262
+ bin . on ( 'error' , function ( err ) {
263
+ assert . fail ( err ) ;
264
+ done ( ) ;
259
265
} ) ;
266
+ bin . on ( 'exit' , done ) ;
260
267
261
268
setTimeout ( function ( ) {
262
- fs . appendFileSync ( src , 'body {}' ) ;
263
- setTimeout ( function ( ) {
264
- assert . equal ( didEmit , false ) ;
265
- bin . kill ( ) ;
266
- done ( ) ;
267
- fs . unlinkSync ( src ) ;
268
- } , 200 ) ;
269
+ touch ( src , { } , function ( err ) {
270
+ if ( err ) {
271
+ assert . fail ( err ) ;
272
+ }
273
+
274
+ setTimeout ( function ( ) {
275
+ bin . kill ( ) ;
276
+ } , 1000 ) ;
277
+ } ) ;
269
278
} , 500 ) ;
270
- } ) ;
279
+ } ) . timeout ( 5000 ) ;
271
280
272
- it . skip ( 'should render all watched files' , function ( done ) {
273
- var src = fixture ( 'simple/bar .scss' ) ;
281
+ it ( 'should render all watched files' , function ( done ) {
282
+ var src = fixture ( 'watching-dir-01/index .scss' ) ;
274
283
275
- fs . writeFileSync ( src , '' ) ;
276
-
277
- var bin = spawn ( cli , [
278
- '--output-style' , 'compressed' ,
279
- '--watch' , src
280
- ] ) ;
284
+ var bin = spawn ( cli , [ '--output-style' , 'compressed' , '--watch' , src ] ) ;
281
285
282
286
bin . stdout . setEncoding ( 'utf8' ) ;
283
287
bin . stdout . once ( 'data' , function ( data ) {
284
- assert . strictEqual ( data . trim ( ) , 'body{background:white}' ) ;
285
- fs . unlinkSync ( src ) ;
288
+ assert . strictEqual ( data . trim ( ) , 'a{color:green}' ) ;
286
289
bin . kill ( ) ;
290
+ } ) ;
291
+ bin . on ( 'error' , function ( err ) {
292
+ assert . fail ( err ) ;
287
293
done ( ) ;
288
294
} ) ;
295
+ bin . on ( 'exit' , done ) ;
289
296
290
297
setTimeout ( function ( ) {
291
- fs . appendFileSync ( src , 'body{background:white}' ) ;
298
+ touch . sync ( src ) ;
292
299
} , 500 ) ;
293
- } ) ;
300
+ } ) . timeout ( 5000 ) ;
294
301
295
- it . skip ( 'should watch the full scss dep tree for a single file (scss)' , function ( done ) {
302
+ it ( 'should watch the full scss dep tree for a single file (scss)' , function ( done ) {
296
303
var src = fixture ( 'watching/index.scss' ) ;
297
- var foo = fixture ( 'watching/white.scss' ) ;
304
+ var child = fixture ( 'watching/white.scss' ) ;
298
305
299
- fs . writeFileSync ( foo , '' ) ;
300
-
301
- var bin = spawn ( cli , [
302
- '--output-style' , 'compressed' ,
303
- '--watch' , src
304
- ] ) ;
306
+ var bin = spawn ( cli , [ '--output-style' , 'compressed' , '--watch' , src ] ) ;
305
307
306
308
bin . stdout . setEncoding ( 'utf8' ) ;
307
- bin . stdout . once ( 'data' , function ( data ) {
308
- assert . strictEqual ( data . trim ( ) , 'body{background:blue}' ) ;
309
- bin . kill ( ) ;
309
+ bin . stdout . once ( 'data' , function ( ) {
310
+ touch ( child , function ( ) {
311
+ bin . stdout . once ( 'data' , function ( data ) {
312
+ assert . strictEqual ( data . trim ( ) , 'body{background:white}' ) ;
313
+ bin . kill ( ) ;
314
+ } ) ;
315
+ } ) ;
316
+ } ) ;
317
+ bin . on ( 'error' , function ( err ) {
318
+ assert . fail ( err ) ;
310
319
done ( ) ;
311
320
} ) ;
321
+ bin . on ( 'exit' , done ) ;
322
+ } ) . timeout ( 5000 ) ;
312
323
313
- setTimeout ( function ( ) {
314
- fs . appendFileSync ( foo , 'body{background:blue}\n' ) ;
315
- } , 500 ) ;
316
- } ) ;
317
-
318
- it . skip ( 'should watch the full sass dep tree for a single file (sass)' , function ( done ) {
324
+ it ( 'should watch the full sass dep tree for a single file (sass)' , function ( done ) {
319
325
var src = fixture ( 'watching/index.sass' ) ;
320
- var foo = fixture ( 'watching/bar.sass' ) ;
321
-
322
- fs . writeFileSync ( foo , '' ) ;
326
+ var child = fixture ( 'watching/bar.sass' ) ;
323
327
324
- var bin = spawn ( cli , [
325
- '--output-style' , 'compressed' ,
326
- '--watch' , src
327
- ] ) ;
328
+ var bin = spawn ( cli , [ '--output-style' , 'compressed' , '--watch' , src ] ) ;
328
329
329
330
bin . stdout . setEncoding ( 'utf8' ) ;
330
- bin . stdout . once ( 'data' , function ( data ) {
331
- assert . strictEqual ( data . trim ( ) , 'body{background:red}' ) ;
332
- bin . kill ( ) ;
331
+ bin . stdout . once ( 'data' , function ( ) {
332
+ touch ( child , function ( ) {
333
+ bin . stdout . once ( 'data' , function ( data ) {
334
+ assert . strictEqual ( data . trim ( ) , 'body{background:white}' ) ;
335
+ bin . kill ( ) ;
336
+ } ) ;
337
+ } ) ;
338
+ } ) ;
339
+ bin . on ( 'error' , function ( err ) {
340
+ assert . fail ( err ) ;
333
341
done ( ) ;
334
342
} ) ;
343
+ bin . on ( 'exit' , done ) ;
335
344
336
345
setTimeout ( function ( ) {
337
- fs . appendFileSync ( foo , 'body\n\tbackground: red\n' ) ;
346
+ touch . sync ( child ) ;
338
347
} , 500 ) ;
339
348
} ) ;
340
- } ) ;
349
+ } ) . timeout ( 5000 ) ;
341
350
342
351
describe ( 'node-sass --output directory' , function ( ) {
343
- it . skip ( 'should watch whole directory' , function ( done ) {
344
- var destDir = fixture ( 'watching-css-out-01/' ) ;
352
+ it ( 'should watch whole directory' , function ( done ) {
353
+ var destDir = tmpDir ( {
354
+ create : true
355
+ } ) ;
345
356
var srcDir = fixture ( 'watching-dir-01/' ) ;
346
357
var srcFile = path . join ( srcDir , 'index.scss' ) ;
358
+ var w ;
347
359
348
- fs . writeFileSync ( srcFile , '' ) ;
360
+ var bin = spawn ( cli , [ '--output-style' , 'compressed' , '--output' , destDir , '--watch' , srcDir ] ) ;
349
361
350
- var bin = spawn ( cli , [
351
- '--output-style' , 'compressed' ,
352
- '--output' , destDir ,
353
- '--watch' , srcDir
354
- ] ) ;
362
+ bin . stdout . setEncoding ( 'utf8' ) ;
363
+ bin . stdout . once ( 'data' , function ( data ) {
364
+ assert . equal ( 'Watching ' + srcDir , data . trim ( ) ) ;
365
+ touch ( srcFile , function ( ) {
366
+ bin . stdout . once ( 'data' , function ( ) {
367
+ assert . fail ( 'should not emit console output when watching a directory' ) ;
368
+ } ) ;
369
+ } ) ;
370
+ } ) ;
371
+ bin . on ( 'error' , assert . fail ) ;
372
+ bin . on ( 'exit' , w . close ) ;
355
373
356
- setTimeout ( function ( ) {
357
- fs . appendFileSync ( srcFile , 'a {color:green;}\n' ) ;
358
- setTimeout ( function ( ) {
359
- bin . kill ( ) ;
360
- var files = fs . readdirSync ( destDir ) ;
374
+ w = fs . watch ( destDir , function ( ) {
375
+ bin . kill ( ) ;
376
+ fs . readdir ( destDir , function ( err , files ) {
361
377
assert . deepEqual ( files , [ 'index.css' ] ) ;
362
378
rimraf ( destDir , done ) ;
363
- } , 200 ) ;
364
- } , 500 ) ;
365
- } ) ;
379
+ } ) ;
380
+ } ) ;
381
+ } ) . timeout ( 5000 ) ;
366
382
367
- it . skip ( 'should compile all changed files in watched directory' , function ( done ) {
368
- var destDir = fixture ( 'watching-css-out-02/' ) ;
383
+ it ( 'should compile all changed files in watched directory' , function ( done ) {
384
+ var destDir = tmpDir ( {
385
+ create : true
386
+ } ) ;
369
387
var srcDir = fixture ( 'watching-dir-02/' ) ;
370
388
var srcFile = path . join ( srcDir , 'foo.scss' ) ;
371
389
372
- fs . writeFileSync ( srcFile , '' ) ;
390
+ var bin = spawn ( cli , [ '--output-style' , 'compressed' , '--output' , destDir , '--watch' , srcDir ] ) ;
373
391
374
- var bin = spawn ( cli , [
375
- '--output-style ', 'compressed' ,
376
- '-- output' , destDir ,
377
- '--watch' , srcDir
378
- ] ) ;
392
+ bin . stdout . setEncoding ( 'utf8' ) ;
393
+ bin . stdout . once ( 'data ', function ( ) {
394
+ assert . fail ( 'should not emit console output when watching a directory' ) ;
395
+ } ) ;
396
+ bin . on ( 'error' , assert . fail ) ;
379
397
380
- setTimeout ( function ( ) {
381
- fs . appendFileSync ( srcFile , 'body{background:white}\n' ) ;
382
- setTimeout ( function ( ) {
398
+ setTimeout ( function ( ) {
399
+ setTimeout ( function ( ) {
383
400
bin . kill ( ) ;
384
- var files = fs . readdirSync ( destDir ) ;
385
- assert . deepEqual ( files , [ 'foo.css' , 'index.css' ] ) ;
386
- rimraf ( destDir , done ) ;
387
- } , 200 ) ;
401
+ fs . readdir ( destDir , function ( err , files ) {
402
+ assert . deepEqual ( files , [ 'foo.css' , 'index.css' ] ) ;
403
+ rimraf ( destDir , done ) ;
404
+ } ) ;
405
+ } , 1000 ) ;
406
+
407
+ spawn ( 'node' , [ '-e' , 'require("touch").sync("' + srcFile + '")' ] ) ;
388
408
} , 500 ) ;
389
409
} ) ;
390
410
} ) ;
@@ -612,7 +632,6 @@ describe('cli', function() {
612
632
done ( ) ;
613
633
} ) ;
614
634
} ) ;
615
-
616
635
} ) ;
617
636
618
637
describe ( 'node-sass --follow --output output-dir input-dir' , function ( ) {
0 commit comments