1
1
2
+ /* eslint-disable require-jsdoc, jsdoc/require-jsdoc */
3
+
2
4
import { expect , test } from '@jest/globals'
3
5
import asyncGeneratorMap from './asyncGeneratorMap.mjs'
4
6
import { range } from 'itertools'
@@ -8,7 +10,6 @@ import Deferred from './Deferred.mjs'
8
10
import asyncSleep from './asyncSleep'
9
11
import asyncIterableToArray from './asyncIterableToArray.mjs'
10
12
11
- // eslint-disable-next-line require-jsdoc
12
13
class TestError extends Error { }
13
14
14
15
test ( 'asyncGeneratorMap base' , async ( ) => {
@@ -634,16 +635,15 @@ test('asyncGeneratorMap reaches concurrency', async () => {
634
635
} )
635
636
636
637
test ( 'common for await interrupts generator on interrupted iteration' , async ( ) => {
638
+ let finallyReached = false
637
639
638
- let finallyReached = false ;
639
-
640
- async function * asyncGenWithFinally ( ) {
640
+ async function * asyncGenWithFinally ( ) {
641
641
try {
642
642
for ( const element of range ( 10 ) ) {
643
- yield element ;
643
+ yield element
644
644
}
645
645
} finally {
646
- finallyReached = true ;
646
+ finallyReached = true
647
647
}
648
648
}
649
649
@@ -653,54 +653,51 @@ test('common for await interrupts generator on interrupted iteration', async ()
653
653
}
654
654
}
655
655
656
- expect ( finallyReached ) . toBe ( true ) ;
656
+ expect ( finallyReached ) . toBe ( true )
657
657
} )
658
658
659
659
test ( 'common for await calls AsyncGenerator.return() not AsyncGenerator.throw()' , async ( ) => {
660
+ let catchedException = null
660
661
661
- let catchedException = null ;
662
-
663
- async function * asyncGenWithFinally ( ) {
662
+ async function * asyncGenWithFinally ( ) {
664
663
try {
665
664
for ( const element of range ( 10 ) ) {
666
- yield element ;
665
+ yield element
667
666
}
668
667
} catch ( e ) {
669
- catchedException = e ;
668
+ catchedException = e
670
669
}
671
670
}
672
671
673
672
try {
674
673
for await ( const n of asyncGenWithFinally ( ) ) {
675
674
if ( n === 2 ) {
676
- throw new TestError ( ) ;
675
+ throw new TestError ( )
677
676
}
678
677
}
679
- } catch ( e ) // ignore
680
- {
678
+ } catch ( e ) {
681
679
expect ( e instanceof TestError ) . toBe ( true )
682
680
}
683
- expect ( catchedException ) . toBe ( null ) ;
681
+ expect ( catchedException ) . toBe ( null )
684
682
} )
685
683
686
684
test ( 'asyncGeneratorMap interrupts generator on interrupted iteration' , async ( ) => {
685
+ let finallyReached = false
687
686
688
- let finallyReached = false ;
689
-
690
- async function * asyncGenWithFinally ( ) {
687
+ async function * asyncGenWithFinally ( ) {
691
688
try {
692
689
for ( const element of range ( 10 ) ) {
693
- yield element ;
690
+ yield element
694
691
}
695
692
} finally {
696
- finallyReached = true ;
693
+ finallyReached = true
697
694
}
698
695
}
699
696
700
- for await ( const n of asyncGeneratorMap ( asyncGenWithFinally ( ) , n => n * 2 ) ) {
697
+ for await ( const n of asyncGeneratorMap ( asyncGenWithFinally ( ) , n => n * 2 ) ) {
701
698
if ( n === 4 ) {
702
699
break
703
700
}
704
701
}
705
- expect ( finallyReached ) . toBe ( true ) ;
702
+ expect ( finallyReached ) . toBe ( true )
706
703
} )
0 commit comments