Skip to content

Commit 6aa9c85

Browse files
committed
update node.js from 20 to 22
Signed-off-by: Ashish Pandey <aspandey@redhat.com>
1 parent e60a19d commit 6aa9c85

File tree

4 files changed

+36
-16
lines changed

4 files changed

+36
-16
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20.11.0
1+
22.4.1

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
"@types/jest": "29.5.14",
133133
"@types/lodash": "4.17.13",
134134
"@types/mongodb": "4.0.7",
135-
"@types/node": "20.17.6",
135+
"@types/node": "22.4.1",
136136
"@types/pg": "8.11.10",
137137
"@types/request": "2.48.12",
138138
"eslint": "8.57.1",

src/test/unit_tests/test_nb_native_fs.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,42 @@ const { get_process_fs_context } = require('../../util/native_fs_utils');
1313

1414
const DEFAULT_FS_CONFIG = get_process_fs_context();
1515

16+
/**
17+
* Node.js 22 changes fs.Stats Date values to be populated lazily for improving performance.
18+
* @param {fs.Stats} fs_stat
19+
*/
20+
function get_fs_stat_with_lazy_date(fs_stat) {
21+
const stats_obj = { ...fs_stat };
22+
if (!os_utils.IS_MAC) {
23+
stats_obj.birthtime = fs_stat.ctime;
24+
stats_obj.birthtimeMs = fs_stat.ctimeMs;
25+
}
26+
stats_obj.atime = fs_stat.atime;
27+
stats_obj.ctime = fs_stat.ctime;
28+
stats_obj.mtime = fs_stat.mtime;
29+
return stats_obj;
30+
}
31+
32+
1633
mocha.describe('nb_native fs', async function() {
1734

1835
mocha.describe('stat', async function() {
1936
mocha.it('works', async function() {
2037
const path = 'package.json';
2138
const res = await nb_native().fs.stat(DEFAULT_FS_CONFIG, path);
2239
const res2 = await fs.promises.stat(path);
40+
console.log("res2.atime: ", res2.atime, "res2.mtime: ", res2.mtime, "res2.ctime: ", res2.ctime);
41+
2342
// birthtime in non mac platforms is ctime
2443
//https://nodejs.org/api/fs.html#statsbirthtime
25-
if (!os_utils.IS_MAC) {
26-
res2.birthtime = res2.ctime;
27-
res2.birthtimeMs = res2.ctimeMs;
28-
}
44+
//Node 22 creates Date objects lazily to improve performance.
45+
//To get these objects we have to access it and just printing
46+
//would not do that, we have to assign it.
47+
const fs_stat_all_dates = get_fs_stat_with_lazy_date(res2);
48+
2949
assert.deepStrictEqual(
3050
_.omit(res, 'xattr', 'mtimeNsBigint', 'atimeNsBigint', 'ctimeNsBigint'), // we need to remove xattr, mtimeSec, mtimeNsec from fs_napi response as the node JS stat doesn't return them
31-
_.omitBy(res2, v => typeof v === 'function'),
51+
_.omitBy(fs_stat_all_dates, v => typeof v === 'function'),
3252
);
3353
});
3454
});
@@ -56,15 +76,15 @@ mocha.describe('nb_native fs', async function() {
5676
// stat_res is the stat of the regular file (follows the link)
5777
const stat_res = await fs.promises.stat(LINK_PATH);
5878

79+
console.log("lstat_res.atime: ", lstat_res.atime, "lstat_res.mtime: ", lstat_res.mtime, "lstat_res.ctime: ", lstat_res.ctime);
80+
5981
// birthtime in non mac platforms is ctime
6082
// https://nodejs.org/api/fs.html#statsbirthtime
61-
if (!os_utils.IS_MAC) {
62-
lstat_res.birthtime = lstat_res.ctime;
63-
lstat_res.birthtimeMs = lstat_res.ctimeMs;
64-
}
83+
const fs_lstat_all_dates = get_fs_stat_with_lazy_date(lstat_res);
84+
6585
assert.deepStrictEqual(
6686
_.omit(native_lstat_res, 'xattr', 'mtimeNsBigint', 'atimeNsBigint', 'ctimeNsBigint'), // we need to remove xattr, mtimeNsBigint, atimeNsBigint, ctimeNsBigint from fs_napi response as the node JS stat doesn't return them
67-
_.omitBy(lstat_res, v => typeof v === 'function'),
87+
_.omitBy(fs_lstat_all_dates, v => typeof v === 'function'),
6888
);
6989

7090
assert.notDeepStrictEqual(

0 commit comments

Comments
 (0)