|
|
@ -65,38 +65,55 @@ fs.open('.', 'r', undefined, common.mustCall(function(err, fd) { |
|
|
|
assert.fail(err); |
|
|
|
} |
|
|
|
if (stats) { |
|
|
|
console.dir(stats); |
|
|
|
assert.ok(stats.mtime instanceof Date); |
|
|
|
} |
|
|
|
fs.close(fd, assert.ifError); |
|
|
|
})); |
|
|
|
|
|
|
|
console.log(`stating: ${__filename}`); |
|
|
|
fs.stat(__filename, common.mustCall(function(err, s) { |
|
|
|
assert.ifError(err); |
|
|
|
|
|
|
|
console.dir(s); |
|
|
|
|
|
|
|
console.log(`isDirectory: ${JSON.stringify(s.isDirectory())}`); |
|
|
|
assert.strictEqual(false, s.isDirectory()); |
|
|
|
|
|
|
|
console.log(`isFile: ${JSON.stringify(s.isFile())}`); |
|
|
|
assert.strictEqual(true, s.isFile()); |
|
|
|
|
|
|
|
console.log(`isSocket: ${JSON.stringify(s.isSocket())}`); |
|
|
|
assert.strictEqual(false, s.isSocket()); |
|
|
|
|
|
|
|
console.log(`isBlockDevice: ${JSON.stringify(s.isBlockDevice())}`); |
|
|
|
assert.strictEqual(false, s.isBlockDevice()); |
|
|
|
|
|
|
|
console.log(`isCharacterDevice: ${JSON.stringify(s.isCharacterDevice())}`); |
|
|
|
assert.strictEqual(false, s.isCharacterDevice()); |
|
|
|
|
|
|
|
console.log(`isFIFO: ${JSON.stringify(s.isFIFO())}`); |
|
|
|
assert.strictEqual(false, s.isFIFO()); |
|
|
|
|
|
|
|
console.log(`isSymbolicLink: ${JSON.stringify(s.isSymbolicLink())}`); |
|
|
|
assert.strictEqual(false, s.isSymbolicLink()); |
|
|
|
|
|
|
|
assert.ok(s.mtime instanceof Date); |
|
|
|
const keys = [ |
|
|
|
'dev', 'mode', 'nlink', 'uid', |
|
|
|
'gid', 'rdev', 'ino', 'size', |
|
|
|
'atime', 'mtime', 'ctime', 'birthtime', |
|
|
|
'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs' |
|
|
|
]; |
|
|
|
if (!common.isWindows) { |
|
|
|
keys.push('blocks', 'blksize'); |
|
|
|
} |
|
|
|
const numberFields = [ |
|
|
|
'dev', 'mode', 'nlink', 'uid', 'gid', 'rdev', 'ino', 'size', |
|
|
|
'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs' |
|
|
|
]; |
|
|
|
const dateFields = ['atime', 'mtime', 'ctime', 'birthtime']; |
|
|
|
keys.forEach(function(k) { |
|
|
|
assert.ok(k in s, `${k} should be in Stats`); |
|
|
|
assert.notStrictEqual(s[k], undefined, `${k} should not be undefined`); |
|
|
|
assert.notStrictEqual(s[k], null, `${k} should not be null`); |
|
|
|
}); |
|
|
|
numberFields.forEach((k) => { |
|
|
|
assert.strictEqual(typeof s[k], 'number', `${k} should be a number`); |
|
|
|
}); |
|
|
|
dateFields.forEach((k) => { |
|
|
|
assert.ok(s[k] instanceof Date, `${k} should be a Date`); |
|
|
|
}); |
|
|
|
const jsonString = JSON.stringify(s); |
|
|
|
const parsed = JSON.parse(jsonString); |
|
|
|
keys.forEach(function(k) { |
|
|
|
assert.notStrictEqual(parsed[k], undefined, `${k} should not be undefined`); |
|
|
|
assert.notStrictEqual(parsed[k], null, `${k} should not be null`); |
|
|
|
}); |
|
|
|
numberFields.forEach((k) => { |
|
|
|
assert.strictEqual(typeof parsed[k], 'number', `${k} should be a number`); |
|
|
|
}); |
|
|
|
dateFields.forEach((k) => { |
|
|
|
assert.strictEqual(typeof parsed[k], 'string', `${k} should be a string`); |
|
|
|
}); |
|
|
|
})); |
|
|
|