@@ -12,7 +12,7 @@ import {
1212 makeTauriFileSystem ,
1313 rsync ,
1414} from "../src/index.js" ;
15- import { createEffect , createRoot } from "solid-js" ;
15+ import { catchError , createEffect , createRoot } from "solid-js" ;
1616
1717describe ( "makeNoFileSystem" , ( ) => {
1818 const fs = makeNoFileSystem ( ) ;
@@ -52,6 +52,15 @@ describe("makeVirtualFileSystem", () => {
5252 } ) ;
5353 test ( "fs.readFile returns file content" , ( ) =>
5454 expect ( fs . readFile ( "src/test.ts" ) ) . toBe ( "// test" ) ) ;
55+ test ( "fs.readFile throws on attempting to read a directory as file" , ( ) => {
56+ expect ( ( ) => fs . readFile ( "src" ) ) . toThrow ( '"src" is not a file' ) ;
57+ } ) ;
58+ test ( "fs.readFile throws on attempting to read a non-existent file" , ( ) => {
59+ expect ( ( ) => fs . readFile ( "src/nonexistent.ts" ) ) . toThrow ( '"src/nonexistent.ts" is not a file' ) ;
60+ } ) ;
61+ test ( "fs.readFile throws on attempting to read from a non-existing directory" , ( ) => {
62+ expect ( ( ) => fs . readFile ( "nonexistent/test.ts" ) ) . toThrow ( '"nonexistent" is not a directory' )
63+ } ) ;
5564 test ( "fs.writeFile creates and overwrites file" , ( ) => {
5665 expect ( fs . readdir ( "src" ) ) . toHaveLength ( 1 ) ;
5766 fs . writeFile ( "src/test2.ts" , "// data" ) ;
@@ -115,6 +124,20 @@ describe("createFileSystem (sync) calls the underlying fs", () => {
115124 } ) ;
116125} ) ;
117126
127+ describe ( "createFileSystem (sync) relays file system errors" , ( ) => {
128+ test ( "a deleted file stored in a signal throws an error" , ( ) => new Promise < void > ( ( done , fail ) => {
129+ setTimeout ( ( ) => fail ( new Error ( 'did not throw' ) ) , 100 ) ;
130+ const fs = createFileSystem ( makeVirtualFileSystem ( { 'test.json' : '{}' } ) ) ;
131+ catchError ( ( ) => {
132+ createEffect ( ( ) => fs . readFile ( "test.json" ) ) ;
133+ setTimeout ( ( ) => fs . rm ( "test.json" ) , 30 ) ;
134+ } , ( error ) => {
135+ expect ( error ) . toEqual ( new Error ( '"test.json" is not a file' ) ) ;
136+ done ( ) ;
137+ } ) ;
138+ } ) ) ;
139+ } ) ;
140+
118141describe ( "createFileSystem (async) calls the underlying fs" , ( ) => {
119142 const afs = makeNoAsyncFileSystem ( ) ;
120143 instrumentFs ( afs ) ;
0 commit comments