@@ -86,16 +86,18 @@ describe('UnionIterator', () => {
8686 iterator = new UnionIterator ( sources ) ;
8787 } ) ;
8888
89- it ( 'should have ended' , ( ) => {
90- iterator . ended . should . be . true ;
89+ describe ( 'before reading' , ( ) => {
90+ it ( 'should not have ended' , ( ) => {
91+ iterator . ended . should . be . false ;
92+ } ) ;
9193 } ) ;
9294 } ) ;
9395
9496 describe ( 'when constructed with an array of 0 sources without autoStart' , ( ) => {
9597 let iterator ;
9698 before ( ( ) => {
9799 const sources = [ ] ;
98- iterator = new UnionIterator ( sources , { autoStart : false } ) ;
100+ iterator = new UnionIterator ( sources ) ;
99101 } ) ;
100102
101103 describe ( 'before reading' , ( ) => {
@@ -147,7 +149,7 @@ describe('UnionIterator', () => {
147149 } ) ;
148150
149151 it ( 'should have ended' , ( ) => {
150- iterator . ended . should . be . true ;
152+ iterator . ended . should . be . false ;
151153 } ) ;
152154 } ) ;
153155
@@ -159,15 +161,15 @@ describe('UnionIterator', () => {
159161 } ) ;
160162
161163 it ( 'should have ended' , ( ) => {
162- iterator . ended . should . be . true ;
164+ iterator . ended . should . be . false ;
163165 } ) ;
164166 } ) ;
165167
166168 describe ( 'when constructed with an iterator of 0 sources without autoStart' , ( ) => {
167169 let iterator ;
168170 before ( ( ) => {
169171 const sources = [ ] ;
170- iterator = new UnionIterator ( new ArrayIterator ( sources ) , { autoStart : false } ) ;
172+ iterator = new UnionIterator ( new ArrayIterator ( sources ) ) ;
171173 } ) ;
172174
173175 describe ( 'before reading' , ( ) => {
@@ -237,10 +239,6 @@ describe('UnionIterator', () => {
237239 } ) ;
238240
239241 describe ( 'before reading' , ( ) => {
240- it ( 'should have read the sources' , ( ) => {
241- sourceIterator . read . should . have . been . called ;
242- } ) ;
243-
244242 it ( 'should not have ended' , ( ) => {
245243 iterator . ended . should . be . false ;
246244 } ) ;
@@ -268,12 +266,12 @@ describe('UnionIterator', () => {
268266 const sources = [ Promise . resolve ( range ( 0 , 2 ) ) , range ( 3 , 6 ) ] ;
269267 sourceIterator = new ArrayIterator ( sources ) ;
270268 sinon . spy ( sourceIterator , 'read' ) ;
271- iterator = new UnionIterator ( sourceIterator , { autoStart : true } ) ;
269+ iterator = new UnionIterator ( sourceIterator ) ;
272270 } ) ;
273271
274272 describe ( 'before reading' , ( ) => {
275- it ( 'should have read the sources' , ( ) => {
276- sourceIterator . read . should . have . been . called ;
273+ it ( 'should not have read the sources' , ( ) => {
274+ sourceIterator . read . should . not . have . been . called ;
277275 } ) ;
278276
279277 it ( 'should not have ended' , ( ) => {
@@ -303,7 +301,7 @@ describe('UnionIterator', () => {
303301 const sources = [ range ( 0 , 2 ) , range ( 3 , 6 ) ] ;
304302 sourceIterator = new ArrayIterator ( sources ) ;
305303 sinon . spy ( sourceIterator , 'read' ) ;
306- iterator = new UnionIterator ( sourceIterator , { autoStart : false } ) ;
304+ iterator = new UnionIterator ( sourceIterator ) ;
307305 } ) ;
308306
309307 describe ( 'before reading' , ( ) => {
@@ -342,7 +340,7 @@ describe('UnionIterator', () => {
342340 const sources = [ Promise . resolve ( range ( 0 , 2 ) ) , range ( 3 , 6 ) ] ;
343341 sourceIterator = new ArrayIterator ( sources ) ;
344342 sinon . spy ( sourceIterator , 'read' ) ;
345- iterator = new UnionIterator ( sourceIterator , { autoStart : false } ) ;
343+ iterator = new UnionIterator ( sourceIterator ) ;
346344 } ) ;
347345
348346 describe ( 'before reading' , ( ) => {
@@ -387,6 +385,9 @@ describe('UnionIterator', () => {
387385 } ) ;
388386
389387 it ( 'should emit an error when the first iterator emits an error' , ( ) => {
388+ iterator . read ( ) . should . eql ( 0 ) ;
389+ iterator . read ( ) . should . eql ( 1 ) ;
390+
390391 const error = new Error ( 'error' ) ;
391392 const callback = sinon . spy ( ) ;
392393 iterator . on ( 'error' , callback ) ;
@@ -396,6 +397,11 @@ describe('UnionIterator', () => {
396397 } ) ;
397398
398399 it ( 'should emit an error when the second iterator emits an error' , ( ) => {
400+ iterator . read ( ) . should . eql ( 0 ) ;
401+ iterator . read ( ) . should . eql ( 1 ) ;
402+ iterator . read ( ) . should . eql ( 2 ) ;
403+ iterator . read ( ) . should . eql ( 3 ) ;
404+
399405 const error = new Error ( 'error' ) ;
400406 const callback = sinon . spy ( ) ;
401407 iterator . on ( 'error' , callback ) ;
@@ -408,23 +414,9 @@ describe('UnionIterator', () => {
408414 ( await toArray ( iterator ) ) . should . be . instanceof ( Array ) ;
409415 } ) ;
410416
411- it ( 'should allow the _read method to be called multiple times' , ( ) => {
412- iterator . _read ( 1 , noop ) ;
413- iterator . _read ( 1 , noop ) ;
414- } ) ;
415-
416417 it ( 'should make a round-robin union of the data elements' , async ( ) => {
417418 ( await toArray ( iterator ) ) . sort ( ) . should . eql ( [ 0 , 1 , 2 , 3 , 4 , 5 , 6 ] ) ;
418419 } ) ;
419-
420- it ( 'should destroy the sources when closing' , async ( ) => {
421- iterator . close ( ) ;
422-
423- await new Promise ( resolve => iterator . on ( 'end' , resolve ) ) ;
424-
425- sources [ 0 ] . closed . should . be . true ;
426- sources [ 1 ] . closed . should . be . true ;
427- } ) ;
428420 } ) ;
429421
430422 describe ( 'a UnionIterator with two sources without destroySources' , ( ) => {
@@ -555,9 +547,18 @@ describe('UnionIterator', () => {
555547 await new Promise ( resolve => iterator . on ( 'end' , resolve ) ) ;
556548
557549 sourcesIterator . closed . should . be . true ;
550+ } ) ;
551+
552+ it ( 'should close iterators that have started to be read' , async ( ) => {
553+ iterator . read ( ) ;
554+ iterator . close ( ) ;
555+
556+ await new Promise ( resolve => iterator . on ( 'end' , resolve ) ) ;
557+
558+ sourcesIterator . closed . should . be . true ;
558559
559560 sources [ 0 ] . closed . should . be . true ;
560- sources [ 1 ] . closed . should . be . true ;
561+ sources [ 1 ] . closed . should . be . false ;
561562 } ) ;
562563 } ) ;
563564
@@ -586,9 +587,6 @@ describe('UnionIterator', () => {
586587 await new Promise ( resolve => iterator . on ( 'end' , resolve ) ) ;
587588
588589 sourcesIterator . closed . should . be . true ;
589-
590- sources [ 0 ] . closed . should . be . true ;
591- sources [ 1 ] . closed . should . be . true ;
592590 } ) ;
593591 } ) ;
594592
0 commit comments