Use fixed timestamps in the fs.cp preserveTimestamps test (#2136)

This commit is contained in:
Chris Tate
2026-10-24 15:01:18 -05:00
committed by GitHub
+6 -1
View File
@@ -88,8 +88,13 @@ const stamp = new Date("2021-05-06T07:08:09.123Z");
fs.utimesSync("file.txt", stamp, stamp);
await fsp.cp("file.txt", "p-stamped.txt", { preserveTimestamps: true });
console.log(new Date(fs.statSync("p-stamped.txt").mtimeMs).toISOString());
// The source tree gets fixed times: its own times come from the clock, and
// whether a copy equals them depends on their sub-millisecond digits.
fs.utimesSync("src/a.txt", stamp, stamp);
fs.utimesSync("src", stamp, stamp);
await fsp.cp("src", "p-stamped-dir", { recursive: true, preserveTimestamps: true });
console.log(fs.statSync("p-stamped-dir").mtimeMs === fs.statSync("src").mtimeMs);
for (const path of ["p-stamped-dir", "p-stamped-dir/a.txt"])
console.log(path, new Date(fs.statSync(path).mtimeMs).toISOString());
const rejected = await fsp.cp("missing", "x").then(
() => "fulfilled",