tschaub / mock-fs

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

binding: mock readFileSync #378

Closed Rugvip closed 10 months ago

Rugvip commented 11 months ago

Potential fix for #377

Most of it is explained in the comment, but to reiterate: we can mock the optimized readFileSync method introduced in Node v20 by calling the original readFileSync but bypassing the optimization by calling .toString('utf8') manually afterwards instead.

I figured it's safe to ignore the flag since it's just mocked reads anyway, let's me know if that needs a fix.

chadlwilson commented 11 months ago

Whereas it was working fine on Node 20.7.0, I think this workaround no longer work entirely correctly on its own with Node 20.8.0+.

Based on the changelog at https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V20.md#2023-09-28-version-2080-current-ruyadorno , I am guessing it's some of the changes such as https://github.com/nodejs/node/pull/49593 or https://github.com/nodejs/node/pull/49691

Rugvip commented 10 months ago

Closing this since there are additional breaking change in Node.js v20.8.0, and we are now moving away from mock-fs in favor of temporary mock directories. (https://github.com/backstage/backstage/issues/20436 has some extra context in case anyone is interested)