1- import { existsSync } from 'node:fs'
2- import { readFile , writeFile } from 'node:fs/promises'
1+ import { existsSync , readFileSync } from 'node:fs'
2+ import { writeFile } from 'node:fs/promises'
33import { join , relative } from 'node:path'
44
55import {
@@ -387,7 +387,7 @@ describe('devupUILoader', () => {
387387 path === 'themeFile'
388388 )
389389 } )
390- vi . mocked ( readFile ) . mockResolvedValue ( '{}' )
390+ vi . mocked ( readFileSync ) . mockReturnValue ( '{}' )
391391 vi . mocked ( codeExtract ) . mockReturnValue ( {
392392 code : 'code' ,
393393 css : 'css' ,
@@ -403,16 +403,14 @@ describe('devupUILoader', () => {
403403 expect ( existsSync ) . toHaveBeenCalledWith ( 'classMapFile' )
404404 expect ( existsSync ) . toHaveBeenCalledWith ( 'fileMapFile' )
405405 expect ( existsSync ) . toHaveBeenCalledWith ( 'themeFile' )
406- await vi . waitFor ( ( ) => {
407- expect ( readFile ) . toHaveBeenCalledWith ( 'sheetFile' , 'utf-8' )
408- expect ( readFile ) . toHaveBeenCalledWith ( 'classMapFile' , 'utf-8' )
409- expect ( readFile ) . toHaveBeenCalledWith ( 'fileMapFile' , 'utf-8' )
410- expect ( readFile ) . toHaveBeenCalledWith ( 'themeFile' , 'utf-8' )
411- expect ( importSheet ) . toHaveBeenCalledWith ( { } )
412- expect ( importClassMap ) . toHaveBeenCalledWith ( { } )
413- expect ( importFileMap ) . toHaveBeenCalledWith ( { } )
414- expect ( registerTheme ) . toHaveBeenCalledWith ( { } )
415- } )
406+ expect ( readFileSync ) . toHaveBeenCalledWith ( 'sheetFile' , 'utf-8' )
407+ expect ( readFileSync ) . toHaveBeenCalledWith ( 'classMapFile' , 'utf-8' )
408+ expect ( readFileSync ) . toHaveBeenCalledWith ( 'fileMapFile' , 'utf-8' )
409+ expect ( readFileSync ) . toHaveBeenCalledWith ( 'themeFile' , 'utf-8' )
410+ expect ( importSheet ) . toHaveBeenCalledWith ( { } )
411+ expect ( importClassMap ) . toHaveBeenCalledWith ( { } )
412+ expect ( importFileMap ) . toHaveBeenCalledWith ( { } )
413+ expect ( registerTheme ) . toHaveBeenCalledWith ( { } )
416414 } )
417415
418416 it ( 'should not read files when they do not exist in watch mode' , async ( ) => {
@@ -448,7 +446,7 @@ describe('devupUILoader', () => {
448446 expect ( existsSync ) . toHaveBeenCalledWith ( 'classMapFile' )
449447 expect ( existsSync ) . toHaveBeenCalledWith ( 'fileMapFile' )
450448 expect ( existsSync ) . toHaveBeenCalledWith ( 'themeFile' )
451- expect ( readFile ) . not . toHaveBeenCalled ( )
449+ expect ( readFileSync ) . not . toHaveBeenCalled ( )
452450 } )
453451
454452 it ( 'should not write base style when watch is false even if updatedBaseStyle is true' , async ( ) => {
@@ -507,7 +505,7 @@ describe('devupUILoader', () => {
507505 addDependency : vi . fn ( ) ,
508506 }
509507 vi . mocked ( existsSync ) . mockReturnValue ( true )
510- vi . mocked ( readFile ) . mockResolvedValue ( '{}' )
508+ vi . mocked ( readFileSync ) . mockReturnValue ( '{}' )
511509 vi . mocked ( codeExtract ) . mockImplementation ( ( ) => {
512510 throw new Error ( 'error' )
513511 } )
@@ -545,7 +543,7 @@ describe('devupUILoader', () => {
545543 } ,
546544 }
547545 vi . mocked ( existsSync ) . mockImplementation ( ( path ) => path === 'themeFile' )
548- vi . mocked ( readFile ) . mockResolvedValue ( JSON . stringify ( themeData ) )
546+ vi . mocked ( readFileSync ) . mockReturnValue ( JSON . stringify ( themeData ) )
549547 vi . mocked ( codeExtract ) . mockReturnValue ( {
550548 code : 'code' ,
551549 css : 'css' ,
@@ -558,14 +556,12 @@ describe('devupUILoader', () => {
558556 devupUILoader . bind ( t as any ) ( Buffer . from ( 'code' ) , 'index.tsx' )
559557
560558 expect ( existsSync ) . toHaveBeenCalledWith ( 'themeFile' )
561- await vi . waitFor ( ( ) => {
562- expect ( readFile ) . toHaveBeenCalledWith ( 'themeFile' , 'utf-8' )
563- expect ( registerTheme ) . toHaveBeenCalledWith ( {
564- colors : {
565- primary : '#000' ,
566- secondary : '#fff' ,
567- } ,
568- } )
559+ expect ( readFileSync ) . toHaveBeenCalledWith ( 'themeFile' , 'utf-8' )
560+ expect ( registerTheme ) . toHaveBeenCalledWith ( {
561+ colors : {
562+ primary : '#000' ,
563+ secondary : '#fff' ,
564+ } ,
569565 } )
570566 } )
571567
@@ -590,7 +586,9 @@ describe('devupUILoader', () => {
590586 otherProperty : 'value' ,
591587 }
592588 vi . mocked ( existsSync ) . mockImplementation ( ( path ) => path === 'themeFile' )
593- vi . mocked ( readFile ) . mockResolvedValue ( JSON . stringify ( themeDataWithoutTheme ) )
589+ vi . mocked ( readFileSync ) . mockReturnValue (
590+ JSON . stringify ( themeDataWithoutTheme ) ,
591+ )
594592 vi . mocked ( codeExtract ) . mockReturnValue ( {
595593 code : 'code' ,
596594 css : 'css' ,
@@ -603,10 +601,8 @@ describe('devupUILoader', () => {
603601 devupUILoader . bind ( t as any ) ( Buffer . from ( 'code' ) , 'index.tsx' )
604602
605603 expect ( existsSync ) . toHaveBeenCalledWith ( 'themeFile' )
606- await vi . waitFor ( ( ) => {
607- expect ( readFile ) . toHaveBeenCalledWith ( 'themeFile' , 'utf-8' )
608- expect ( registerTheme ) . toHaveBeenCalledWith ( { } )
609- } )
604+ expect ( readFileSync ) . toHaveBeenCalledWith ( 'themeFile' , 'utf-8' )
605+ expect ( registerTheme ) . toHaveBeenCalledWith ( { } )
610606 } )
611607
612608 it ( 'should read themeFile and use empty object when theme property is null' , async ( ) => {
@@ -630,7 +626,7 @@ describe('devupUILoader', () => {
630626 theme : null ,
631627 }
632628 vi . mocked ( existsSync ) . mockImplementation ( ( path ) => path === 'themeFile' )
633- vi . mocked ( readFile ) . mockResolvedValue (
629+ vi . mocked ( readFileSync ) . mockReturnValue (
634630 JSON . stringify ( themeDataWithNullTheme ) ,
635631 )
636632 vi . mocked ( codeExtract ) . mockReturnValue ( {
@@ -645,9 +641,7 @@ describe('devupUILoader', () => {
645641 devupUILoader . bind ( t as any ) ( Buffer . from ( 'code' ) , 'index.tsx' )
646642
647643 expect ( existsSync ) . toHaveBeenCalledWith ( 'themeFile' )
648- await vi . waitFor ( ( ) => {
649- expect ( readFile ) . toHaveBeenCalledWith ( 'themeFile' , 'utf-8' )
650- expect ( registerTheme ) . toHaveBeenCalledWith ( { } )
651- } )
644+ expect ( readFileSync ) . toHaveBeenCalledWith ( 'themeFile' , 'utf-8' )
645+ expect ( registerTheme ) . toHaveBeenCalledWith ( { } )
652646 } )
653647} )
0 commit comments