1- import { PromiseBuffer } from '../src/promisebuffer' ;
1+ import { makePromiseBuffer } from '../src/promisebuffer' ;
22import { SyncPromise } from '../src/syncpromise' ;
33
44describe ( 'PromiseBuffer' , ( ) => {
55 describe ( 'add()' , ( ) => {
66 test ( 'no limit' , ( ) => {
7- const buffer = new PromiseBuffer ( ) ;
7+ const buffer = makePromiseBuffer ( ) ;
88 const p = jest . fn ( ( ) => new SyncPromise ( resolve => setTimeout ( resolve ) ) ) ;
99 void buffer . add ( p ) ;
1010 expect ( buffer . length ( ) ) . toEqual ( 1 ) ;
1111 } ) ;
1212
1313 test ( 'with limit' , ( ) => {
14- const buffer = new PromiseBuffer ( 1 ) ;
14+ const buffer = makePromiseBuffer ( 1 ) ;
1515 let task1 ;
1616 const producer1 = jest . fn ( ( ) => {
1717 task1 = new SyncPromise ( resolve => setTimeout ( resolve ) ) ;
@@ -28,7 +28,7 @@ describe('PromiseBuffer', () => {
2828
2929 describe ( 'drain()' , ( ) => {
3030 test ( 'without timeout' , async ( ) => {
31- const buffer = new PromiseBuffer ( ) ;
31+ const buffer = makePromiseBuffer ( ) ;
3232 for ( let i = 0 ; i < 5 ; i ++ ) {
3333 void buffer . add ( ( ) => new SyncPromise ( resolve => setTimeout ( resolve ) ) ) ;
3434 }
@@ -39,7 +39,7 @@ describe('PromiseBuffer', () => {
3939 } ) ;
4040
4141 test ( 'with timeout' , async ( ) => {
42- const buffer = new PromiseBuffer ( ) ;
42+ const buffer = makePromiseBuffer ( ) ;
4343 for ( let i = 0 ; i < 5 ; i ++ ) {
4444 void buffer . add ( ( ) => new SyncPromise ( resolve => setTimeout ( resolve , 100 ) ) ) ;
4545 }
@@ -49,7 +49,7 @@ describe('PromiseBuffer', () => {
4949 } ) ;
5050
5151 test ( 'on empty buffer' , async ( ) => {
52- const buffer = new PromiseBuffer ( ) ;
52+ const buffer = makePromiseBuffer ( ) ;
5353 expect ( buffer . length ( ) ) . toEqual ( 0 ) ;
5454 const result = await buffer . drain ( ) ;
5555 expect ( result ) . toEqual ( true ) ;
@@ -58,7 +58,7 @@ describe('PromiseBuffer', () => {
5858 } ) ;
5959
6060 test ( 'resolved promises should not show up in buffer length' , async ( ) => {
61- const buffer = new PromiseBuffer ( ) ;
61+ const buffer = makePromiseBuffer ( ) ;
6262 const producer = ( ) => new SyncPromise ( resolve => setTimeout ( resolve ) ) ;
6363 const task = buffer . add ( producer ) ;
6464 expect ( buffer . length ( ) ) . toEqual ( 1 ) ;
@@ -67,7 +67,7 @@ describe('PromiseBuffer', () => {
6767 } ) ;
6868
6969 test ( 'rejected promises should not show up in buffer length' , async ( ) => {
70- const buffer = new PromiseBuffer ( ) ;
70+ const buffer = makePromiseBuffer ( ) ;
7171 const producer = ( ) => new SyncPromise ( ( _ , reject ) => setTimeout ( reject ) ) ;
7272 const task = buffer . add ( producer ) ;
7373 expect ( buffer . length ( ) ) . toEqual ( 1 ) ;
@@ -80,7 +80,7 @@ describe('PromiseBuffer', () => {
8080 } ) ;
8181
8282 test ( 'resolved task should give an access to the return value' , async ( ) => {
83- const buffer = new PromiseBuffer < string > ( ) ;
83+ const buffer = makePromiseBuffer < string > ( ) ;
8484 const producer = ( ) => new SyncPromise < string > ( resolve => setTimeout ( ( ) => resolve ( 'test' ) ) ) ;
8585 const task = buffer . add ( producer ) ;
8686 const result = await task ;
@@ -89,7 +89,7 @@ describe('PromiseBuffer', () => {
8989
9090 test ( 'rejected task should give an access to the return value' , async ( ) => {
9191 expect . assertions ( 1 ) ;
92- const buffer = new PromiseBuffer < string > ( ) ;
92+ const buffer = makePromiseBuffer < string > ( ) ;
9393 const producer = ( ) => new SyncPromise < string > ( ( _ , reject ) => setTimeout ( ( ) => reject ( new Error ( 'whoops' ) ) ) ) ;
9494 const task = buffer . add ( producer ) ;
9595 try {
0 commit comments