Open jwngr opened 9 years ago
Hey @tschaub - if you can point me to some code lines or let me know what you think may be the issue here, I'd be happy to put together a PR for this. I assume the issue here is that each call to appendFile()
is actually overwriting the file instead of appending to it. We don't run into this issue with appendFileSync()
since it blocks the process until the append is done, before any other appends can be started.
Sequential calls to the asynchronous
fs.appendFile()
using this mocked library appear to conflict and overwrite each other, while the non-mocked library does not have this behavior.Here is the behavior with the regular
fs
library:This outputs the following:
Note that this output is non-deterministic because the five writes could complete in any order. But that is tangential to this issue.
Now, using the
mock-fs
library:This outputs:
As you can see, only the last append succeeds. If we use the synchronous mocked version, all is well:
Outputs:
I would like to use the asynchronous version of
appendFile()
because I don't care about the ordering of items, just that they all are there. I also don't want to block the process while the write is happening, which is what the synchronous version does.