1- 'use strict' ;
1+ import * as common from '../common/index.mjs' ;
2+ import { setTimeout } from 'timers/promises' ;
3+ import { Readable } from 'stream' ;
4+ import assert from 'assert' ;
25
3- const common = require ( '../common' ) ;
4- const { setTimeout } = require ( 'timers/promises' ) ;
5- const {
6- Readable,
7- } = require ( 'stream' ) ;
8- const assert = require ( 'assert' ) ;
96
107function oneTo5 ( ) {
118 return Readable . from ( [ 1 , 2 , 3 , 4 , 5 ] ) ;
@@ -19,53 +16,45 @@ function oneTo5Async() {
1916}
2017{
2118 // Some, find, and every work with a synchronous stream and predicate
22- ( async ( ) => {
23- assert . strictEqual ( await oneTo5 ( ) . some ( ( x ) => x > 3 ) , true ) ;
24- assert . strictEqual ( await oneTo5 ( ) . every ( ( x ) => x > 3 ) , false ) ;
25- assert . strictEqual ( await oneTo5 ( ) . find ( ( x ) => x > 3 ) , 4 ) ;
26- assert . strictEqual ( await oneTo5 ( ) . some ( ( x ) => x > 6 ) , false ) ;
27- assert . strictEqual ( await oneTo5 ( ) . every ( ( x ) => x < 6 ) , true ) ;
28- assert . strictEqual ( await oneTo5 ( ) . find ( ( x ) => x > 6 ) , undefined ) ;
29- assert . strictEqual ( await Readable . from ( [ ] ) . some ( ( ) => true ) , false ) ;
30- assert . strictEqual ( await Readable . from ( [ ] ) . every ( ( ) => true ) , true ) ;
31- assert . strictEqual ( await Readable . from ( [ ] ) . find ( ( ) => true ) , undefined ) ;
32- } ) ( ) . then ( common . mustCall ( ) ) ;
19+ assert . strictEqual ( await oneTo5 ( ) . some ( ( x ) => x > 3 ) , true ) ;
20+ assert . strictEqual ( await oneTo5 ( ) . every ( ( x ) => x > 3 ) , false ) ;
21+ assert . strictEqual ( await oneTo5 ( ) . find ( ( x ) => x > 3 ) , 4 ) ;
22+ assert . strictEqual ( await oneTo5 ( ) . some ( ( x ) => x > 6 ) , false ) ;
23+ assert . strictEqual ( await oneTo5 ( ) . every ( ( x ) => x < 6 ) , true ) ;
24+ assert . strictEqual ( await oneTo5 ( ) . find ( ( x ) => x > 6 ) , undefined ) ;
25+ assert . strictEqual ( await Readable . from ( [ ] ) . some ( ( ) => true ) , false ) ;
26+ assert . strictEqual ( await Readable . from ( [ ] ) . every ( ( ) => true ) , true ) ;
27+ assert . strictEqual ( await Readable . from ( [ ] ) . find ( ( ) => true ) , undefined ) ;
3328}
3429
3530{
3631 // Some, find, and every work with an asynchronous stream and synchronous predicate
37- ( async ( ) => {
38- assert . strictEqual ( await oneTo5Async ( ) . some ( ( x ) => x > 3 ) , true ) ;
39- assert . strictEqual ( await oneTo5Async ( ) . every ( ( x ) => x > 3 ) , false ) ;
40- assert . strictEqual ( await oneTo5Async ( ) . find ( ( x ) => x > 3 ) , 4 ) ;
41- assert . strictEqual ( await oneTo5Async ( ) . some ( ( x ) => x > 6 ) , false ) ;
42- assert . strictEqual ( await oneTo5Async ( ) . every ( ( x ) => x < 6 ) , true ) ;
43- assert . strictEqual ( await oneTo5Async ( ) . find ( ( x ) => x > 6 ) , undefined ) ;
44- } ) ( ) . then ( common . mustCall ( ) ) ;
32+ assert . strictEqual ( await oneTo5Async ( ) . some ( ( x ) => x > 3 ) , true ) ;
33+ assert . strictEqual ( await oneTo5Async ( ) . every ( ( x ) => x > 3 ) , false ) ;
34+ assert . strictEqual ( await oneTo5Async ( ) . find ( ( x ) => x > 3 ) , 4 ) ;
35+ assert . strictEqual ( await oneTo5Async ( ) . some ( ( x ) => x > 6 ) , false ) ;
36+ assert . strictEqual ( await oneTo5Async ( ) . every ( ( x ) => x < 6 ) , true ) ;
37+ assert . strictEqual ( await oneTo5Async ( ) . find ( ( x ) => x > 6 ) , undefined ) ;
4538}
4639
4740{
4841 // Some, find, and every work on synchronous streams with an asynchronous predicate
49- ( async ( ) => {
50- assert . strictEqual ( await oneTo5 ( ) . some ( async ( x ) => x > 3 ) , true ) ;
51- assert . strictEqual ( await oneTo5 ( ) . every ( async ( x ) => x > 3 ) , false ) ;
52- assert . strictEqual ( await oneTo5 ( ) . find ( async ( x ) => x > 3 ) , 4 ) ;
53- assert . strictEqual ( await oneTo5 ( ) . some ( async ( x ) => x > 6 ) , false ) ;
54- assert . strictEqual ( await oneTo5 ( ) . every ( async ( x ) => x < 6 ) , true ) ;
55- assert . strictEqual ( await oneTo5 ( ) . find ( async ( x ) => x > 6 ) , undefined ) ;
56- } ) ( ) . then ( common . mustCall ( ) ) ;
42+ assert . strictEqual ( await oneTo5 ( ) . some ( async ( x ) => x > 3 ) , true ) ;
43+ assert . strictEqual ( await oneTo5 ( ) . every ( async ( x ) => x > 3 ) , false ) ;
44+ assert . strictEqual ( await oneTo5 ( ) . find ( async ( x ) => x > 3 ) , 4 ) ;
45+ assert . strictEqual ( await oneTo5 ( ) . some ( async ( x ) => x > 6 ) , false ) ;
46+ assert . strictEqual ( await oneTo5 ( ) . every ( async ( x ) => x < 6 ) , true ) ;
47+ assert . strictEqual ( await oneTo5 ( ) . find ( async ( x ) => x > 6 ) , undefined ) ;
5748}
5849
5950{
6051 // Some, find, and every work on asynchronous streams with an asynchronous predicate
61- ( async ( ) => {
62- assert . strictEqual ( await oneTo5Async ( ) . some ( async ( x ) => x > 3 ) , true ) ;
63- assert . strictEqual ( await oneTo5Async ( ) . every ( async ( x ) => x > 3 ) , false ) ;
64- assert . strictEqual ( await oneTo5Async ( ) . find ( async ( x ) => x > 3 ) , 4 ) ;
65- assert . strictEqual ( await oneTo5Async ( ) . some ( async ( x ) => x > 6 ) , false ) ;
66- assert . strictEqual ( await oneTo5Async ( ) . every ( async ( x ) => x < 6 ) , true ) ;
67- assert . strictEqual ( await oneTo5Async ( ) . find ( async ( x ) => x > 6 ) , undefined ) ;
68- } ) ( ) . then ( common . mustCall ( ) ) ;
52+ assert . strictEqual ( await oneTo5Async ( ) . some ( async ( x ) => x > 3 ) , true ) ;
53+ assert . strictEqual ( await oneTo5Async ( ) . every ( async ( x ) => x > 3 ) , false ) ;
54+ assert . strictEqual ( await oneTo5Async ( ) . find ( async ( x ) => x > 3 ) , 4 ) ;
55+ assert . strictEqual ( await oneTo5Async ( ) . some ( async ( x ) => x > 6 ) , false ) ;
56+ assert . strictEqual ( await oneTo5Async ( ) . every ( async ( x ) => x < 6 ) , true ) ;
57+ assert . strictEqual ( await oneTo5Async ( ) . find ( async ( x ) => x > 6 ) , undefined ) ;
6958}
7059
7160{
@@ -74,8 +63,9 @@ function oneTo5Async() {
7463 await setTimeout ( ) ;
7564 assert . strictEqual ( stream . destroyed , true ) ;
7665 }
77- // Some, find, and every short circuit
78- ( async ( ) => {
66+
67+ {
68+ // Some, find, and every short circuit
7969 const someStream = oneTo5 ( ) ;
8070 await someStream . some ( common . mustCall ( ( x ) => x > 2 , 3 ) ) ;
8171 await checkDestroyed ( someStream ) ;
@@ -92,10 +82,10 @@ function oneTo5Async() {
9282 await oneTo5 ( ) . some ( common . mustCall ( ( ) => false , 5 ) ) ;
9383 await oneTo5 ( ) . every ( common . mustCall ( ( ) => true , 5 ) ) ;
9484 await oneTo5 ( ) . find ( common . mustCall ( ( ) => false , 5 ) ) ;
95- } ) ( ) . then ( common . mustCall ( ) ) ;
85+ }
9686
97- // Some, find, and every short circuit async stream/predicate
98- ( async ( ) => {
87+ {
88+ // Some, find, and every short circuit async stream/predicate
9989 const someStream = oneTo5Async ( ) ;
10090 await someStream . some ( common . mustCall ( async ( x ) => x > 2 , 3 ) ) ;
10191 await checkDestroyed ( someStream ) ;
@@ -112,21 +102,19 @@ function oneTo5Async() {
112102 await oneTo5Async ( ) . some ( common . mustCall ( async ( ) => false , 5 ) ) ;
113103 await oneTo5Async ( ) . every ( common . mustCall ( async ( ) => true , 5 ) ) ;
114104 await oneTo5Async ( ) . find ( common . mustCall ( async ( ) => false , 5 ) ) ;
115- } ) ( ) . then ( common . mustCall ( ) ) ;
105+ }
116106}
117107
118108{
119109 // Concurrency doesn't affect which value is found.
120- ( async ( ) => {
121- const found = await Readable . from ( [ 1 , 2 ] ) . find ( async ( val ) => {
122- if ( val === 1 ) {
123- // eslint-disable-next-line no-restricted-syntax
124- await setTimeout ( 100 ) ;
125- }
126- return true ;
127- } , { concurrency : 2 } ) ;
128- assert . strictEqual ( found , 1 ) ;
129- } ) ( ) . then ( common . mustCall ( ) ) ;
110+ const found = await Readable . from ( [ 1 , 2 ] ) . find ( async ( val ) => {
111+ if ( val === 1 ) {
112+ // eslint-disable-next-line no-restricted-syntax
113+ await setTimeout ( 100 ) ;
114+ }
115+ return true ;
116+ } , { concurrency : 2 } ) ;
117+ assert . strictEqual ( found , 1 ) ;
130118}
131119
132120{
@@ -174,3 +162,13 @@ function oneTo5Async() {
174162 } , / E R R _ I N V A L I D _ A R G _ T Y P E / , `${ op } should throw for invalid signal` ) . then ( common . mustCall ( ) ) ;
175163 }
176164}
165+ {
166+ for ( const op of [ 'some' , 'every' , 'find' ] ) {
167+ const stream = oneTo5 ( ) ;
168+ Object . defineProperty ( stream , 'map' , {
169+ value : common . mustNotCall ( ( ) => { } ) ,
170+ } ) ;
171+ // Check that map isn't getting called.
172+ stream [ op ] ( ( ) => { } ) ;
173+ }
174+ }
0 commit comments