@@ -5,10 +5,15 @@ import fs from "fs";
55import path from "path" ;
66
77import { run } from "./eff" ;
8- import { readFile , writeFile , interpretLocalFileSystem } from "./fileSystem" ;
8+ import {
9+ readFile ,
10+ writeFile ,
11+ interpretLocalFileSystem ,
12+ interpretMockFileSystem ,
13+ } from "./fileSystem" ;
914import { tempDirectory } from "./testUtils.js" ;
1015
11- test . cb ( "Read file" , t => {
16+ test . cb ( "Local File System – Read file" , t => {
1217 const a = "Hello, World! I'm reading!" ;
1318 const fileName = "./helloWorldReading.txt" ;
1419
@@ -28,7 +33,7 @@ test.cb("Read file", t => {
2833 } ) ;
2934} ) ;
3035
31- test . cb ( "Write file" , t => {
36+ test . cb ( "Local File System – Write file" , t => {
3237 const a = "Hello, World! I'm writing!" ;
3338 const fileName = "./helloWorldWriting.txt" ;
3439
@@ -47,3 +52,49 @@ test.cb("Write file", t => {
4752 } ) ( application ) ;
4853 } ) ;
4954} ) ;
55+
56+ test . cb ( "Mock File System – Read file" , t => {
57+ const a = "Hello, World! I'm writing!" ;
58+ const fileName = "./helloWorldWriting.txt" ;
59+ const directory = "/directory" ;
60+
61+ const application = readFile ( fileName ) ;
62+
63+ let fileSystem = { "/directory/helloWorldWriting.txt" : a } ;
64+
65+ run (
66+ interpretMockFileSystem ( {
67+ fileSystemRoot : directory ,
68+ startingFileSystem : fileSystem ,
69+ onUpdate : newFileSystem => {
70+ fileSystem = newFileSystem ;
71+ } ,
72+ } ) ,
73+ ) ( b => {
74+ t . is ( b , a ) ;
75+ t . end ( ) ;
76+ } ) ( application ) ;
77+ } ) ;
78+
79+ test . cb ( "Mock File System – Write file" , t => {
80+ const a = "Hello, World! I'm writing!" ;
81+ const fileName = "./helloWorldWriting.txt" ;
82+ const directory = "/directory" ;
83+
84+ const application = writeFile ( fileName , a ) ;
85+
86+ let fileSystem : { [ string ] : string } = { } ;
87+
88+ run (
89+ interpretMockFileSystem ( {
90+ fileSystemRoot : directory ,
91+ startingFileSystem : fileSystem ,
92+ onUpdate : newFileSystem => {
93+ fileSystem = newFileSystem ;
94+ } ,
95+ } ) ,
96+ ) ( ( ) => {
97+ t . is ( fileSystem [ "/directory/helloWorldWriting.txt" ] , a ) ;
98+ t . end ( ) ;
99+ } ) ( application ) ;
100+ } ) ;
0 commit comments