It looks like the fs.cp mock does not work on Node 20.
In my examples fs.stat('/path/that/exists/only/in/mock-fs') works indicating that mocks are active, yet fs.cp('/path/that/exists/only/in/mock-fs', tempPath, {recursive: true}) throws.
Example (index.js file):
import { default as mock } from "mock-fs";
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { fileURLToPath } from "node:url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
async function statAndCopy(source, dest) {
const stats = await fs.stat(source);
console.log(source, stats.ctime);
await fs.cp(source, dest, { recursive: true });
}
const tempdirs = [];
try {
console.log(`native:`);
tempdirs.unshift(await fs.mkdtemp(os.tmpdir()));
await statAndCopy(__dirname, tempdirs[0]);
console.log();
mock({ "/source": mock.load(`${__dirname}`) });
console.log(`mocked:`);
tempdirs.unshift(await fs.mkdtemp(os.tmpdir()));
await statAndCopy("/source", tempdirs[0]);
console.log();
mock.restore();
} catch (e) {
console.error(e);
} finally {
await Promise.allSettled(tempdirs.map((d) => fs.rm(d, { recursive: true })));
}
It looks like the
fs.cp
mock does not work on Node 20.In my examples
fs.stat('/path/that/exists/only/in/mock-fs')
works indicating that mocks are active, yetfs.cp('/path/that/exists/only/in/mock-fs', tempPath, {recursive: true})
throws.Example (
index.js
file):arm64, mac OS 14.7, node v20.15.0,
mock-fs@5.4.1