const fs = require('fs');
fs.utimesSync(__filename, Date.now(), Date.now());
const fs = require('fs');
fs.utimesSync(__filename, Date.now().toString(), Date.now().toString());
Always
It should work same as Linux and Mac
● does not re-run tests when only access time is modified
EINVAL: invalid argument, utime 'C:\Users\RUNNER~1\AppData\Local\Temp\watch_mode_no_access\foo.js'
61 | const modulePath = path.join(DIR, 'foo.js');
62 | const stat = fs.lstatSync(modulePath);
> 63 | fs.utimesSync(modulePath, stat.atime.getTime(), stat.mtime.getTime());
| ^
64 |
65 | await testRun.waitUntil(({stderr}) => numberOfTestRuns(stderr) === 2);
66 |
at Object.utimesSync (e2e/__tests__/watchModeNoAccess.test.ts:63:6)
That's from this CI run, where the same test passes on both Linux and Mac: https://github.com/facebook/jest/runs/641141754
According to the docs, utimes can take number | string | Date: https://nodejs.org/api/fs.html#fs_fs_utimes_path_atime_mtime_callback. Seems like Windows only supports Date?
This is the same as #5561.
Seems like Windows only supports Date?
No, but you're passing numbers that are probably out of range for the underlying file system.
Date.now() returns the time in milliseconds but fs.utimesSync() takes timestamps in seconds. You need to divide by 1,000.
Oh! Hah, would you look at that 😅 That's not mentioned in the docs, although I guess most people calling these APIs know that already?
Would it be possible for utimes to throw if number passed in is way into the future? Might be valid tho.
The documentation could be clearer on the units used, I agree. Do you want to send a PR for that?
Would it be possible for utimes to throw if number passed in is way into the future?
I don't think so. There's no real way to know what the supported range is until you try it.
@bnoordhuis quick try (or as quick as GitHub's laggy web editor allows) here: #33230
Closed by above PR