Transcript from the "I/O Shell" Lesson
>> Some other things that make testing easier, I don't know where I first encountered this idea, but it's really good idea for writing both reusable code and for writing code that's easy to test. It's the idea of the IO shell. That's where you try to defer all of the places where you're gonna use input/output.
[00:00:20] So these are things where you what you're doing has kind of like an effect on the environment. So that might include something like reading from a file or writing to a file, these kinds of operations. If you can kind of push those up to the uppermost layer so that it's configurable, it'll be a lot easier to run your code in different kinds of environments.
[00:00:45] Like a web browser, or on some other kind of system, or kind of in a testing, in a way where it's easy to kind of provide synthetic inputs and get synthetic outputs. An example of what that might look like is if you have a piece of code where normally you have a module called foo.
[00:01:07] And by default, it uses the fs module behind the scenes. But you also maybe don't want it to do a bunch of stuff on your file system. So what you can do is pass in an optional fs argument that's like fake-fs. And it's just in memory, for example.
[00:01:25] This will make your tests run a bit faster. Although I would caution a little bit, if you use too many of these fake libraries, sooner or later, you're gonna hit a bug in one of those libraries. And then it's like you're kind of a little bit far removed from the real system.
[00:01:41] So it's just good to use a mix, I would say, of both real system calls when you can. But sometimes it's better to also use fake ones.