tschaub / mock-fs

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

DirectoryOptions - mtime does not get used #333

Open viyaha opened 3 years ago

viyaha commented 3 years ago

Setup:

Node: 14.17.1 mock-fs: 5.0.0

Specification of the mtime in a directory call gets ignored, all other timestamps are working as expected.

import { statSync } from "fs";
import mock from "mock-fs";
import { directory, file } from "mock-fs/lib/filesystem";

mock({
    "C:\\test": directory({mtime: new Date(1), ctime: new Date(1), atime: new Date(1), birthtime: new Date(1)}),
    "C:\\test\\test.txt": file({mtime: new Date(1), ctime: new Date(1), atime: new Date(1), birthtime: new Date(1)}),
});

console.log(statSync("C:\\test"));
console.log(statSync("C:\\test\\test.txt"));

Result:

Stats {
  dev: 8675309,
  mode: 16895,
  nlink: 2,
  uid: 0,
  gid: 0,
  rdev: 0,
  blksize: 4096,
  ino: 10,
  size: 1,
  blocks: 1,
  atimeMs: 1,
  mtimeMs: 1626956851865,
  ctimeMs: 1,
  birthtimeMs: 1,
  atime: 1970-01-01T00:00:00.001Z,
  mtime: 2021-07-22T12:27:31.865Z,
  ctime: 1970-01-01T00:00:00.001Z,
  birthtime: 1970-01-01T00:00:00.001Z
}
Stats {
  dev: 8675309,
  mode: 33206,
  nlink: 1,
  uid: 0,
  gid: 0,
  rdev: 0,
  blksize: 4096,
  ino: 11,
  size: 0,
  blocks: 0,
  atimeMs: 1,
  mtimeMs: 1,
  ctimeMs: 1,
  birthtimeMs: 1,
  atime: 1970-01-01T00:00:00.001Z,
  mtime: 1970-01-01T00:00:00.001Z,
  ctime: 1970-01-01T00:00:00.001Z,
  birthtime: 1970-01-01T00:00:00.001Z
}