@@ -304,27 +304,27 @@ describe('cli', function() {
304
304
305
305
it ( 'should watch the full scss dep tree for a single file (scss)' , function ( done ) {
306
306
var src = fixture ( 'watching/index.scss' ) ;
307
- var foo = fixture ( 'watching/white.scss' ) ;
307
+ var child = fixture ( 'watching/white.scss' ) ;
308
308
309
309
var bin = spawn ( cli , [
310
310
'--output-style' , 'compressed' ,
311
311
'--watch' , src
312
312
] ) ;
313
313
314
314
bin . stdout . setEncoding ( 'utf8' ) ;
315
- bin . stdout . on ( 'data' , function ( data ) {
316
- assert . strictEqual ( data . trim ( ) , 'body{background:white}' ) ;
317
- bin . kill ( ) ;
315
+ bin . stdout . once ( 'data' , function ( ) {
316
+ touch ( child , function ( ) {
317
+ bin . stdout . once ( 'data' , function ( data ) {
318
+ assert . strictEqual ( data . trim ( ) , 'body{background:white}' ) ;
319
+ bin . kill ( ) ;
320
+ } ) ;
321
+ } ) ;
318
322
} ) ;
319
323
bin . on ( 'error' , function ( err ) {
320
324
assert . fail ( err ) ;
321
325
done ( ) ;
322
326
} ) ;
323
327
bin . on ( 'exit' , done ) ;
324
-
325
- setTimeout ( function ( ) {
326
- touch . sync ( foo ) ;
327
- } , 500 ) ;
328
328
} ) . timeout ( 5000 ) ;
329
329
330
330
it ( 'should watch the full sass dep tree for a single file (sass)' , function ( done ) {
@@ -337,9 +337,13 @@ describe('cli', function() {
337
337
] ) ;
338
338
339
339
bin . stdout . setEncoding ( 'utf8' ) ;
340
- bin . stdout . once ( 'data' , function ( data ) {
341
- assert . strictEqual ( data . trim ( ) , 'body{background:white}' ) ;
342
- bin . kill ( ) ;
340
+ bin . stdout . once ( 'data' , function ( ) {
341
+ touch ( child , function ( ) {
342
+ bin . stdout . once ( 'data' , function ( data ) {
343
+ assert . strictEqual ( data . trim ( ) , 'body{background:white}' ) ;
344
+ bin . kill ( ) ;
345
+ } ) ;
346
+ } ) ;
343
347
} ) ;
344
348
bin . on ( 'error' , function ( err ) {
345
349
assert . fail ( err ) ;
@@ -358,6 +362,7 @@ describe('cli', function() {
358
362
var destDir = tmpDir ( { create : true } ) ;
359
363
var srcDir = fixture ( 'watching-dir-01/' ) ;
360
364
var srcFile = path . join ( srcDir , 'index.scss' ) ;
365
+ var w ;
361
366
362
367
var bin = spawn ( cli , [
363
368
'--output-style' , 'compressed' ,
@@ -366,24 +371,25 @@ describe('cli', function() {
366
371
] ) ;
367
372
368
373
bin . stdout . setEncoding ( 'utf8' ) ;
369
- bin . stdout . once ( 'data' , function ( ) {
370
- assert . fail ( 'should not emit console output when watching a directory' ) ;
374
+ bin . stdout . once ( 'data' , function ( data ) {
375
+ assert . equal ( 'Watching ' + srcDir , data . trim ( ) ) ;
376
+ touch ( srcFile , function ( ) {
377
+ bin . stdout . once ( 'data' , function ( ) {
378
+ assert . fail ( 'should not emit console output when watching a directory' ) ;
379
+ } ) ;
380
+ } ) ;
371
381
} ) ;
372
382
bin . on ( 'error' , assert . fail ) ;
383
+ bin . on ( 'exit' , w . close ) ;
373
384
374
-
375
- fs . watch ( destDir , once ( function ( ) {
385
+ w = fs . watch ( destDir , function ( ) {
376
386
bin . kill ( ) ;
377
387
fs . readdir ( destDir , function ( err , files ) {
378
388
assert . deepEqual ( files , [ 'index.css' ] ) ;
379
389
rimraf ( destDir , done ) ;
380
390
} ) ;
381
- } ) ) ;
382
-
383
- setTimeout ( function ( ) {
384
- touch . sync ( srcFile ) ;
385
- } , 500 ) ;
386
- } ) ;
391
+ } ) ;
392
+ } ) . timeout ( 5000 ) ;
387
393
388
394
it ( 'should compile all changed files in watched directory' , function ( done ) {
389
395
var destDir = tmpDir ( { create : true } ) ;
@@ -402,17 +408,16 @@ describe('cli', function() {
402
408
} ) ;
403
409
bin . on ( 'error' , assert . fail ) ;
404
410
405
-
406
- fs . watch ( destDir , once ( function ( ) {
407
- bin . kill ( ) ;
408
- fs . readdir ( destDir , function ( err , files ) {
409
- assert . deepEqual ( files , [ 'foo.css' , 'index.css' ] ) ;
410
- rimraf ( destDir , done ) ;
411
- } ) ;
412
- } ) ) ;
413
-
414
411
setTimeout ( function ( ) {
415
- touch . sync ( srcFile ) ;
412
+ setTimeout ( function ( ) {
413
+ bin . kill ( ) ;
414
+ fs . readdir ( destDir , function ( err , files ) {
415
+ assert . deepEqual ( files , [ 'foo.css' , 'index.css' ] ) ;
416
+ rimraf ( destDir , done ) ;
417
+ } ) ;
418
+ } , 1000 ) ;
419
+
420
+ spawn ( 'node' , [ '-e' , 'require("touch").sync("' + srcFile + '")' ] ) ;
416
421
} , 500 ) ;
417
422
} ) ;
418
423
} ) ;
0 commit comments