@@ -438,6 +438,90 @@ describe('File', function() {
438
438
done ( ) ;
439
439
} ) ;
440
440
441
+ it ( 'should not start flowing until all clones flows' , function ( done ) {
442
+ var contents = new Stream . PassThrough ( ) ;
443
+ var options = {
444
+ cwd : '/' ,
445
+ base : '/test/' ,
446
+ path : '/test/test.coffee' ,
447
+ contents : contents ,
448
+ } ;
449
+ var file = new File ( options ) ;
450
+ var file2 = file . clone ( ) ;
451
+ var ends = 2 ;
452
+
453
+ function latch ( ) {
454
+ if ( -- ends === 0 ) {
455
+ done ( ) ;
456
+ }
457
+ }
458
+
459
+ contents . write ( new Buffer ( 'wa' ) ) ;
460
+
461
+ process . nextTick ( function ( ) {
462
+ contents . write ( new Buffer ( 'dup' ) ) ;
463
+ contents . end ( ) ;
464
+ } ) ;
465
+
466
+ // Start flowing file2
467
+ file2 . contents . on ( 'data' , function ( ) { } ) ;
468
+
469
+ file2 . contents . once ( 'data' , function ( ) {
470
+ process . nextTick ( function ( ) {
471
+ // Starts flowing file
472
+ file . contents . on ( 'data' , function ( ) {
473
+ ends . should . equal ( 2 ) ;
474
+ } ) ;
475
+ } ) ;
476
+ } ) ;
477
+
478
+ file2 . contents . on ( 'end' , latch ) ;
479
+ file . contents . on ( 'end' , latch ) ;
480
+ } ) ;
481
+
482
+ it ( 'should not start flowing until all clones flows' , function ( done ) {
483
+ var contents = new Stream . PassThrough ( ) ;
484
+ var options = {
485
+ cwd : '/' ,
486
+ base : '/test/' ,
487
+ path : '/test/test.coffee' ,
488
+ contents : contents ,
489
+ } ;
490
+ var file = new File ( options ) ;
491
+ var file2 = file . clone ( ) ;
492
+ var ends = 2 ;
493
+
494
+ function latch ( ) {
495
+ if ( -- ends === 0 ) {
496
+ done ( ) ;
497
+ }
498
+ }
499
+
500
+ contents . write ( new Buffer ( 'wa' ) ) ;
501
+
502
+ process . nextTick ( function ( ) {
503
+ contents . write ( new Buffer ( 'dup' ) ) ;
504
+ contents . end ( ) ;
505
+ } ) ;
506
+
507
+ // Start flowing file2
508
+ file2 . contents . on ( 'readable' , function ( ) {
509
+ this . read ( ) ;
510
+ } ) ;
511
+
512
+ file2 . contents . once ( 'readable' , function ( ) {
513
+ process . nextTick ( function ( ) {
514
+ // Starts flowing file
515
+ file . contents . on ( 'readable' , function ( ) {
516
+ ends . should . equal ( 2 ) ;
517
+ } ) ;
518
+ } ) ;
519
+ } ) ;
520
+
521
+ file2 . contents . on ( 'end' , latch ) ;
522
+ file . contents . on ( 'end' , latch ) ;
523
+ } ) ;
524
+
441
525
it ( 'should copy all attributes over with null' , function ( done ) {
442
526
var options = {
443
527
cwd : '/' ,
@@ -636,7 +720,7 @@ describe('File', function() {
636
720
path : '/test/test.coffee' ,
637
721
contents : new Stream . PassThrough ( ) ,
638
722
} ) ;
639
- file . inspect ( ) . should . equal ( '<File "test.coffee" <PassThroughStream >>' ) ;
723
+ file . inspect ( ) . should . equal ( '<File "test.coffee" <CloneableStream >>' ) ;
640
724
done ( ) ;
641
725
} ) ;
642
726
@@ -661,11 +745,11 @@ describe('File', function() {
661
745
done ( ) ;
662
746
} ) ;
663
747
664
- it ( 'should work with Stream' , function ( done ) {
665
- var val = new Stream . PassThrough ( ) ;
748
+ it ( 'should wrap Stream in Cloneable ' , function ( done ) {
749
+ var val = new Stream ( ) ;
666
750
var file = new File ( ) ;
667
751
file . contents = val ;
668
- file . contents . should . equal ( val ) ;
752
+ ( typeof file . contents . clone ) . should . equal ( 'function' ) ;
669
753
done ( ) ;
670
754
} ) ;
671
755
0 commit comments