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