@@ -28,17 +28,14 @@ const fs = require('fs');
28
28
fs . stat ( '.' , common . mustCall ( function ( err , stats ) {
29
29
assert . ifError ( err ) ;
30
30
assert . ok ( stats . mtime instanceof Date ) ;
31
+ assert . ok ( stats . hasOwnProperty ( 'blksize' ) ) ;
32
+ assert . ok ( stats . hasOwnProperty ( 'blocks' ) ) ;
31
33
// Confirm that we are not running in the context of the internal binding
32
34
// layer.
33
35
// Ref: https://github.com/nodejs/node/commit/463d6bac8b349acc462d345a6e298a76f7d06fb1
34
36
assert . strictEqual ( this , undefined ) ;
35
37
} ) ) ;
36
38
37
- fs . stat ( '.' , common . mustCall ( function ( err , stats ) {
38
- assert . ok ( stats . hasOwnProperty ( 'blksize' ) ) ;
39
- assert . ok ( stats . hasOwnProperty ( 'blocks' ) ) ;
40
- } ) ) ;
41
-
42
39
fs . lstat ( '.' , common . mustCall ( function ( err , stats ) {
43
40
assert . ifError ( err ) ;
44
41
assert . ok ( stats . mtime instanceof Date ) ;
@@ -71,16 +68,9 @@ fs.open('.', 'r', undefined, common.mustCall(function(err, fd) {
71
68
72
69
// fstatSync
73
70
fs . open ( '.' , 'r' , undefined , common . mustCall ( function ( err , fd ) {
74
- let stats ;
75
- try {
76
- stats = fs . fstatSync ( fd ) ;
77
- } catch ( err ) {
78
- assert . fail ( err ) ;
79
- }
80
- if ( stats ) {
81
- assert . ok ( stats . mtime instanceof Date ) ;
82
- }
83
- fs . close ( fd , assert . ifError ) ;
71
+ const stats = fs . fstatSync ( fd ) ;
72
+ assert . ok ( stats . mtime instanceof Date ) ;
73
+ fs . close ( fd , common . mustCall ( assert . ifError ) ) ;
84
74
} ) ) ;
85
75
86
76
fs . stat ( __filename , common . mustCall ( function ( err , s ) {
@@ -92,38 +82,30 @@ fs.stat(__filename, common.mustCall(function(err, s) {
92
82
assert . strictEqual ( s . isCharacterDevice ( ) , false ) ;
93
83
assert . strictEqual ( s . isFIFO ( ) , false ) ;
94
84
assert . strictEqual ( s . isSymbolicLink ( ) , false ) ;
95
- const keys = [
85
+
86
+ const jsonString = JSON . stringify ( s ) ;
87
+ const parsed = JSON . parse ( jsonString ) ;
88
+ [
96
89
'dev' , 'mode' , 'nlink' , 'uid' ,
97
90
'gid' , 'rdev' , 'blksize' , 'ino' , 'size' , 'blocks' ,
98
91
'atime' , 'mtime' , 'ctime' , 'birthtime' ,
99
- 'atimeMs' , 'mtimeMs' , 'ctimeMs' , 'birthtimeMs'
100
- ] ;
101
- const numberFields = [
102
- 'dev' , 'mode' , 'nlink' , 'uid' , 'gid' , 'rdev' , 'blksize' , 'ino' , 'size' ,
103
- 'blocks' , 'atimeMs' , 'mtimeMs' , 'ctimeMs' , 'birthtimeMs'
104
- ] ;
105
- const dateFields = [ 'atime' , 'mtime' , 'ctime' , 'birthtime' ] ;
106
- keys . forEach ( function ( k ) {
92
+ 'atimeMs' , 'mtimeMs' , 'ctimeMs' , 'birthtimeMs' ,
93
+ ] . forEach ( function ( k ) {
107
94
assert . ok ( k in s , `${ k } should be in Stats` ) ;
108
95
assert . notStrictEqual ( s [ k ] , undefined , `${ k } should not be undefined` ) ;
109
96
assert . notStrictEqual ( s [ k ] , null , `${ k } should not be null` ) ;
110
- } ) ;
111
- numberFields . forEach ( ( k ) => {
112
- assert . strictEqual ( typeof s [ k ] , 'number' , `${ k } should be a number` ) ;
113
- } ) ;
114
- dateFields . forEach ( ( k ) => {
115
- assert . ok ( s [ k ] instanceof Date , `${ k } should be a Date` ) ;
116
- } ) ;
117
- const jsonString = JSON . stringify ( s ) ;
118
- const parsed = JSON . parse ( jsonString ) ;
119
- keys . forEach ( function ( k ) {
120
97
assert . notStrictEqual ( parsed [ k ] , undefined , `${ k } should not be undefined` ) ;
121
98
assert . notStrictEqual ( parsed [ k ] , null , `${ k } should not be null` ) ;
122
99
} ) ;
123
- numberFields . forEach ( ( k ) => {
100
+ [
101
+ 'dev' , 'mode' , 'nlink' , 'uid' , 'gid' , 'rdev' , 'blksize' , 'ino' , 'size' ,
102
+ 'blocks' , 'atimeMs' , 'mtimeMs' , 'ctimeMs' , 'birthtimeMs' ,
103
+ ] . forEach ( ( k ) => {
104
+ assert . strictEqual ( typeof s [ k ] , 'number' , `${ k } should be a number` ) ;
124
105
assert . strictEqual ( typeof parsed [ k ] , 'number' , `${ k } should be a number` ) ;
125
106
} ) ;
126
- dateFields . forEach ( ( k ) => {
107
+ [ 'atime' , 'mtime' , 'ctime' , 'birthtime' ] . forEach ( ( k ) => {
108
+ assert . ok ( s [ k ] instanceof Date , `${ k } should be a Date` ) ;
127
109
assert . strictEqual ( typeof parsed [ k ] , 'string' , `${ k } should be a string` ) ;
128
110
} ) ;
129
111
} ) ) ;
0 commit comments