@@ -13,22 +13,42 @@ const { get_process_fs_context } = require('../../util/native_fs_utils');
13
13
14
14
const DEFAULT_FS_CONFIG = get_process_fs_context ( ) ;
15
15
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
+
16
33
mocha . describe ( 'nb_native fs' , async function ( ) {
17
34
18
35
mocha . describe ( 'stat' , async function ( ) {
19
36
mocha . it ( 'works' , async function ( ) {
20
37
const path = 'package.json' ;
21
38
const res = await nb_native ( ) . fs . stat ( DEFAULT_FS_CONFIG , path ) ;
22
39
const res2 = await fs . promises . stat ( path ) ;
40
+ console . log ( "res2.atime: " , res2 . atime , "res2.mtime: " , res2 . mtime , "res2.ctime: " , res2 . ctime ) ;
41
+
23
42
// birthtime in non mac platforms is ctime
24
43
//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
+
29
49
assert . deepStrictEqual (
30
50
_ . 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' ) ,
32
52
) ;
33
53
} ) ;
34
54
} ) ;
@@ -56,15 +76,15 @@ mocha.describe('nb_native fs', async function() {
56
76
// stat_res is the stat of the regular file (follows the link)
57
77
const stat_res = await fs . promises . stat ( LINK_PATH ) ;
58
78
79
+ console . log ( "lstat_res.atime: " , lstat_res . atime , "lstat_res.mtime: " , lstat_res . mtime , "lstat_res.ctime: " , lstat_res . ctime ) ;
80
+
59
81
// birthtime in non mac platforms is ctime
60
82
// 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
+
65
85
assert . deepStrictEqual (
66
86
_ . 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' ) ,
68
88
) ;
69
89
70
90
assert . notDeepStrictEqual (
0 commit comments