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' ;
2
5
3
- const common = require ( '../common' ) ;
4
- const { setTimeout } = require ( 'timers/promises' ) ;
5
- const {
6
- Readable,
7
- } = require ( 'stream' ) ;
8
- const assert = require ( 'assert' ) ;
9
6
10
7
function oneTo5 ( ) {
11
8
return Readable . from ( [ 1 , 2 , 3 , 4 , 5 ] ) ;
@@ -19,53 +16,45 @@ function oneTo5Async() {
19
16
}
20
17
{
21
18
// 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 ) ;
33
28
}
34
29
35
30
{
36
31
// 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 ) ;
45
38
}
46
39
47
40
{
48
41
// 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 ) ;
57
48
}
58
49
59
50
{
60
51
// 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 ) ;
69
58
}
70
59
71
60
{
@@ -74,8 +63,9 @@ function oneTo5Async() {
74
63
await setTimeout ( ) ;
75
64
assert . strictEqual ( stream . destroyed , true ) ;
76
65
}
77
- // Some, find, and every short circuit
78
- ( async ( ) => {
66
+
67
+ {
68
+ // Some, find, and every short circuit
79
69
const someStream = oneTo5 ( ) ;
80
70
await someStream . some ( common . mustCall ( ( x ) => x > 2 , 3 ) ) ;
81
71
await checkDestroyed ( someStream ) ;
@@ -92,10 +82,10 @@ function oneTo5Async() {
92
82
await oneTo5 ( ) . some ( common . mustCall ( ( ) => false , 5 ) ) ;
93
83
await oneTo5 ( ) . every ( common . mustCall ( ( ) => true , 5 ) ) ;
94
84
await oneTo5 ( ) . find ( common . mustCall ( ( ) => false , 5 ) ) ;
95
- } ) ( ) . then ( common . mustCall ( ) ) ;
85
+ }
96
86
97
- // Some, find, and every short circuit async stream/predicate
98
- ( async ( ) => {
87
+ {
88
+ // Some, find, and every short circuit async stream/predicate
99
89
const someStream = oneTo5Async ( ) ;
100
90
await someStream . some ( common . mustCall ( async ( x ) => x > 2 , 3 ) ) ;
101
91
await checkDestroyed ( someStream ) ;
@@ -112,21 +102,19 @@ function oneTo5Async() {
112
102
await oneTo5Async ( ) . some ( common . mustCall ( async ( ) => false , 5 ) ) ;
113
103
await oneTo5Async ( ) . every ( common . mustCall ( async ( ) => true , 5 ) ) ;
114
104
await oneTo5Async ( ) . find ( common . mustCall ( async ( ) => false , 5 ) ) ;
115
- } ) ( ) . then ( common . mustCall ( ) ) ;
105
+ }
116
106
}
117
107
118
108
{
119
109
// 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 ) ;
130
118
}
131
119
132
120
{
0 commit comments