Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 18 additions & 36 deletions test/parallel/test-fs-stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,14 @@ const fs = require('fs');
fs.stat('.', common.mustCall(function(err, stats) {
assert.ifError(err);
assert.ok(stats.mtime instanceof Date);
assert.ok(stats.hasOwnProperty('blksize'));
assert.ok(stats.hasOwnProperty('blocks'));
// Confirm that we are not running in the context of the internal binding
// layer.
// Ref: https://github.com/nodejs/node/commit/463d6bac8b349acc462d345a6e298a76f7d06fb1
assert.strictEqual(this, undefined);
}));

fs.stat('.', common.mustCall(function(err, stats) {
assert.ok(stats.hasOwnProperty('blksize'));
assert.ok(stats.hasOwnProperty('blocks'));
}));

fs.lstat('.', common.mustCall(function(err, stats) {
assert.ifError(err);
assert.ok(stats.mtime instanceof Date);
Expand Down Expand Up @@ -71,16 +68,9 @@ fs.open('.', 'r', undefined, common.mustCall(function(err, fd) {

// fstatSync
fs.open('.', 'r', undefined, common.mustCall(function(err, fd) {
let stats;
try {
stats = fs.fstatSync(fd);
} catch (err) {
assert.fail(err);
}
if (stats) {
assert.ok(stats.mtime instanceof Date);
}
fs.close(fd, assert.ifError);
const stats = fs.fstatSync(fd);
assert.ok(stats.mtime instanceof Date);
fs.close(fd, common.mustCall(assert.ifError));
}));

fs.stat(__filename, common.mustCall(function(err, s) {
Expand All @@ -92,38 +82,30 @@ fs.stat(__filename, common.mustCall(function(err, s) {
assert.strictEqual(s.isCharacterDevice(), false);
assert.strictEqual(s.isFIFO(), false);
assert.strictEqual(s.isSymbolicLink(), false);
const keys = [

const jsonString = JSON.stringify(s);
const parsed = JSON.parse(jsonString);
[
'dev', 'mode', 'nlink', 'uid',
'gid', 'rdev', 'blksize', 'ino', 'size', 'blocks',
'atime', 'mtime', 'ctime', 'birthtime',
'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs'
];
const numberFields = [
'dev', 'mode', 'nlink', 'uid', 'gid', 'rdev', 'blksize', 'ino', 'size',
'blocks', 'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs'
];
const dateFields = ['atime', 'mtime', 'ctime', 'birthtime'];
keys.forEach(function(k) {
'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs',
].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) => {
[
'dev', 'mode', 'nlink', 'uid', 'gid', 'rdev', 'blksize', 'ino', 'size',
'blocks', 'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs',
].forEach((k) => {
assert.strictEqual(typeof s[k], 'number', `${k} should be a number`);
assert.strictEqual(typeof parsed[k], 'number', `${k} should be a number`);
});
dateFields.forEach((k) => {
['atime', 'mtime', 'ctime', 'birthtime'].forEach((k) => {
assert.ok(s[k] instanceof Date, `${k} should be a Date`);
assert.strictEqual(typeof parsed[k], 'string', `${k} should be a string`);
});
}));
Expand Down