@@ -114,4 +114,78 @@ if(window.__TAURI__ || window.__ELECTRON__){
114114 } ) ;
115115 }
116116 } ) ;
117+
118+ describe ( `test homeDir api` , function ( ) {
119+ async function getHomeDir ( ) {
120+ if ( window . __TAURI__ ) {
121+ return window . __TAURI__ . path . homeDir ( ) ;
122+ } else if ( window . electronAPI ) {
123+ return window . electronAPI . homeDir ( ) ;
124+ }
125+ return null ;
126+ }
127+
128+ it ( `should homeDir return a valid path ending with separator` , async function ( ) {
129+ let homeDir = await getHomeDir ( ) ;
130+ expect ( homeDir ) . to . be . a ( 'string' ) ;
131+ expect ( homeDir . length ) . to . be . greaterThan ( 0 ) ;
132+ if ( IS_WINDOWS ) {
133+ // Windows home dir should contain a drive letter like C:\Users\...
134+ expect ( homeDir . charAt ( 1 ) ) . to . eql ( ':' ) ;
135+ expect ( homeDir . endsWith ( '\\' ) ) . to . be . true ;
136+ } else {
137+ // Unix home dir should start and end with /
138+ expect ( homeDir . startsWith ( '/' ) ) . to . be . true ;
139+ expect ( homeDir . endsWith ( '/' ) ) . to . be . true ;
140+ }
141+ } ) ;
142+ } ) ;
143+
144+ describe ( `test tempDir api` , function ( ) {
145+ async function getTempDir ( ) {
146+ if ( window . __TAURI__ ) {
147+ return window . __TAURI__ . os . tempdir ( ) ;
148+ } else if ( window . electronAPI ) {
149+ return window . electronAPI . tempDir ( ) ;
150+ }
151+ return null ;
152+ }
153+
154+ it ( `should tempDir return a valid path without trailing separator` , async function ( ) {
155+ let tempDir = await getTempDir ( ) ;
156+ expect ( tempDir ) . to . be . a ( 'string' ) ;
157+ expect ( tempDir . length ) . to . be . greaterThan ( 0 ) ;
158+ if ( IS_WINDOWS ) {
159+ // Windows temp dir should contain a drive letter like C:\...
160+ expect ( tempDir . charAt ( 1 ) ) . to . eql ( ':' ) ;
161+ expect ( tempDir . endsWith ( '\\' ) ) . to . be . false ;
162+ } else {
163+ // Unix temp dir should start with / but not end with /
164+ expect ( tempDir . startsWith ( '/' ) ) . to . be . true ;
165+ expect ( tempDir . endsWith ( '/' ) ) . to . be . false ;
166+ }
167+ } ) ;
168+ } ) ;
169+
170+ describe ( `test path.sep api` , function ( ) {
171+ function getPathSep ( ) {
172+ if ( window . __TAURI__ ) {
173+ return window . __TAURI__ . path . sep ;
174+ } else if ( window . electronAPI ) {
175+ return window . electronAPI . path . sep ;
176+ }
177+ return null ;
178+ }
179+
180+ it ( `should path.sep return correct separator for platform` , function ( ) {
181+ let sep = getPathSep ( ) ;
182+ expect ( sep ) . to . be . a ( 'string' ) ;
183+ expect ( sep . length ) . to . eql ( 1 ) ;
184+ if ( IS_WINDOWS ) {
185+ expect ( sep ) . to . eql ( '\\' ) ;
186+ } else {
187+ expect ( sep ) . to . eql ( '/' ) ;
188+ }
189+ } ) ;
190+ } ) ;
117191}
0 commit comments