-
Notifications
You must be signed in to change notification settings - Fork 86
Closed
Description
Node v20.5.0 introduced an optimization to fs.readFileSync
for utf-8 files. Unfortunately, this breaks mock-fs. Here is a minimal test case that works with Node v20.4.0 but breaks with Node v20.5.0:
import mockFs from "mock-fs";
import { test } from "node:test";
import { readFileSync } from "fs";
import assert from "node:assert/strict";
test("mockFs", () => {
mockFs({ "file": "contents" })
const fileContents = readFileSync("file", 'utf-8').toString()
assert.equal(fileContents, "contents")
})
In Node v20.5.0, I get the error Error: ENOENT: no such file or directory, open 'file'
.
The above test case also works in Node v20.5.0 if I remove the 'utf-8'
option from readFileSync
. This issue specifically occurs for readFileSync
with 'utf-8'
option.
Here is the relevant commit: nodejs/node#48658
sunesimonsen, doosuu, joelcox22, j4r1mattia, tanner-reits and 13 morewatson, jjtang1985 and BethGriggs
Metadata
Metadata
Assignees
Labels
No labels