@@ -41,23 +41,25 @@ function test1() {
4141
4242 // Run test without limiting concurrency.
4343
44- Promise . map ( list , run ) . then ( ( result : string [ ] ) => {
45- ++ testCount ;
44+ return (
45+ Promise . map ( list , run ) . then ( ( result : string [ ] ) => {
46+ ++ testCount ;
4647
47- equals ( result . join ( '' ) , '123456' ) ;
48- equals ( maxRunning , 6 ) ;
48+ equals ( result . join ( '' ) , '123456' ) ;
49+ equals ( maxRunning , 6 ) ;
4950
50- maxRunning = 0 ;
51+ maxRunning = 0 ;
5152
52- // Run test and limit concurrency.
53+ // Run test and limit concurrency.
5354
54- return ( Promise . map ( list , queue . wrap ( run ) ) )
55- } ) . then ( ( result : string [ ] ) => {
56- ++ testCount ;
55+ return ( Promise . map ( list , queue . wrap ( run ) ) )
56+ } ) . then ( ( result : string [ ] ) => {
57+ ++ testCount ;
5758
58- equals ( result . join ( '' ) , '123456' ) ;
59- equals ( maxRunning , 3 ) ;
60- } )
59+ equals ( result . join ( '' ) , '123456' ) ;
60+ equals ( maxRunning , 3 ) ;
61+ } )
62+ ) ;
6163}
6264
6365function test2 ( ) {
@@ -69,8 +71,12 @@ function test2() {
6971
7072 var queue = new TaskQueue ( Promise , 1 ) ;
7173
72- queue . wrap ( throws ) ( ) . then ( null as any , ( err : any ) => ++ testCount ) ;
73- queue . wrap ( throws ) ( ) . then ( null as any , ( err : any ) => ++ testCount ) ;
74+ return (
75+ Promise . all ( [
76+ queue . wrap ( throws ) ( ) . then ( null as any , ( err : any ) => ++ testCount ) ,
77+ queue . wrap ( throws ) ( ) . then ( null as any , ( err : any ) => ++ testCount )
78+ ] )
79+ ) ;
7480}
7581
7682function test3 ( ) {
@@ -80,8 +86,12 @@ function test3() {
8086
8187 var queue = new TaskQueue ( Promise , 1 ) ;
8288
83- queue . wrap ( rejects ) ( ) . then ( null as any , ( err : any ) => ++ testCount ) ;
84- queue . wrap ( rejects ) ( ) . then ( null as any , ( err : any ) => ++ testCount ) ;
89+ return (
90+ Promise . all ( [
91+ queue . wrap ( rejects ) ( ) . then ( null as any , ( err : any ) => ++ testCount ) ,
92+ queue . wrap ( rejects ) ( ) . then ( null as any , ( err : any ) => ++ testCount )
93+ ] )
94+ ) ;
8595}
8696
8797function test4 ( ) {
@@ -99,25 +109,28 @@ function test4() {
99109 const result : number [ ] = [ ] ;
100110 const start = new Date ( ) . getTime ( ) ;
101111
102- Promise . map (
103- unsorted ,
104- ( item : number ) => queue . add (
105- ( ) => {
106- const delta = new Date ( ) . getTime ( ) - start - item * 10 ;
107- if ( delta > 0 && delta < 20 ) result . push ( item ) ;
108- } ,
109- item * 10
112+ return (
113+ Promise . map (
114+ unsorted ,
115+ ( item : number ) => queue . add (
116+ ( ) => {
117+ const delta = new Date ( ) . getTime ( ) - start - item * 10 ;
118+ if ( delta > 0 && delta < 20 ) result . push ( item ) ;
119+ } ,
120+ item * 10
121+ )
122+ ) . then (
123+ ( ) => result . join ( ' ' ) == correct . join ( ' ' ) && ++ testCount
110124 )
111- ) . then (
112- ( ) => result . join ( ' ' ) == correct . join ( ' ' ) && ++ testCount
113125 ) ;
114126}
115127
116- test1 ( ) ;
117- test2 ( ) ;
118- test3 ( ) ;
119- test4 ( ) ;
120128
121- setTimeout ( ( ) => {
122- equals ( testCount , 7 ) ;
123- } , 1000 ) ;
129+ Promise . all ( [
130+ test1 ( ) ,
131+ test2 ( ) ,
132+ test3 ( ) ,
133+ test4 ( )
134+ ] ) . then (
135+ ( ) => equals ( testCount , 7 )
136+ ) ;
0 commit comments