File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -313,7 +313,7 @@ describe('upload stream', function() {
313313 expect ( files [ 1 ] . chunks . length ) . toBe ( 3 ) ;
314314 flow . upload ( ) ;
315315 expect ( files [ 0 ] . isReading ( ) ) . toBeTruthy ( ) ;
316- await sleep ( 1 ) ;
316+ await waitFor ( ( ) => xhr_server . requests . length ) ;
317317
318318 /*
319319 [^^ ]
@@ -331,7 +331,8 @@ describe('upload stream', function() {
331331 */
332332 expect ( xhr_server . requests [ 0 ] . status ) . toBe ( 200 ) ;
333333 expect ( xhr_server . requests [ 1 ] . status ) . toBe ( 200 ) ;
334- await sleep ( 1 ) ;
334+ await waitFor ( ( ) => xhr_server . requests . length == 4 ) ;
335+
335336 /*
336337 [oo^^__]
337338 [ ]
@@ -344,19 +345,19 @@ describe('upload stream', function() {
344345 // corresponding `xhr`. They will get back to pending.
345346 // Flow should start uploading second file now
346347 files [ 0 ] . pause ( ) ;
347- await sleep ( 1 ) ;
348+ await waitFor ( ( ) => xhr_server . requests . length == 6 ) ;
348349
349350 /*
350351 [oo____]
351352 [^^ ]
352353 */
354+ expect ( xhr_server . requests . length ) . toBe ( 6 ) ;
353355 expect ( xhr_server . requests [ 2 ] . aborted ) . toBeTruthy ( ) ;
354356 expect ( xhr_server . requests [ 3 ] . aborted ) . toBeTruthy ( ) ;
355357 expect ( xhr_server . requests [ 4 ] . aborted ) . toBeUndefined ( ) ;
356358 expect ( files [ 0 ] . isUploading ( ) ) . toBeFalsy ( ) ;
357359
358360 flow . upload ( ) ;
359- await sleep ( 1 ) ;
360361 expect ( files [ 0 ] . isUploading ( ) ) . toBeFalsy ( ) ;
361362 expect ( files [ 1 ] . isUploading ( ) ) . toBeTruthy ( ) ;
362363
Original file line number Diff line number Diff line change @@ -21,6 +21,13 @@ function hex(buff) {
2121 return [ ] . map . call ( new Uint8Array ( buff ) , b => ( '00' + b . toString ( 16 ) ) . slice ( - 2 ) ) . join ( '' ) ;
2222}
2323
24+ async function waitFor ( condition , milliseconds = 10 , step = 1 ) {
25+ while ( ! condition ( ) && milliseconds ) {
26+ await sleep ( step ) ;
27+ milliseconds -- ;
28+ }
29+ }
30+
2431function sleep ( milliseconds ) {
2532 return new Promise ( resolve => setTimeout ( resolve , milliseconds ) ) ;
2633}
You can’t perform that action at this time.
0 commit comments