tschaub / mock-fs

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

fix: Replace nextTick by setImmediate. #360

Closed regseb closed 1 month ago

regseb commented 2 years ago

Replace process.nextTick() by setImmediate() to be closer to the reality of asynchronous methods. This pull request fixes #352 testcase with yauzl.

3cp commented 2 years ago

The CI shows this fix only works for Nodejs v16+. You can try to add a condition to test against nodejs version.

regseb commented 2 years ago

I replaced the nextTick only for the promise and it seems to work on all versions of Node. Maybe the callbacks are executed directly after, while the promises are executed on the next event loop.

3cp commented 2 years ago

@tschaub can you review this? I am not sure about the side effect of this change.

regseb commented 1 month ago

I tested mock-fs with the latest version 5.3.0 and the problem is still there.

  1. npm install
  2. zip foo.zip package.json (or zip package.json with an other tool)
  3. node index.js

    • Current:

      [setImmediate] end [Promise] end

    • Expected:

      [setImmediate] entry package.json [setImmediate] end [Promise] entry package.json [Promise] end


@tschaub Can you review this PR to fix the problem?