11import path from 'node:path' ;
22
3- // Mocks
4- const existsSync = jest . fn ( ) ;
5- const mkdirSync = jest . fn ( ) ;
6- const writeFileSync = jest . fn ( ) ;
3+ const existsSyncMock = jest . fn ( ) ;
4+ const mkdirSyncMock = jest . fn ( ) ;
5+ const writeFileSyncMock = jest . fn ( ) ;
6+
77jest . mock ( 'node:fs' , ( ) => ( {
88 __esModule : true ,
99 default : {
10- existsSync : ( ...a : unknown [ ] ) => existsSync ( ...a ) ,
11- mkdirSync : ( ...a : unknown [ ] ) => mkdirSync ( ...a ) ,
12- writeFileSync : ( ...a : unknown [ ] ) => writeFileSync ( ...a ) ,
10+ existsSync : ( ...a : unknown [ ] ) => existsSyncMock ( ...a ) ,
11+ mkdirSync : ( ...a : unknown [ ] ) => mkdirSyncMock ( ...a ) ,
12+ writeFileSync : ( ...a : unknown [ ] ) => writeFileSyncMock ( ...a ) ,
1313 } ,
14- existsSync : ( ...a : unknown [ ] ) => existsSync ( ...a ) ,
15- mkdirSync : ( ...a : unknown [ ] ) => mkdirSync ( ...a ) ,
16- writeFileSync : ( ...a : unknown [ ] ) => writeFileSync ( ...a ) ,
14+ existsSync : ( ...a : unknown [ ] ) => existsSyncMock ( ...a ) ,
15+ mkdirSync : ( ...a : unknown [ ] ) => mkdirSyncMock ( ...a ) ,
16+ writeFileSync : ( ...a : unknown [ ] ) => writeFileSyncMock ( ...a ) ,
1717} ) ) ;
1818
19- const moveToApplicationsFolder = jest . fn ( ) ;
20- const isInApplicationsFolder = jest . fn ( ( ) => false ) ;
21- const getPath = jest . fn ( ( ) => '/User/Data' ) ;
19+ const moveToApplicationsFolderMock = jest . fn ( ) ;
20+ const isInApplicationsFolderMock = jest . fn ( ( ) => false ) ;
21+ const getPathMock = jest . fn ( ( ) => '/User/Data' ) ;
2222
23- const showMessageBox = jest . fn ( async ( ) => ( { response : 0 } ) ) ;
23+ const showMessageBoxMock = jest . fn ( async ( ) => ( { response : 0 } ) ) ;
2424
2525jest . mock ( 'electron' , ( ) => ( {
2626 app : {
27- getPath : ( ) => getPath ( ) ,
28- isInApplicationsFolder : ( ) => isInApplicationsFolder ( ) ,
29- moveToApplicationsFolder : ( ) => moveToApplicationsFolder ( ) ,
27+ getPath : ( ) => getPathMock ( ) ,
28+ isInApplicationsFolder : ( ) => isInApplicationsFolderMock ( ) ,
29+ moveToApplicationsFolder : ( ) => moveToApplicationsFolderMock ( ) ,
3030 } ,
31- dialog : { showMessageBox : ( ) => showMessageBox ( ) } ,
31+ dialog : { showMessageBox : ( ) => showMessageBoxMock ( ) } ,
3232} ) ) ;
3333
34- const logError = jest . fn ( ) ;
34+ const logErrorMock = jest . fn ( ) ;
3535jest . mock ( '../shared/logger' , ( ) => ( {
36- logError : ( ...a : unknown [ ] ) => logError ( ...a ) ,
36+ logError : ( ...a : unknown [ ] ) => logErrorMock ( ...a ) ,
3737} ) ) ;
3838
3939let mac = true ;
@@ -54,55 +54,55 @@ describe('main/first-run', () => {
5454 } ) ;
5555
5656 it ( 'creates first-run marker when not existing and returns true' , async ( ) => {
57- existsSync . mockReturnValueOnce ( false ) ; // marker absent
58- existsSync . mockReturnValueOnce ( false ) ; // folder absent
57+ existsSyncMock . mockReturnValueOnce ( false ) ; // marker absent
58+ existsSyncMock . mockReturnValueOnce ( false ) ; // folder absent
5959 await onFirstRunMaybe ( ) ;
60- expect ( mkdirSync ) . toHaveBeenCalledWith ( path . dirname ( configPath ( ) ) ) ;
61- expect ( writeFileSync ) . toHaveBeenCalledWith ( configPath ( ) , '' ) ;
60+ expect ( mkdirSyncMock ) . toHaveBeenCalledWith ( path . dirname ( configPath ( ) ) ) ;
61+ expect ( writeFileSyncMock ) . toHaveBeenCalledWith ( configPath ( ) , '' ) ;
6262 } ) ;
6363
6464 it ( 'skips writing when marker exists' , async ( ) => {
65- existsSync . mockReturnValueOnce ( true ) ; // marker present
65+ existsSyncMock . mockReturnValueOnce ( true ) ; // marker present
6666 await onFirstRunMaybe ( ) ;
67- expect ( writeFileSync ) . not . toHaveBeenCalled ( ) ;
68- expect ( mkdirSync ) . not . toHaveBeenCalled ( ) ;
67+ expect ( writeFileSyncMock ) . not . toHaveBeenCalled ( ) ;
68+ expect ( mkdirSyncMock ) . not . toHaveBeenCalled ( ) ;
6969 } ) ;
7070
7171 it ( 'handles fs write error gracefully' , async ( ) => {
72- existsSync . mockReturnValueOnce ( false ) ; // marker absent
73- existsSync . mockReturnValueOnce ( true ) ; // folder exists
74- writeFileSync . mockImplementation ( ( ) => {
72+ existsSyncMock . mockReturnValueOnce ( false ) ; // marker absent
73+ existsSyncMock . mockReturnValueOnce ( true ) ; // folder exists
74+ writeFileSyncMock . mockImplementation ( ( ) => {
7575 throw new Error ( 'fail' ) ;
7676 } ) ;
7777 await onFirstRunMaybe ( ) ;
78- expect ( logError ) . toHaveBeenCalledWith (
78+ expect ( logErrorMock ) . toHaveBeenCalledWith (
7979 'isFirstRun' ,
8080 'Unable to write firstRun file' ,
8181 expect . any ( Error ) ,
8282 ) ;
8383 } ) ;
8484
8585 it ( 'prompts and moves app on macOS when user accepts' , async ( ) => {
86- existsSync . mockReturnValueOnce ( false ) ; // marker
87- existsSync . mockReturnValueOnce ( false ) ; // folder
88- showMessageBox . mockResolvedValueOnce ( { response : 0 } ) ;
86+ existsSyncMock . mockReturnValueOnce ( false ) ; // marker
87+ existsSyncMock . mockReturnValueOnce ( false ) ; // folder
88+ showMessageBoxMock . mockResolvedValueOnce ( { response : 0 } ) ;
8989 await onFirstRunMaybe ( ) ;
90- expect ( moveToApplicationsFolder ) . toHaveBeenCalled ( ) ;
90+ expect ( moveToApplicationsFolderMock ) . toHaveBeenCalled ( ) ;
9191 } ) ;
9292
9393 it ( 'does not move when user declines' , async ( ) => {
94- existsSync . mockReturnValueOnce ( false ) ;
95- existsSync . mockReturnValueOnce ( false ) ;
96- showMessageBox . mockResolvedValueOnce ( { response : 1 } ) ;
94+ existsSyncMock . mockReturnValueOnce ( false ) ;
95+ existsSyncMock . mockReturnValueOnce ( false ) ;
96+ showMessageBoxMock . mockResolvedValueOnce ( { response : 1 } ) ;
9797 await onFirstRunMaybe ( ) ;
98- expect ( moveToApplicationsFolder ) . not . toHaveBeenCalled ( ) ;
98+ expect ( moveToApplicationsFolderMock ) . not . toHaveBeenCalled ( ) ;
9999 } ) ;
100100
101101 it ( 'skips prompt on non-macOS' , async ( ) => {
102102 mac = false ;
103- existsSync . mockReturnValueOnce ( false ) ;
104- existsSync . mockReturnValueOnce ( false ) ;
103+ existsSyncMock . mockReturnValueOnce ( false ) ;
104+ existsSyncMock . mockReturnValueOnce ( false ) ;
105105 await onFirstRunMaybe ( ) ;
106- expect ( showMessageBox ) . not . toHaveBeenCalled ( ) ;
106+ expect ( showMessageBoxMock ) . not . toHaveBeenCalled ( ) ;
107107 } ) ;
108108} ) ;
0 commit comments