File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ async function sleep(ms: number): Promise<void> {
1313async function waitFor ( fn : ( ) => void ) {
1414 return new Promise < void > ( ( resolve , reject ) => {
1515 let error : unknown = null ;
16- const intervalTimer = setInterval ( ( ) => {
16+ function runFn ( ) {
1717 try {
1818 fn ( ) ;
1919 clearInterval ( intervalTimer ) ;
@@ -22,6 +22,10 @@ async function waitFor(fn: () => void) {
2222 } catch ( e ) {
2323 error = e ;
2424 }
25+ }
26+ runFn ( ) ; // First, execute immediately
27+ const intervalTimer = setInterval ( ( ) => {
28+ runFn ( ) ;
2529 } , 50 ) ;
2630 const timeoutTimer = setTimeout ( ( ) => {
2731 clearInterval ( intervalTimer ) ;
@@ -68,7 +72,7 @@ describe('runCMKInWatchMode', () => {
6872 console . log ( 'update file' ) ;
6973 await writeFile ( textFilePath , '1' ) ;
7074 const startTime = Date . now ( ) ;
71- await vi . waitFor ( ( ) => {
75+ await waitFor ( ( ) => {
7276 console . log ( 'elapsed' , Date . now ( ) - startTime ) ;
7377 assert ( globalThis . changeCount === 1 , `Expected changeCount to be 1, but got ${ globalThis . changeCount } ` ) ;
7478 } ) ;
You can’t perform that action at this time.
0 commit comments