tschaub / mock-fs

Configurable mock for the fs module
https://npmjs.org/package/mock-fs
Other
906 stars 86 forks source link

Reset initial counter state back to 0 #367

Open AlexanderBelokon opened 1 year ago

AlexanderBelokon commented 1 year ago

https://github.com/tschaub/mock-fs/pull/322 fixed some issues with tape, but introduced a new one: the node process exits with a non-zero code in some scenarios. I believe this change is responsible for that, and reverting it fixes the issue for me.

3cp commented 1 year ago

@tschaub do you recall why you set the counter to -1 when fixing the tape issue?

tschaub commented 1 year ago

Initializing the counter to -1 means that stdin will have a file descriptor of 0, stdout will get 1, and stderr will get 2 given the order that things are constructed. This lets people do things like fs.write(1, buffer) to write to stdout, which is what I understood that Tape does.

I should have added tests or comments to make this clearer.

I think we’ll need to get some more details on what doesn’t work in Tape before settling on a better fix.

AlexanderBelokon commented 1 year ago

@tschaub Thank you for looking into this! I've created a repro for my problem when using tape and mock-fs on Node16+.

If you run npm run test in the repo, tape's output looks fine, but the exit code of the node process is 134 instead of 0, as if it was terminated abnormally.

If you run npm run hack it finishes with 0, as it should.

I wish I could provide an explanation for why that is, but as of now I can't. I really need this to work, though 😅