Neil de Carteret
Neil de Carteret11mo ago

What's a good way to write tests for a script which does a bunch filesystem wrangling?

As per the title - I have a script which, given a folder, does a bunch of moving and renaming. I'd like to test it, ideally without having to abstract the entire fs away. The last timer I had to do this under Node.js I think I used mock-fs, but that works directly with Node's fs API. What would be a good approach for doing this in Deno?
4 Replies
marvinh.
marvinh.11mo ago
Create a fixture folder with test data. For each test you can create a temporary folder with Deno. makeTempFile() and copy the test files into that. Then do your file moving or other logic and assert the end result. That's what I usually do
Neil de Carteret
Neil de Carteret11mo ago
Yeah, that's a workable approach. It just gets slow when the number of test cases gets high. Thanks for responding!
marvinh.
marvinh.11mo ago
It really depends. With SSDs these days it's pretty fast
Esente
Esente11mo ago
I have been using https://deno.land/x/mock_file@v1.1.2 with good result.