File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
packages/core/__tests__/unit/utils Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { callPromiseUntilEnd , callUntilEnd } from "@/main" ;
2
+ import { expect , test } from "vitest" ;
3
+
4
+ test ( "Call until end" , async ( ) => {
5
+ const startT = Date . now ( ) ;
6
+ let i = 0 ;
7
+ await callUntilEnd ( ( ) => {
8
+ expect ( Date . now ( ) - startT ) . toBeGreaterThanOrEqual ( 100 * i ) ;
9
+ return ++ i === 10 ;
10
+ } , 100 ) ;
11
+
12
+ expect ( Date . now ( ) - startT ) . toBeGreaterThanOrEqual ( 1000 ) ;
13
+ expect ( i ) . toBe ( 10 ) ;
14
+ } ) ;
15
+
16
+ test ( "Call promise until end" , async ( ) => {
17
+ const startT = Date . now ( ) ;
18
+ let i = 0 ;
19
+ await callPromiseUntilEnd ( async ( ) => {
20
+ return new Promise ( ( resolve ) =>
21
+ setTimeout ( ( ) => {
22
+ i ++ ;
23
+ expect ( Date . now ( ) - startT ) . toBeGreaterThanOrEqual ( 100 * i * 2 ) ;
24
+ console . log ( Date . now ( ) - startT , i ) ;
25
+
26
+ resolve ( i >= 10 ) ;
27
+ } , 100 )
28
+ ) ;
29
+ } , 100 ) ;
30
+
31
+ expect ( Date . now ( ) - startT ) . toBeGreaterThanOrEqual ( 2000 ) ;
32
+ expect ( i ) . toBe ( 10 ) ;
33
+ } ) ;
You can’t perform that action at this time.
0 commit comments