@@ -157,7 +157,7 @@ test('pMapSkip', async t => {
157
157
] , async value => value ) , [ 1 , 2 ] ) ;
158
158
} ) ;
159
159
160
- test ( 'do not run mapping after stop-on-error happened' , async t => {
160
+ test ( 'all mappers should run when concurrency is infinite, even after stop-on-error happened' , async t => {
161
161
const input = [ 1 , async ( ) => delay ( 300 , { value : 2 } ) , 3 ] ;
162
162
const mappedValues = [ ] ;
163
163
await t . throwsAsync (
@@ -271,7 +271,7 @@ test('asyncIterator - pMapSkip', async t => {
271
271
] ) , async value => value ) , [ 1 , 2 ] ) ;
272
272
} ) ;
273
273
274
- test ( 'asyncIterator - do not run mapping after stop-on-error happened' , async t => {
274
+ test ( 'asyncIterator - all mappers should run when concurrency is infinite, even after stop-on-error happened' , async t => {
275
275
const input = [ 1 , async ( ) => delay ( 300 , { value : 2 } ) , 3 ] ;
276
276
const mappedValues = [ ] ;
277
277
await t . throwsAsync (
@@ -283,13 +283,13 @@ test('asyncIterator - do not run mapping after stop-on-error happened', async t
283
283
mappedValues . push ( value ) ;
284
284
if ( value === 1 ) {
285
285
await delay ( 100 ) ;
286
- throw new Error ( ' Oops!' ) ;
286
+ throw new Error ( ` Oops! ${ value } ` ) ;
287
287
}
288
- } ,
289
- { concurrency : 1 } )
288
+ } ) ,
289
+ { message : 'Oops! 1' }
290
290
) ;
291
291
await delay ( 500 ) ;
292
- t . deepEqual ( mappedValues , [ 1 ] ) ;
292
+ t . deepEqual ( mappedValues , [ 1 , 3 , 2 ] ) ;
293
293
} ) ;
294
294
295
295
test ( 'catches exception from source iterator - 1st item' , async t => {
@@ -349,3 +349,22 @@ test('catches exception from source iterator - 2nd item after 1st item mapper th
349
349
t . is ( input . index , 2 ) ;
350
350
t . deepEqual ( mappedValues , [ 0 ] ) ;
351
351
} ) ;
352
+
353
+ test ( 'asyncIterator - get the correct exception after stop-on-error' , async t => {
354
+ const input = [ 1 , async ( ) => delay ( 200 , { value : 2 } ) , async ( ) => delay ( 300 , { value : 3 } ) ] ;
355
+ const mappedValues = [ ] ;
356
+
357
+ const task = pMap ( new AsyncTestData ( input ) , async value => {
358
+ if ( typeof value === 'function' ) {
359
+ value = await value ( ) ;
360
+ }
361
+
362
+ mappedValues . push ( value ) ;
363
+ // Throw for each item - all should fail and we should get only the first
364
+ await delay ( 100 ) ;
365
+ throw new Error ( `Oops! ${ value } ` ) ;
366
+ } ) ;
367
+ await delay ( 500 ) ;
368
+ await t . throwsAsync ( task , { message : 'Oops! 1' } ) ;
369
+ t . deepEqual ( mappedValues , [ 1 , 2 , 3 ] ) ;
370
+ } ) ;
0 commit comments