MCPcopy Index your code
hub / github.com/nodejs/node / runTest

Function runTest

test/parallel/test-fs-stat-date.mjs:52–88  ·  view source on GitHub ↗
(atime, mtime, margin = 0)

Source from the content-addressed store, hash-verified

50}
51
52async function runTest(atime, mtime, margin = 0) {
53 margin += Number.EPSILON;
54 try {
55 await fsPromises.utimes(filepath, new Date(atime), new Date(mtime));
56 } catch (e) {
57 if (ignoredErrors.has(e.code)) return;
58 throw e;
59 }
60
61 const stats = await fsPromises.stat(filepath);
62 closeEnough(stats.atimeMs, atime, margin);
63 closeEnough(stats.mtimeMs, mtime, margin);
64 closeEnough(stats.atime.getTime(), new Date(atime).getTime(), margin);
65 closeEnough(stats.mtime.getTime(), new Date(mtime).getTime(), margin);
66 validateEnumerability(stats);
67
68 const statsBigint = await fsPromises.stat(filepath, { bigint: true });
69 closeEnough(statsBigint.atimeMs, BigInt(atime), margin);
70 closeEnough(statsBigint.mtimeMs, BigInt(mtime), margin);
71 closeEnough(statsBigint.atime.getTime(), new Date(atime).getTime(), margin);
72 closeEnough(statsBigint.mtime.getTime(), new Date(mtime).getTime(), margin);
73 validateEnumerability(statsBigint);
74
75 const statsSync = fs.statSync(filepath);
76 closeEnough(statsSync.atimeMs, atime, margin);
77 closeEnough(statsSync.mtimeMs, mtime, margin);
78 closeEnough(statsSync.atime.getTime(), new Date(atime).getTime(), margin);
79 closeEnough(statsSync.mtime.getTime(), new Date(mtime).getTime(), margin);
80 validateEnumerability(statsSync);
81
82 const statsSyncBigint = fs.statSync(filepath, { bigint: true });
83 closeEnough(statsSyncBigint.atimeMs, BigInt(atime), margin);
84 closeEnough(statsSyncBigint.mtimeMs, BigInt(mtime), margin);
85 closeEnough(statsSyncBigint.atime.getTime(), new Date(atime).getTime(), margin);
86 closeEnough(statsSyncBigint.mtime.getTime(), new Date(mtime).getTime(), margin);
87 validateEnumerability(statsSyncBigint);
88}
89
90// Too high/low numbers produce too different results on different platforms
91{

Callers 1

Calls 6

closeEnoughFunction · 0.70
validateEnumerabilityFunction · 0.70
hasMethod · 0.65
utimesMethod · 0.45
statMethod · 0.45
statSyncMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…